| OLD | NEW |
| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // it stands for the optional callback. We must do this, because we have | 99 // it stands for the optional callback. We must do this, because we have |
| 100 // to replace it with our own callback. If we simply append our own | 100 // to replace it with our own callback. If we simply append our own |
| 101 // callback to the list, it won't match the signature of the function | 101 // callback to the list, it won't match the signature of the function |
| 102 // and will cause an exception. | 102 // and will cause an exception. |
| 103 if (typeof args[args.length - 1] == "undefined") | 103 if (typeof args[args.length - 1] == "undefined") |
| 104 args.pop(); | 104 args.pop(); |
| 105 | 105 |
| 106 let resolvePromise = null; | 106 let resolvePromise = null; |
| 107 let rejectPromise = null; | 107 let rejectPromise = null; |
| 108 | 108 |
| 109 let callStack = new Error().stack; | |
| 110 | |
| 111 func.call(object, ...args, result => | 109 func.call(object, ...args, result => |
| 112 { | 110 { |
| 113 let error = browser.runtime.lastError; | 111 let error = browser.runtime.lastError; |
| 114 if (error && !portClosedBeforeResponseError.test(error.message)) | 112 if (error && !portClosedBeforeResponseError.test(error.message)) |
| 115 { | 113 { |
| 116 // runtime.lastError is already an Error instance on Edge, while on | 114 // runtime.lastError is already an Error instance on Edge, while on |
| 117 // Chrome it is a plain object with only a message property. | 115 // Chrome it is a plain object with only a message property. |
| 118 if (!(error instanceof Error)) | 116 if (!(error instanceof Error)) |
| 119 { | |
| 120 error = new Error(error.message); | 117 error = new Error(error.message); |
| 121 | 118 |
| 122 // Add a more helpful stack trace. | |
| 123 error.stack = callStack; | |
| 124 } | |
| 125 | |
| 126 rejectPromise(error); | 119 rejectPromise(error); |
| 127 } | 120 } |
| 128 else | 121 else |
| 129 { | 122 { |
| 130 resolvePromise(result); | 123 resolvePromise(result); |
| 131 } | 124 } |
| 132 }); | 125 }); |
| 133 | 126 |
| 134 return new Promise((resolve, reject) => | 127 return new Promise((resolve, reject) => |
| 135 { | 128 { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 227 |
| 235 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList | 228 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList |
| 236 // didn't have iterator support before Chrome 51. | 229 // didn't have iterator support before Chrome 51. |
| 237 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 | 230 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 |
| 238 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) | 231 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) |
| 239 { | 232 { |
| 240 if (!(Symbol.iterator in object.prototype)) | 233 if (!(Symbol.iterator in object.prototype)) |
| 241 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; | 234 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; |
| 242 } | 235 } |
| 243 } | 236 } |
| OLD | NEW |