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

Delta Between Two Patch Sets: polyfill.js

Issue 29582713: Issue 4579 - Wrap rejection reason in Error object (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Created Oct. 19, 2017, 12:29 a.m.
Right Patch Set: Add stack trace only on Chrome Created Oct. 20, 2017, 12:03 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
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 if (typeof args[args.length - 1] == "undefined") 73 if (typeof args[args.length - 1] == "undefined")
74 args.pop(); 74 args.pop();
75 75
76 return new Promise((resolve, reject) => 76 return new Promise((resolve, reject) =>
77 { 77 {
78 func.call(object, ...args, result => 78 func.call(object, ...args, result =>
79 { 79 {
80 let error = browser.runtime.lastError; 80 let error = browser.runtime.lastError;
81 if (error) 81 if (error)
82 { 82 {
83 // runtime.lastError on Chrome is a plain object with only a 83 // runtime.lastError is already an Error instance on Edge, while on
84 // message property. 84 // Chrome it is a plain object with only a message property.
85 if (!(error instanceof Error)) 85 if (!(error instanceof Error))
Sebastian Noack 2017/10/19 04:30:24 Why checking whether it is an error, if we know th
Manish Jethani 2017/10/19 09:35:39 It seems that only Chrome's runtime.lastError is n
Manish Jethani 2017/10/19 09:37:39 Ollie just confirmed on IRC that it is in fact an
86 {
86 error = new Error(error.message); 87 error = new Error(error.message);
87 88
88 // Add a more helpful stack trace. 89 // Add a more helpful stack trace.
89 error.stack = callStack.replace(/^Error\n {4}at Object\./, 90 error.stack = callStack;
Manish Jethani 2017/10/19 00:32:13 The stack trace from the caller's side is actually
Sebastian Noack 2017/10/19 04:30:24 Not sure whether this is worth it: * Firefox does
Wladimir Palant 2017/10/19 07:51:35 Making assumptions about the stack format and doin
Manish Jethani 2017/10/19 09:35:39 I think I see that this was a bit of overkill. I'v
90 "Error\n at browser."); 91 }
92
91 reject(error); 93 reject(error);
92 } 94 }
93 else 95 else
94 { 96 {
95 resolve(result); 97 resolve(result);
96 } 98 }
97 }); 99 });
98 }); 100 });
99 }; 101 };
100
101 // Set the name for debugging.
102 Object.defineProperty(object[name], "name", {
Manish Jethani 2017/10/19 00:32:13 If we do this we get the name of the API in the st
Sebastian Noack 2017/10/19 04:30:24 IMO this goes to far. Not even the original chrome
Manish Jethani 2017/10/19 09:35:39 Yes, but when the call throws an error synchronous
103 writable: false,
104 enumerable: false,
105 configurable: true,
106 value: api
107 });
108 } 102 }
109 103
110 function shouldWrapAPIs() 104 function shouldWrapAPIs()
111 { 105 {
112 try 106 try
113 { 107 {
114 return !(browser.storage.local.get([]) instanceof Promise); 108 return !(browser.storage.local.get([]) instanceof Promise);
115 } 109 }
116 catch (error) 110 catch (error)
117 { 111 {
(...skipping 16 matching lines...) Expand all
134 128
135 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList 129 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList
136 // didn't have iterator support before Chrome 51. 130 // didn't have iterator support before Chrome 51.
137 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 131 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699
138 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) 132 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList])
139 { 133 {
140 if (!(Symbol.iterator in object.prototype)) 134 if (!(Symbol.iterator in object.prototype))
141 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; 135 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
142 } 136 }
143 } 137 }
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