Browse Source

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

close #6574
dev
Elevista 7 years ago
committed by Evan You
parent
commit
3ee62fd59e
  1. 4
      src/core/instance/inject.js
  2. 10
      test/unit/features/options/inject.spec.js

4
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++) {

10
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' }}

Loading…
Cancel
Save