Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: polyfill.js

Issue 29590603: Issue 5954 - Read-only properties cannot be assigned in strict mode in Edge (Closed)
Patch Set: Created Oct. 27, 2017, 1:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 { 62 {
63 object = object[node]; 63 object = object[node];
64 64
65 if (!object) 65 if (!object)
66 return; 66 return;
67 } 67 }
68 68
69 let func = object[name]; 69 let func = object[name];
70 if (!func) 70 if (!func)
71 return; 71 return;
72 let descriptor = Reflect.getOwnPropertyDescriptor(object, name);
Oleksandr 2017/10/27 13:12:37 We cannot use Object.getOwnPropertyDescriptor beca
Manish Jethani 2017/10/27 14:25:16 We can use Object.getOwnPropertyDescriptor here si
72 73
73 object[name] = function(...args) 74 if (descriptor && descriptor.configurable)
Oleksandr 2017/10/27 13:12:38 There isn't really an object in our list that does
Manish Jethani 2017/10/27 14:25:16 Yes, we should remove it. If it's not configurabl
74 { 75 {
75 let callStack = new Error().stack; 76 Object.defineProperty(object, name, {
Manish Jethani 2017/10/27 14:25:16 You could just do: descriptor.value = (...args)
77 enumerable: true,
78 configurable: true,
79 writable: true,
80 value: (...args) =>
81 {
82 let callStack = new Error().stack;
83 if (typeof args[args.length - 1] == "function")
84 return func.apply(object, args);
76 85
77 if (typeof args[args.length - 1] == "function") 86 // If the last argument is undefined, we drop it from the list
78 return func.apply(object, args); 87 // assuming it stands for the optional callback. We must do this,
88 // because we have to replace it with our own callback. If we simply
89 // append our own callback to the list, it won't match the signature
90 // of the function and will cause an exception.
91 if (typeof args[args.length - 1] == "undefined")
92 args.pop();
79 93
80 // If the last argument is undefined, we drop it from the list assuming 94 return new Promise((resolve, reject) =>
81 // it stands for the optional callback. We must do this, because we have 95 {
82 // to replace it with our own callback. If we simply append our own 96 func.call(object, ...args, result =>
83 // callback to the list, it won't match the signature of the function and 97 {
84 // will cause an exception. 98 let error = browser.runtime.lastError;
85 if (typeof args[args.length - 1] == "undefined") 99 if (error && !portClosedBeforeResponseError.test(error.message))
86 args.pop(); 100 {
101 // runtime.lastError is already an Error instance on Edge, while
102 // on Chrome it is a plain object with only a message property.
103 if (!(error instanceof Error))
104 {
105 error = new Error(error.message);
87 106
88 return new Promise((resolve, reject) => 107 // Add a more helpful stack trace.
89 { 108 error.stack = callStack;
90 func.call(object, ...args, result => 109 }
91 {
92 let error = browser.runtime.lastError;
93 if (error && !portClosedBeforeResponseError.test(error.message))
94 {
95 // runtime.lastError is already an Error instance on Edge, while on
96 // Chrome it is a plain object with only a message property.
97 if (!(error instanceof Error))
98 {
99 error = new Error(error.message);
100 110
101 // Add a more helpful stack trace. 111 reject(error);
102 error.stack = callStack; 112 }
103 } 113 else
104 114 {
105 reject(error); 115 resolve(result);
106 } 116 }
107 else 117 });
108 { 118 });
109 resolve(result); 119 }});
110 } 120 }
111 });
112 });
113 };
114 } 121 }
115 122
116 function shouldWrapAPIs() 123 function shouldWrapAPIs()
117 { 124 {
118 try 125 try
119 { 126 {
120 return !(browser.storage.local.get([]) instanceof Promise); 127 return !(browser.storage.local.get([]) instanceof Promise);
121 } 128 }
122 catch (error) 129 catch (error)
123 { 130 {
(...skipping 16 matching lines...) Expand all
140 147
141 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList 148 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList
142 // didn't have iterator support before Chrome 51. 149 // didn't have iterator support before Chrome 51.
143 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 150 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699
144 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) 151 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList])
145 { 152 {
146 if (!(Symbol.iterator in object.prototype)) 153 if (!(Symbol.iterator in object.prototype))
147 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; 154 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
148 } 155 }
149 } 156 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld