| Index: polyfill.js |
| =================================================================== |
| --- a/polyfill.js |
| +++ b/polyfill.js |
| @@ -107,26 +107,25 @@ |
| // If the property is not writable assigning it will fail, so we use |
| // Object.defineProperty here instead. Assuming the property isn't |
| // inherited its other attributes (e.g. enumerable) are preserved, |
| // except for accessor attributes (e.g. get and set) which are discarded |
| // since we're specifying a value. |
| Object.defineProperty(object, name, { |
| value(...args) |
| { |
| - if (typeof args[args.length - 1] == "function") |
| - return func.apply(object, args); |
| + let lastArgumentType = typeof args[args.length - 1]; |
| - // If the last argument is undefined, we drop it from the list assuming |
| - // it stands for the optional callback. We must do this, because we have |
| - // to replace it with our own callback. If we simply append our own |
| - // callback to the list, it won't match the signature of the function |
| - // and will cause an exception. |
| - if (typeof args[args.length - 1] == "undefined") |
| - args.pop(); |
| + // If the last argument is undefined, we assume it stands for the |
| + // optional callback. |
| + if (lastArgumentType == "function" || |
| + 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
|
| + { |
| + throw new Error("Callbacks are no longer supported."); |
| + } |
| let resolvePromise = null; |
| let rejectPromise = null; |
| func.call(object, ...args, result => |
| { |
| let error = browser.runtime.lastError; |
| if (error && !portClosedBeforeResponseError.test(error.message)) |