OLD | NEW |
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return; | 85 return; |
86 | 86 |
87 // If the property is not writable assigning it will fail, so we use | 87 // If the property is not writable assigning it will fail, so we use |
88 // Object.defineProperty here instead. Assuming the property isn't | 88 // Object.defineProperty here instead. Assuming the property isn't |
89 // inherited its other attributes (e.g. enumerable) are preserved, | 89 // inherited its other attributes (e.g. enumerable) are preserved, |
90 // except for accessor attributes (e.g. get and set) which are discarded | 90 // except for accessor attributes (e.g. get and set) which are discarded |
91 // since we're specifying a value. | 91 // since we're specifying a value. |
92 Object.defineProperty(object, name, { | 92 Object.defineProperty(object, name, { |
93 value(...args) | 93 value(...args) |
94 { | 94 { |
95 if (typeof args[args.length - 1] == "function") | 95 let lastArgumentType = typeof args[args.length - 1]; |
96 return func.apply(object, args); | |
97 | 96 |
98 // If the last argument is undefined, we drop it from the list assuming | 97 // If the last argument is undefined, we assume it stands for the |
99 // it stands for the optional callback. We must do this, because we have | 98 // optional callback. |
100 // to replace it with our own callback. If we simply append our own | 99 if (lastArgumentType == "function" || lastArgumentType == "undefined") |
101 // callback to the list, it won't match the signature of the function | 100 throw new Error("Callbacks are no longer supported."); |
102 // and will cause an exception. | |
103 if (typeof args[args.length - 1] == "undefined") | |
104 args.pop(); | |
105 | 101 |
106 let resolvePromise = null; | 102 let resolvePromise = null; |
107 let rejectPromise = null; | 103 let rejectPromise = null; |
108 | 104 |
109 func.call(object, ...args, result => | 105 func.call(object, ...args, result => |
110 { | 106 { |
111 let error = browser.runtime.lastError; | 107 let error = browser.runtime.lastError; |
112 if (error && !portClosedBeforeResponseError.test(error.message)) | 108 if (error && !portClosedBeforeResponseError.test(error.message)) |
113 { | 109 { |
114 // runtime.lastError is already an Error instance on Edge, while on | 110 // runtime.lastError is already an Error instance on Edge, while on |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 223 |
228 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList | 224 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList |
229 // didn't have iterator support before Chrome 51. | 225 // didn't have iterator support before Chrome 51. |
230 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 | 226 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 |
231 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) | 227 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) |
232 { | 228 { |
233 if (!(Symbol.iterator in object.prototype)) | 229 if (!(Symbol.iterator in object.prototype)) |
234 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; | 230 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; |
235 } | 231 } |
236 } | 232 } |
OLD | NEW |