🐛 lazy added non-configurable props should be reported as configurable to avoid TypeError (#953)

This commit is contained in:
Kuitos 2020-09-24 21:17:40 +08:00 committed by GitHub
parent 969761a11b
commit b0f5a73f87
2 changed files with 11 additions and 0 deletions

View File

@ -135,6 +135,13 @@ test('descriptor of non-configurable and non-enumerable property existed in raw
});
});
test('A property cannot be reported as non-configurable, if it does not exists as an own property of the target object', () => {
const { proxy } = new ProxySandbox('non-configurable');
Object.defineProperty(window, 'nonConfigurablePropAfterSandboxCreated', { value: 'test', configurable: false });
const descriptor = Object.getOwnPropertyDescriptor(proxy, 'nonConfigurablePropAfterSandboxCreated');
expect(descriptor?.configurable).toBeTruthy();
});
test('property added by Object.defineProperty should works as expect', () => {
const { proxy } = new ProxySandbox('object-define-property-test');

View File

@ -219,6 +219,10 @@ export default class ProxySandbox implements SandBox {
if (rawWindow.hasOwnProperty(p)) {
const descriptor = Object.getOwnPropertyDescriptor(rawWindow, p);
descriptorTargetMap.set(p, 'rawWindow');
// A property cannot be reported as non-configurable, if it does not exists as an own property of the target object
if (descriptor && !descriptor.configurable) {
descriptor.configurable = true;
}
return descriptor;
}