Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude not enumerable keys of inject object #6346

Merged
merged 7 commits into from
Sep 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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