From: wujieZ <2878354193@qq.com> Date: Wed, 5 Aug 2020 15:53:50 +0000 (+0800) Subject: fix(reactivity): use isExtensible instead of isFrozen (#1753) X-Git-Tag: v3.0.0-rc.6~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2787c34cd436e3ec4656b6986d9d14d57911a7b5;p=thirdparty%2Fvuejs%2Fcore.git fix(reactivity): use isExtensible instead of isFrozen (#1753) close #1784 --- diff --git a/packages/reactivity/__tests__/reactive.spec.ts b/packages/reactivity/__tests__/reactive.spec.ts index c0b10969ba..b7f9cdf4eb 100644 --- a/packages/reactivity/__tests__/reactive.spec.ts +++ b/packages/reactivity/__tests__/reactive.spec.ts @@ -183,11 +183,16 @@ describe('reactivity/reactive', () => { expect(isReactive(obj.bar)).toBe(false) }) - test('should not observe frozen objects', () => { + test('should not observe non-extensible objects', () => { const obj = reactive({ - foo: Object.freeze({ a: 1 }) + foo: Object.preventExtensions({ a: 1 }), + // sealed or frozen objects are considered non-extensible as well + bar: Object.freeze({ a: 1 }), + baz: Object.seal({ a: 1 }) }) expect(isReactive(obj.foo)).toBe(false) + expect(isReactive(obj.bar)).toBe(false) + expect(isReactive(obj.baz)).toBe(false) }) test('should not observe objects with __v_skip', () => { diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index 8e333fc81b..4dea9e00c8 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -39,7 +39,7 @@ const canObserve = (value: Target): boolean => { return ( !value[ReactiveFlags.SKIP] && isObservableType(toRawType(value)) && - !Object.isFrozen(value) + Object.isExtensible(value) ) }