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: 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:
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 is already an Error instance on Edge, while on
84 // Chrome it is a plain object with only a message property.
85 if (!(error instanceof Error))
86 {
87 error = new Error(error.message);
88
89 // Add a more helpful stack trace.
90 error.stack = callStack;
91 }
92
80 reject(error); 93 reject(error);
94 }
81 else 95 else
96 {
82 resolve(result); 97 resolve(result);
98 }
83 }); 99 });
84 }); 100 });
85 }; 101 };
86 } 102 }
87 103
88 function shouldWrapAPIs() 104 function shouldWrapAPIs()
89 { 105 {
90 try 106 try
91 { 107 {
92 return !(browser.storage.local.get([]) instanceof Promise); 108 return !(browser.storage.local.get([]) instanceof Promise);
(...skipping 19 matching lines...) Expand all
112 128
113 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList 129 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList
114 // didn't have iterator support before Chrome 51. 130 // didn't have iterator support before Chrome 51.
115 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 131 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699
116 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) 132 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList])
117 { 133 {
118 if (!(Symbol.iterator in object.prototype)) 134 if (!(Symbol.iterator in object.prototype))
119 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; 135 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
120 } 136 }
121 } 137 }
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