Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 let {object, name, func} = wrappables; | 105 let {object, name, func} = wrappables; |
106 | 106 |
107 // If the property is not writable assigning it will fail, so we use | 107 // If the property is not writable assigning it will fail, so we use |
108 // Object.defineProperty here instead. Assuming the property isn't | 108 // Object.defineProperty here instead. Assuming the property isn't |
109 // inherited its other attributes (e.g. enumerable) are preserved, | 109 // inherited its other attributes (e.g. enumerable) are preserved, |
110 // except for accessor attributes (e.g. get and set) which are discarded | 110 // except for accessor attributes (e.g. get and set) which are discarded |
111 // since we're specifying a value. | 111 // since we're specifying a value. |
112 Object.defineProperty(object, name, { | 112 Object.defineProperty(object, name, { |
113 value(...args) | 113 value(...args) |
114 { | 114 { |
115 let lastArgumentType = typeof args[args.length - 1]; | |
116 | |
117 // If the last argument is undefined, we assume it stands for the | |
118 // optional callback. | |
119 if (lastArgumentType == "function" || | |
120 lastArgumentType == "undefined" && args.length > 0) | |
Manish Jethani
2019/04/24 14:42:23
We need to support calls like `browser.runtime.ope
Sebastian Noack
2019/04/24 19:50:38
I just tested on Firefox (where the promise-based
Manish Jethani
2019/04/24 20:09:47
But we're not? Quite the opposite, the additional
Sebastian Noack
2019/04/24 20:42:29
Like I read the code here, you throw if the last a
Manish Jethani
2019/04/25 08:04:54
Are you suggesting we don't throw the error at all
Sebastian Noack
2019/04/25 08:18:21
I think a polyfill should behave like the implemen
Manish Jethani
2019/04/25 08:51:20
Fair enough, in that case we have two options:
1
| |
121 { | |
122 throw new Error("Callbacks are no longer supported."); | |
123 } | |
124 | |
125 let resolvePromise = null; | 115 let resolvePromise = null; |
126 let rejectPromise = null; | 116 let rejectPromise = null; |
127 | 117 |
128 func.call(object, ...args, result => | 118 func.call(object, ...args, result => |
129 { | 119 { |
130 let error = browser.runtime.lastError; | 120 let error = browser.runtime.lastError; |
131 if (error && !portClosedBeforeResponseError.test(error.message)) | 121 if (error && !portClosedBeforeResponseError.test(error.message)) |
132 { | 122 { |
133 // runtime.lastError is already an Error instance on Edge, while on | 123 // runtime.lastError is already an Error instance on Edge, while on |
134 // Chrome it is a plain object with only a message property. | 124 // Chrome it is a plain object with only a message property. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 if (typeof OffscreenCanvas == "undefined") | 349 if (typeof OffscreenCanvas == "undefined") |
360 { | 350 { |
361 self.OffscreenCanvas = function(width, height) | 351 self.OffscreenCanvas = function(width, height) |
362 { | 352 { |
363 let canvas = document.createElement("canvas"); | 353 let canvas = document.createElement("canvas"); |
364 canvas.width = width; | 354 canvas.width = width; |
365 canvas.height = height; | 355 canvas.height = height; |
366 return canvas; | 356 return canvas; |
367 }; | 357 }; |
368 } | 358 } |
LEFT | RIGHT |