File tree 3 files changed +31
-2
lines changed
test/unit/features/options
3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1
1
/* @flow */
2
2
3
+ import { isNative } from 'core/util/env'
4
+
5
+ const hasReflect = typeof Reflect !== 'undefined' && isNative ( Reflect . ownKeys )
6
+
3
7
export function initInjections ( vm : Component ) {
4
8
const provide = vm . $options . provide
5
9
const inject : any = vm . $options . inject
@@ -12,7 +16,12 @@ export function initInjections (vm: Component) {
12
16
// inject is :any because flow is not smart enough to figure out cached
13
17
// isArray here
14
18
const isArray = Array . isArray ( inject )
15
- const keys = isArray ? inject : Object . keys ( inject )
19
+ const keys = isArray
20
+ ? inject
21
+ : hasReflect
22
+ ? Reflect . ownKeys ( inject )
23
+ : Object . keys ( inject )
24
+
16
25
for ( let i = 0 ; i < keys . length ; i ++ ) {
17
26
const key = keys [ i ]
18
27
const provideKey = isArray ? key : inject [ key ]
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ export const isServerRendering = () => {
37
37
export const devtools = inBrowser && window . __VUE_DEVTOOLS_GLOBAL_HOOK__
38
38
39
39
/* istanbul ignore next */
40
- function isNative ( Ctor : Function ) : boolean {
40
+ export function isNative ( Ctor : Function ) : boolean {
41
41
return / n a t i v e c o d e / . test ( Ctor . toString ( ) )
42
42
}
43
43
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
+ import { isNative } from 'core/util/env'
2
3
3
4
describe ( 'Options provide/inject' , ( ) => {
4
5
let injected
@@ -124,4 +125,23 @@ describe('Options provide/inject', () => {
124
125
125
126
expect ( vm . foo ) . toBe ( 1 )
126
127
} )
128
+
129
+ if ( typeof Reflect !== 'undefined' && isNative ( Reflect . ownKeys ) ) {
130
+ it ( 'with Symbol keys' , ( ) => {
131
+ const s = Symbol ( )
132
+ const vm = new Vue ( {
133
+ template : `<child/>` ,
134
+ provide : {
135
+ [ s ] : 123
136
+ } ,
137
+ components : {
138
+ child : {
139
+ inject : { s } ,
140
+ template : `<div>{{ s }}</div>`
141
+ }
142
+ }
143
+ } ) . $mount ( )
144
+ expect ( vm . $el . textContent ) . toBe ( '123' )
145
+ } )
146
+ }
127
147
} )
You can’t perform that action at this time.
0 commit comments