Просмотр исходного кода

fix(inject): exclude not enumerable keys of inject object (#6346)

close #6574
Elevista 8 лет назад
Родитель
Сommit
3ee62fd59e
2 измененных файлов с 12 добавлено и 2 удалено
  1. 3 1
      src/core/instance/inject.js
  2. 9 1
      test/unit/features/options/inject.spec.js

+ 3 - 1
src/core/instance/inject.js

@@ -41,7 +41,9 @@ export function resolveInject (inject: any, vm: Component): ?Object {
     // inject is :any because flow is not smart enough to figure out cached
     const result = Object.create(null)
     const keys = hasSymbol
-        ? Reflect.ownKeys(inject)
+        ? Reflect.ownKeys(inject).filter(key => {
+          return Object.getOwnPropertyDescriptor(inject, key).enumerable
+        })
         : Object.keys(inject)
 
     for (let i = 0; i < keys.length; i++) {

+ 9 - 1
test/unit/features/options/inject.spec.js

@@ -362,7 +362,15 @@ describe('Options provide/inject', () => {
     expect(`Injection "baz" not found`).not.toHaveBeenWarned()
   })
 
-  // GitHub issue #6008
+  it('should not warn when injection key which is not provided is not enumerable', () => {
+    const parent = new Vue({ provide: { foo: 1 }})
+    const inject = { foo: 'foo' }
+    Object.defineProperty(inject, '__ob__', { enumerable: false, value: '__ob__' })
+    new Vue({ parent, inject })
+    expect(`Injection "__ob__" not found`).not.toHaveBeenWarned()
+  })
+
+  // Github issue #6008
   it('should merge provide from mixins (objects)', () => {
     const mixinA = { provide: { foo: 'foo' }}
     const mixinB = { provide: { bar: 'bar' }}