Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/content/snippets.js

Issue 29979555: Issue 7207 - Implement abort-on-property-write snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Addressed comment typo Created Jan. 15, 2019, 4:40 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/content/snippets.js
===================================================================
--- a/lib/content/snippets.js
+++ b/lib/content/snippets.js
@@ -725,17 +725,17 @@
return (() => {}).call.call(onerror, this, message, ...rest);
};
}
/**
* Patches a property on the window object to abort execution when the
* property is read.
*
- * No error is be printed to the console.
+ * No error is printed to the console.
*
* The idea originates from
* {@link https://github.com/uBlockOrigin/uAssets/blob/80b195436f8f8d78ba713237bfc268ecfc9d9d2b/filters/resources.txt#L1703 uBlock Origin}.
*
* @param {string} property The name of the property.
*/
function abortOnPropertyRead(property)
{
@@ -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.
+ *
+ * No error is printed to the console.
+ *
+ * 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}))
+ 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.
*/
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld