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

Side by Side Diff: polyfill.js

Issue 30024555: Issue 7334 - Remove support for callbacks in API wrappers (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Rebase Created April 24, 2019, 2:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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" || lastArgumentType == "undefined")
121 // callback to the list, it won't match the signature of the function 120 throw new Error("Callbacks are no longer supported.");
122 // and will cause an exception.
123 if (typeof args[args.length - 1] == "undefined")
124 args.pop();
125 121
126 let resolvePromise = null; 122 let resolvePromise = null;
127 let rejectPromise = null; 123 let rejectPromise = null;
128 124
129 func.call(object, ...args, result => 125 func.call(object, ...args, result =>
130 { 126 {
131 let error = browser.runtime.lastError; 127 let error = browser.runtime.lastError;
132 if (error && !portClosedBeforeResponseError.test(error.message)) 128 if (error && !portClosedBeforeResponseError.test(error.message))
133 { 129 {
134 // runtime.lastError is already an Error instance on Edge, while on 130 // runtime.lastError is already an Error instance on Edge, while on
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (typeof OffscreenCanvas == "undefined") 356 if (typeof OffscreenCanvas == "undefined")
361 { 357 {
362 self.OffscreenCanvas = function(width, height) 358 self.OffscreenCanvas = function(width, height)
363 { 359 {
364 let canvas = document.createElement("canvas"); 360 let canvas = document.createElement("canvas");
365 canvas.width = width; 361 canvas.width = width;
366 canvas.height = height; 362 canvas.height = height;
367 return canvas; 363 return canvas;
368 }; 364 };
369 } 365 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld