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

Delta Between Two Patch Sets: polyfill.js

Issue 29573892: Issue 4579 - Promisify APIs (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Rebase Created Oct. 17, 2017, 1:30 p.m.
Right Patch Set: Revert patch set 9 Created Oct. 18, 2017, 12:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 (function()
Manish Jethani 2017/10/17 13:33:24 This all needs to be wrapped inside an anonymous f
Manish Jethani 2017/10/17 17:35:45 Actually this can just be an anonymous block. Don
kzar 2017/10/17 18:13:42 IIRC Firefox got upset when declaring functions in
Manish Jethani 2017/10/17 20:48:45 You're right, the function declarations would be "
Sebastian Noack 2017/10/17 23:31:03 Both of you are wrong. In strict mode, as of ES201
Manish Jethani 2017/10/18 00:05:33 Ah, of course. Reverted.
21 { 20 {
22 const asyncAPIs = [ 21 const asyncAPIs = [
23 "contextMenus.removeAll", 22 "contextMenus.removeAll",
24 "devtools.panels.create", 23 "devtools.panels.create",
25 "notifications.clear", 24 "notifications.clear",
26 "notifications.create", 25 "notifications.create",
27 "runtime.openOptionsPage", 26 "runtime.openOptionsPage",
28 "runtime.sendMessage", 27 "runtime.sendMessage",
29 "runtime.setUninstallURL", 28 "runtime.setUninstallURL",
30 "storage.local.get", 29 "storage.local.get",
31 "storage.local.remove", 30 "storage.local.remove",
32 "storage.local.set", 31 "storage.local.set",
33 "storage.managed.get", 32 "storage.managed.get",
34 "tabs.create", 33 "tabs.create",
35 "tabs.get", 34 "tabs.get",
36 "tabs.insertCSS", 35 "tabs.insertCSS",
37 "tabs.query", 36 "tabs.query",
38 "tabs.reload", 37 "tabs.reload",
39 "tabs.sendMessage", 38 "tabs.sendMessage",
40 "tabs.update", 39 "tabs.update",
41 "webNavigation.getAllFrames", 40 "webNavigation.getAllFrames",
42 "webRequest.handlerBehaviorChanged", 41 "webRequest.handlerBehaviorChanged",
43 "windows.create", 42 "windows.create",
44 "windows.update" 43 "windows.update"
45 ]; 44 ];
46 45
47 function wrapAPI(api) 46 function wrapAPI(api)
48 { 47 {
49 let object = browser; 48 let object = browser;
Manish Jethani 2017/10/17 13:33:23 Note: Using browser now instead of chrome
50 let path = api.split("."); 49 let path = api.split(".");
51 let name = path.pop(); 50 let name = path.pop();
52 51
53 for (let node of path) 52 for (let node of path)
54 { 53 {
55 object = object[node]; 54 object = object[node];
56 55
57 if (!object) 56 if (!object)
58 return; 57 return;
59 } 58 }
(...skipping 29 matching lines...) Expand all
89 function shouldWrapAPIs() 88 function shouldWrapAPIs()
90 { 89 {
91 try 90 try
92 { 91 {
93 return !(browser.storage.local.get([]) instanceof Promise); 92 return !(browser.storage.local.get([]) instanceof Promise);
94 } 93 }
95 catch (error) 94 catch (error)
96 { 95 {
97 } 96 }
98 97
99 return true; 98 return true;
Wladimir Palant 2017/10/18 08:59:11 Nit: I would put that return inside the catch bloc
Manish Jethani 2017/10/18 11:00:26 Acknowledged.
100 } 99 }
101 100
102 if (shouldWrapAPIs()) 101 if (shouldWrapAPIs())
103 { 102 {
104 // Unlike Firefox and Microsoft Edge, Chrome doesn't have a "browser" object , 103 // Unlike Firefox and Microsoft Edge, Chrome doesn't have a "browser" object ,
Manish Jethani 2017/10/17 13:33:23 After calling shouldWrapAPIs we can safely overwri
105 // but provides the extension API through the "chrome" namespace 104 // but provides the extension API through the "chrome" namespace
106 // (non-standard). 105 // (non-standard).
107 if (typeof browser == "undefined") 106 if (typeof browser == "undefined")
108 window.browser = chrome; 107 window.browser = chrome;
109 108
110 for (let api of asyncAPIs) 109 for (let api of asyncAPIs)
111 wrapAPI(api); 110 wrapAPI(api);
112 } 111 }
113 112
114 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList 113 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList
115 // didn't have iterator support before Chrome 51. 114 // didn't have iterator support before Chrome 51.
116 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 115 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699
117 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) 116 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList])
118 { 117 {
119 if (!(Symbol.iterator in object.prototype)) 118 if (!(Symbol.iterator in object.prototype))
120 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; 119 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
121 } 120 }
122 }()); 121 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld