Index: lib/content/snippets.js |
=================================================================== |
--- a/lib/content/snippets.js |
+++ b/lib/content/snippets.js |
@@ -695,21 +695,45 @@ |
// 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 name = property.slice(0, dot); |
+ property = property.slice(dot + 1); |
+ let value = object[name]; |
+ if (value && typeof value == "object") |
+ return wrapPropertyAccess(value, property, descriptor); |
+ |
+ let currentDescriptor = Object.getOwnPropertyDescriptor(object, name); |
if (currentDescriptor && !currentDescriptor.configurable) |
return false; |
- Object.defineProperty(object, property, descriptor); |
+ let v; |
Manish Jethani
2019/02/20 06:20:46
There are two things missing in this implementatio
Manish Jethani
2019/02/20 06:28:53
Let me elaborate a little ...
hub
2019/02/22 17:36:19
Fixed them.
|
+ let setter = a => |
+ { |
+ v = a; |
+ if (a && typeof a == "object") |
+ wrapPropertyAccess(a, property, descriptor); |
+ }; |
+ Object.defineProperty(object, name, {get: () => v, set: setter}); |
return true; |
} |
/** |
* 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. |