| Left: | ||
| Right: |
| 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 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 if (typeof args[args.length - 1] == "function") | 115 let lastArgumentType = typeof args[args.length - 1]; |
| 116 return func.apply(object, args); | |
| 117 | 116 |
| 118 // If the last argument is undefined, we drop it from the list assuming | 117 // If the last argument is undefined, we assume it stands for the |
| 119 // it stands for the optional callback. We must do this, because we have | 118 // optional callback. |
| 120 // to replace it with our own callback. If we simply append our own | 119 if (lastArgumentType == "function" || |
| 121 // callback to the list, it won't match the signature of the 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
| |
| 122 // and will cause an exception. | 121 { |
| 123 if (typeof args[args.length - 1] == "undefined") | 122 throw new Error("Callbacks are no longer supported."); |
| 124 args.pop(); | 123 } |
| 125 | 124 |
| 126 let resolvePromise = null; | 125 let resolvePromise = null; |
| 127 let rejectPromise = null; | 126 let rejectPromise = null; |
| 128 | 127 |
| 129 func.call(object, ...args, result => | 128 func.call(object, ...args, result => |
| 130 { | 129 { |
| 131 let error = browser.runtime.lastError; | 130 let error = browser.runtime.lastError; |
| 132 if (error && !portClosedBeforeResponseError.test(error.message)) | 131 if (error && !portClosedBeforeResponseError.test(error.message)) |
| 133 { | 132 { |
| 134 // runtime.lastError is already an Error instance on Edge, while on | 133 // runtime.lastError is already an Error instance on Edge, while on |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 if (typeof OffscreenCanvas == "undefined") | 359 if (typeof OffscreenCanvas == "undefined") |
| 361 { | 360 { |
| 362 self.OffscreenCanvas = function(width, height) | 361 self.OffscreenCanvas = function(width, height) |
| 363 { | 362 { |
| 364 let canvas = document.createElement("canvas"); | 363 let canvas = document.createElement("canvas"); |
| 365 canvas.width = width; | 364 canvas.width = width; |
| 366 canvas.height = height; | 365 canvas.height = height; |
| 367 return canvas; | 366 return canvas; |
| 368 }; | 367 }; |
| 369 } | 368 } |
| OLD | NEW |