| Left: | ||
| Right: |
| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 { | 62 { |
| 63 object = object[node]; | 63 object = object[node]; |
| 64 | 64 |
| 65 if (!object) | 65 if (!object) |
| 66 return; | 66 return; |
| 67 } | 67 } |
| 68 | 68 |
| 69 let func = object[name]; | 69 let func = object[name]; |
| 70 if (!func) | 70 if (!func) |
| 71 return; | 71 return; |
| 72 | 72 let oldDescriptor = Object.getOwnPropertyDescriptor(object, name); |
|
kzar
2017/11/06 08:52:01
How about this (untested):
let descriptor = Objec
Oleksandr
2017/11/06 09:05:00
This doesn't work, because some descriptors can be
kzar
2017/11/06 10:12:38
Which APIs are returned using a getter? I find it
Oleksandr
2017/11/06 10:14:18
For example `setUnintstallUrl`, as it says on the
kzar
2017/11/06 10:37:37
Ah right, well you could just delete the getter an
Oleksandr
2017/11/08 13:58:09
I guess we'll just have to see. I don't know why t
kzar
2017/11/10 14:18:20
What do you think about that Manish?
| |
| 73 object[name] = function(...args) | 73 // Some descriptors like setUninstallURL are in fact accessor descriptors. |
| 74 // We convert them to data descriptors. | |
| 75 let descriptor = { | |
| 76 enumerable: oldDescriptor.enumerable, | |
| 77 configurable: oldDescriptor.configurable, | |
| 78 writable: oldDescriptor.writable | |
| 79 }; | |
| 80 descriptor.value = (...args) => | |
|
Manish Jethani
2017/11/05 10:13:52
Functions and arrow functions have different seman
kzar
2017/11/06 08:52:01
Agreed
Oleksandr
2017/11/06 09:05:00
Done.
| |
| 74 { | 81 { |
| 75 let callStack = new Error().stack; | 82 let callStack = new Error().stack; |
| 76 | 83 |
| 77 if (typeof args[args.length - 1] == "function") | 84 if (typeof args[args.length - 1] == "function") |
| 78 return func.apply(object, args); | 85 return func.apply(object, args); |
| 79 | 86 |
| 80 // If the last argument is undefined, we drop it from the list assuming | 87 // If the last argument is undefined, we drop it from the list assuming |
| 81 // it stands for the optional callback. We must do this, because we have | 88 // it stands for the optional callback. We must do this, because we have |
| 82 // to replace it with our own callback. If we simply append our own | 89 // to replace it with our own callback. If we simply append our own |
| 83 // callback to the list, it won't match the signature of the function and | 90 // callback to the list, it won't match the signature of the function and |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 104 | 111 |
| 105 reject(error); | 112 reject(error); |
| 106 } | 113 } |
| 107 else | 114 else |
| 108 { | 115 { |
| 109 resolve(result); | 116 resolve(result); |
| 110 } | 117 } |
| 111 }); | 118 }); |
| 112 }); | 119 }); |
| 113 }; | 120 }; |
| 121 Object.defineProperty(object, name, descriptor); | |
| 114 } | 122 } |
| 115 | 123 |
| 116 function shouldWrapAPIs() | 124 function shouldWrapAPIs() |
| 117 { | 125 { |
| 118 try | 126 try |
| 119 { | 127 { |
| 120 return !(browser.storage.local.get([]) instanceof Promise); | 128 return !(browser.storage.local.get([]) instanceof Promise); |
| 121 } | 129 } |
| 122 catch (error) | 130 catch (error) |
| 123 { | 131 { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 140 | 148 |
| 141 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList | 149 // Workaround since HTMLCollection, NodeList, StyleSheetList, and CSSRuleList |
| 142 // didn't have iterator support before Chrome 51. | 150 // didn't have iterator support before Chrome 51. |
| 143 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 | 151 // https://bugs.chromium.org/p/chromium/issues/detail?id=401699 |
| 144 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) | 152 for (let object of [HTMLCollection, NodeList, StyleSheetList, CSSRuleList]) |
| 145 { | 153 { |
| 146 if (!(Symbol.iterator in object.prototype)) | 154 if (!(Symbol.iterator in object.prototype)) |
| 147 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; | 155 object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; |
| 148 } | 156 } |
| 149 } | 157 } |
| OLD | NEW |