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

Unified Diff: polyfill.js

Issue 30024555: Issue 7334 - Remove support for callbacks in API wrappers (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created March 6, 2019, 11 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: polyfill.js
===================================================================
--- a/polyfill.js
+++ b/polyfill.js
@@ -87,26 +87,22 @@
// 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")
+ 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))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld