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: Created Jan. 11, 2019, 2:39 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
@@ -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.
*/
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld