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

Side by Side Diff: polyfill.js

Issue 29582713: Issue 4579 - Wrap rejection reason in Error object (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Remove unnecessary code Created Oct. 19, 2017, 9:29 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 { 53 {
54 object = object[node]; 54 object = object[node];
55 55
56 if (!object) 56 if (!object)
57 return; 57 return;
58 } 58 }
59 59
60 let func = object[name]; 60 let func = object[name];
61 object[name] = function(...args) 61 object[name] = function(...args)
62 { 62 {
63 let callStack = new Error().stack;
64
63 if (typeof args[args.length - 1] == "function") 65 if (typeof args[args.length - 1] == "function")
64 return func.apply(object, args); 66 return func.apply(object, args);
65 67
66 // If the last argument is undefined, we drop it from the list assuming 68 // If the last argument is undefined, we drop it from the list assuming
67 // it stands for the optional callback. We must do this, because we have 69 // it stands for the optional callback. We must do this, because we have
68 // to replace it with our own callback. If we simply append our own 70 // to replace it with our own callback. If we simply append our own
69 // callback to the list, it won't match the signature of the function and 71 // callback to the list, it won't match the signature of the function and
70 // will cause an exception. 72 // will cause an exception.
71 if (typeof args[args.length - 1] == "undefined") 73 if (typeof args[args.length - 1] == "undefined")
72 args.pop(); 74 args.pop();
73 75
74 return new Promise((resolve, reject) => 76 return new Promise((resolve, reject) =>
75 { 77 {
76 func.call(object, ...args, result => 78 func.call(object, ...args, result =>
77 { 79 {
78 let error = browser.runtime.lastError; 80 let error = browser.runtime.lastError;
79 if (error) 81 if (error)
82 {
83 // runtime.lastError on Chrome is a plain object with only a
84 // message property.
Sebastian Noack 2017/10/19 18:09:56 Perhaps, this comment could be a little bit more e
Manish Jethani 2017/10/20 00:04:23 Done.
85 if (!(error instanceof Error))
86 error = new Error(error.message);
87
88 // Add a more helpful stack trace.
89 error.stack = callStack;
Sebastian Noack 2017/10/19 18:09:56 How does the stack on Microsoft Edge (where browse
Manish Jethani 2017/10/20 00:04:23 I'm not sure, but I think we should just move it i
90
80 reject(error); 91 reject(error);
92 }
81 else 93 else
94 {
82 resolve(result); 95 resolve(result);
96 }
83 }); 97 });
84 }); 98 });
85 }; 99 };
86 } 100 }
87 101
88 function shouldWrapAPIs() 102 function shouldWrapAPIs()
89 { 103 {
90 try 104 try
91 { 105 {
92 return !(browser.storage.local.get([]) instanceof Promise); 106 return !(browser.storage.local.get([]) instanceof Promise);
(...skipping 19 matching lines...) Expand all
112 126
113 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList 127 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList
114 // didn't have iterator support before Chrome 51. 128 // didn't have iterator support before Chrome 51.
115 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 129 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699
116 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) 130 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList])
117 { 131 {
118 if (!(Symbol.iterator in object.prototype)) 132 if (!(Symbol.iterator in object.prototype))
119 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; 133 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
120 } 134 }
121 } 135 }
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