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: Remove checks Created April 25, 2019, 9:04 a.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")
116 return func.apply(object, args);
117
118 // If the last argument is undefined, we drop it from the list assuming
119 // it stands for the optional callback. We must do this, because we have
120 // to replace it with our own callback. If we simply append our own
121 // callback to the list, it won't match the signature of the function
122 // and will cause an exception.
123 if (typeof args[args.length - 1] == "undefined")
124 args.pop();
125
126 let resolvePromise = null; 115 let resolvePromise = null;
127 let rejectPromise = null; 116 let rejectPromise = null;
128 117
129 func.call(object, ...args, result => 118 func.call(object, ...args, result =>
130 { 119 {
131 let error = browser.runtime.lastError; 120 let error = browser.runtime.lastError;
132 if (error && !portClosedBeforeResponseError.test(error.message)) 121 if (error && !portClosedBeforeResponseError.test(error.message))
133 { 122 {
134 // runtime.lastError is already an Error instance on Edge, while on 123 // runtime.lastError is already an Error instance on Edge, while on
135 // 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
360 if (typeof OffscreenCanvas == "undefined") 349 if (typeof OffscreenCanvas == "undefined")
361 { 350 {
362 self.OffscreenCanvas = function(width, height) 351 self.OffscreenCanvas = function(width, height)
363 { 352 {
364 let canvas = document.createElement("canvas"); 353 let canvas = document.createElement("canvas");
365 canvas.width = width; 354 canvas.width = width;
366 canvas.height = height; 355 canvas.height = height;
367 return canvas; 356 return canvas;
368 }; 357 };
369 } 358 }
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