| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 }); | 123 }); |
| 124 }); | 124 }); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 Object.defineProperty(object, name, descriptor); | 127 Object.defineProperty(object, name, descriptor); |
| 128 } | 128 } |
| 129 | 129 |
| 130 function wrapRuntimeOnMessage() | 130 function wrapRuntimeOnMessage() |
| 131 { | 131 { |
| 132 let {onMessage} = browser.runtime; | 132 let {onMessage} = browser.runtime; |
| 133 let {addListener, removeListener, hasListener} = onMessage; | 133 let {addListener, removeListener} = onMessage; |
| 134 | 134 |
| 135 onMessage.addListener = function(listener) | 135 onMessage.addListener = function(listener) |
| 136 { | 136 { |
| 137 if (typeof listener != "function") | 137 if (typeof listener != "function") |
| 138 throw new Error(invalidMessageListenerError); | 138 throw new Error(invalidMessageListenerError); |
| 139 | 139 |
| 140 // Don't add the same listener twice or we end up with multiple wrappers. | 140 // Don't add the same listener twice or we end up with multiple wrappers. |
| 141 if (messageListeners.has(listener)) | 141 if (messageListeners.has(listener)) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 let wrapper = (message, sender, sendResponse) => | 144 let wrapper = (message, sender, sendResponse) => |
| 145 { | 145 { |
| 146 let wait = listener(message, sender, sendResponse); | 146 let wait = listener(message, sender, sendResponse); |
| 147 | 147 |
| 148 if (wait instanceof Promise) | 148 if (wait instanceof Promise) |
| 149 { | 149 { |
| 150 wait.then(sendResponse, reason => | 150 wait.then(sendResponse, reason => |
| 151 { | 151 { |
| 152 try | 152 try |
| 153 { | 153 { |
| 154 sendResponse(); | 154 sendResponse(); |
| 155 } | 155 } |
| 156 finally | 156 catch (error) |
| 157 { | 157 { |
| 158 // sendResponse can throw if the internal port is closed; be sure | 158 // sendResponse can throw if the internal port is closed; be sure |
| 159 // to throw the original error. | 159 // to throw the original error. |
| 160 throw reason; | |
| 161 } | 160 } |
| 161 |
| 162 throw reason; |
| 162 }); | 163 }); |
| 163 } | 164 } |
| 164 | 165 |
| 165 return !!wait; | 166 return !!wait; |
| 166 }; | 167 }; |
| 167 | 168 |
| 168 addListener.call(onMessage, wrapper); | 169 addListener.call(onMessage, wrapper); |
| 169 messageListeners.set(listener, wrapper); | 170 messageListeners.set(listener, wrapper); |
| 170 }; | 171 }; |
| 171 | 172 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 221 |
| 221 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList | 222 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList |
| 222 // didn't have iterator support before Chrome 51. | 223 // didn't have iterator support before Chrome 51. |
| 223 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 | 224 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 |
| 224 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) | 225 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) |
| 225 { | 226 { |
| 226 if (!(Symbol.iterator in object.prototype)) | 227 if (!(Symbol.iterator in object.prototype)) |
| 227 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; | 228 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; |
| 228 } | 229 } |
| 229 } | 230 } |
| OLD | NEW |