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

Unified Diff: lib/content/snippets.js

Issue 29995559: Issue 7236 - Handle sub properties in abort-on-property snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Handle properties being overridden. Created Feb. 22, 2019, 5:35 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 | test/browser/snippets.js » ('j') | 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
@@ -695,22 +695,46 @@
// 2176782336 - 60466176 = 2116316160. This ensure to always have 6
// chars even if Math.random() returns its minimum value 0.0
//
return Math.floor(Math.random() * 2116316160 + 60466176).toString(36);
}
function wrapPropertyAccess(object, property, descriptor)
{
- let currentDescriptor = Object.getOwnPropertyDescriptor(object, property);
+ let dot = property.indexOf(".");
+ if (dot == -1)
+ {
+ // simple property case.
+ let currentDescriptor = Object.getOwnPropertyDescriptor(object, property);
+ if (currentDescriptor && !currentDescriptor.configurable)
+ return false;
+
+ Object.defineProperty(object, property, descriptor);
+ return true;
+ }
+ let result = true;
+ let name = property.slice(0, dot);
+ property = property.slice(dot + 1);
+ let value = object[name];
+ if (value && typeof value == "object")
+ result = wrapPropertyAccess(value, property, descriptor);
+
+ let currentDescriptor = Object.getOwnPropertyDescriptor(object, name);
if (currentDescriptor && !currentDescriptor.configurable)
- return false;
+ return result;
Manish Jethani 2019/03/04 13:28:49 If I understand this correctly, we return the resu
hub 2019/03/05 13:49:13 I should have set `result` to `false` (line 714).
Manish Jethani 2019/03/06 19:07:12 This has the opposite problem though. If we're try
hub 2019/03/06 21:22:03 Silly me, I should just return true at then end si
- Object.defineProperty(object, property, descriptor);
- return true;
+ let setter = a =>
Manish Jethani 2019/03/04 13:28:49 Nit: Instead of `a` this would seem better as `new
hub 2019/03/05 13:49:13 Done.
+ {
+ value = a;
+ if (a && typeof a == "object")
+ wrapPropertyAccess(a, property, descriptor);
+ };
+ Object.defineProperty(object, name, {get: () => value, set: setter});
+ return result;
}
/**
* Overrides the <code>onerror</code> handler to discard tagged error messages
* from our property wrapping.
*
* @param {string} magic The magic string that tags the error message.
*/
« no previous file with comments | « no previous file | test/browser/snippets.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld