Future proof: getters my be values in other browsers

Example: window.opener is a value property in Chrome.
This commit is contained in:
kkapsner 2019-08-16 17:34:16 +02:00
parent d666d68812
commit a95fae3de8
2 changed files with 39 additions and 0 deletions

View File

@ -349,6 +349,39 @@
Object.defineProperty(object, name, descriptor);
}
else if (
changedGetter.valueGenerator &&
descriptor && descriptor.hasOwnProperty("value")
){
const protectedAPIFeatures = prefs("protectedAPIFeatures");
if (
functionStatus.active &&
(
!protectedAPIFeatures.hasOwnProperty(name) ||
protectedAPIFeatures[name]
)
){
switch (functionStatus.mode){
case "ask": case "block": case "fake":
descriptor.value = changedGetter.valueGenerator({
mode: functionStatus.mode,
original: descriptor.value,
notify: function notifyCallback(messageId){
notify({
url: getURL(window),
errorStack: (new Error()).stack,
messageId,
timestamp: new Date(),
functionName: name,
api: changedGetter.api
});
}
});
Object.defineProperty(object, name, descriptor);
break;
}
}
}
else {
logging.error("Try to fake non getter property:", changedGetter);
}

View File

@ -36,6 +36,12 @@
}
};
return Object.getOwnPropertyDescriptor(temp, "opener").get;
},
valueGenerator: function({original, notify}){
if (original !== null){
notify("fakedWindowReadout");
}
return null;
}
},
{