Index: lib/content/snippets.js |
=================================================================== |
--- a/lib/content/snippets.js |
+++ b/lib/content/snippets.js |
@@ -754,16 +754,48 @@ |
} |
exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, |
wrapPropertyAccess, |
overrideOnError, |
randomId); |
/** |
+ * Patches a property on the window object to abort execution when the |
+ * property is written (set). |
Manish Jethani
2019/01/15 14:13:29
Nit: I don't think "(set)" is necessary, but it's
hub
2019/01/15 16:40:29
I ought it clarify, but then I don't for "read" so
|
+ * |
+ * No error is be printed to the console. |
Manish Jethani
2019/01/15 14:13:30
Correction: No error is printed to the console.
W
hub
2019/01/15 16:40:29
Done.
BTW it is a cut&paste error that is found i
|
+ * |
+ * The idea originates from |
+ * {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237bfc268ecfc9d9d2b/filters/resources.txt#L1671 uBlock Origin}. |
+ * |
+ * @param {string} property The name of the property. |
+ */ |
+function abortOnPropertyWrite(property) |
+{ |
+ if (!property) |
+ return; |
+ |
+ let rid = randomId(); |
+ |
+ function abort() |
+ { |
+ throw new ReferenceError(rid); |
+ } |
+ |
+ if (wrapPropertyAccess(window, property, {set: abort})) |
Manish Jethani
2019/01/15 14:13:29
Do we need a getter here?
hub
2019/01/15 16:40:30
We don't.
Manish Jethani
2019/01/15 17:24:16
Acknowledged.
|
+ overrideOnError(rid); |
+} |
+ |
+exports["abort-on-property-write"] = makeInjector(abortOnPropertyWrite, |
+ wrapPropertyAccess, |
+ overrideOnError, |
+ randomId); |
+ |
+/** |
* Aborts the execution of an inline script. |
* |
* @param {string} api API function or property name to anchor on. |
* @param {?string} [search] If specified, only scripts containing the given |
* string are prevented from executing. If the string begins and ends with a |
* slash (<code>/</code>), the text in between is treated as a regular |
* expression. |
*/ |