Skip to content

Commit

Permalink
fix(inject): exclude not enumerable keys of inject object (#6346)
Browse files Browse the repository at this point in the history
close #6574
  • Loading branch information
Elevista authored and yyx990803 committed Sep 13, 2017
1 parent 1f52a2a commit 3ee62fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/core/instance/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
10 changes: 9 additions & 1 deletion test/unit/features/options/inject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down

0 comments on commit 3ee62fd

Please sign in to comment.