Prevent only target (leaf) property from being overtaken

Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/156#issuecomment-707095193

Related commit:
- 6e010ecc0f
This commit is contained in:
Raymond Hill 2020-10-12 11:00:30 -04:00
parent b38f7b9899
commit a08f33e09d
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 4 additions and 4 deletions

View File

@ -741,7 +741,7 @@
}; };
// https://github.com/uBlockOrigin/uBlock-issues/issues/156 // https://github.com/uBlockOrigin/uBlock-issues/issues/156
// Support multiple trappers for the same property. // Support multiple trappers for the same property.
const trapProp = function(owner, prop, handler) { const trapProp = function(owner, prop, configurable, handler) {
if ( handler.init(owner[prop]) === false ) { return; } if ( handler.init(owner[prop]) === false ) { return; }
const odesc = Object.getOwnPropertyDescriptor(owner, prop); const odesc = Object.getOwnPropertyDescriptor(owner, prop);
let prevGetter, prevSetter; let prevGetter, prevSetter;
@ -754,7 +754,7 @@
} }
} }
Object.defineProperty(owner, prop, { Object.defineProperty(owner, prop, {
configurable: false, configurable,
get() { get() {
if ( prevGetter !== undefined ) { if ( prevGetter !== undefined ) {
prevGetter(); prevGetter();
@ -772,7 +772,7 @@
const trapChain = function(owner, chain) { const trapChain = function(owner, chain) {
const pos = chain.indexOf('.'); const pos = chain.indexOf('.');
if ( pos === -1 ) { if ( pos === -1 ) {
trapProp(owner, chain, { trapProp(owner, chain, false, {
v: undefined, v: undefined,
init: function(v) { init: function(v) {
if ( mustAbort(v) ) { return false; } if ( mustAbort(v) ) { return false; }
@ -798,7 +798,7 @@
trapChain(v, chain); trapChain(v, chain);
return; return;
} }
trapProp(owner, prop, { trapProp(owner, prop, true, {
v: undefined, v: undefined,
init: function(v) { init: function(v) {
this.v = v; this.v = v;