From b0f5a73f87b92a131bea1bca6a3812544e6e6461 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Thu, 24 Sep 2020 21:17:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20lazy=20added=20non-configurable?= =?UTF-8?q?=20props=20should=20be=20reported=20as=20configurable=20to=20av?= =?UTF-8?q?oid=20TypeError=20(#953)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sandbox/__tests__/proxySandbox.test.ts | 7 +++++++ src/sandbox/proxySandbox.ts | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/sandbox/__tests__/proxySandbox.test.ts b/src/sandbox/__tests__/proxySandbox.test.ts index dc02ba0..769b3eb 100644 --- a/src/sandbox/__tests__/proxySandbox.test.ts +++ b/src/sandbox/__tests__/proxySandbox.test.ts @@ -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'); diff --git a/src/sandbox/proxySandbox.ts b/src/sandbox/proxySandbox.ts index 967007e..223c34b 100644 --- a/src/sandbox/proxySandbox.ts +++ b/src/sandbox/proxySandbox.ts @@ -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; }