]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): use isExtensible instead of isFrozen (#1753)
authorwujieZ <2878354193@qq.com>
Wed, 5 Aug 2020 15:53:50 +0000 (23:53 +0800)
committerGitHub <noreply@github.com>
Wed, 5 Aug 2020 15:53:50 +0000 (11:53 -0400)
close #1784

packages/reactivity/__tests__/reactive.spec.ts
packages/reactivity/src/reactive.ts

index c0b10969ba439e26d37fc69fa20431b8ce4fe1be..b7f9cdf4eb3ae3c8ff15ea32c7b6151f55dcf16d 100644 (file)
@@ -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', () => {
index 8e333fc81b511d339327e84b6929cf7ee7dac7c2..4dea9e00c866c869203ddf2b0c27b28edb234c27 100644 (file)
@@ -39,7 +39,7 @@ const canObserve = (value: Target): boolean => {
   return (
     !value[ReactiveFlags.SKIP] &&
     isObservableType(toRawType(value)) &&
-    !Object.isFrozen(value)
+    Object.isExtensible(value)
   )
 }