Skip to content

Commit

Permalink
fix: correct the has implementation in the _renderProxy (vuejs#7878)
Browse files Browse the repository at this point in the history
It's feasible that someone might ask if something other than a string is
in the proxy such as a `Symbol` that lacks a `charAt` method.  This aligns
the implementation with the `getHandler`.
  • Loading branch information
dcherman authored and aJean committed Aug 19, 2020
1 parent fb545f0 commit 1b28535
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/instance/proxy.js
Expand Up @@ -45,7 +45,7 @@ if (process.env.NODE_ENV !== 'production') {
const hasHandler = {
has (target, key) {
const has = key in target
const isAllowed = allowedGlobals(key) || key.charAt(0) === '_'
const isAllowed = allowedGlobals(key) || (typeof key === 'string' && key.charAt(0) === '_')
if (!has && !isAllowed) {
warnNonPresent(target, key)
}
Expand Down
17 changes: 17 additions & 0 deletions test/unit/features/instance/render-proxy.spec.js
Expand Up @@ -28,5 +28,22 @@ if (typeof Proxy !== 'undefined') {
}).$mount()
expect(`Property or method "a" is not defined`).not.toHaveBeenWarned()
})

it('support symbols using the `in` operator in hand-written render functions', () => {
const sym = Symbol()

const vm = new Vue({
created () {
this[sym] = 'foo'
},
render (h) {
if (sym in this) {
return h('div', [this[sym]])
}
}
}).$mount()

expect(vm.$el.textContent).toBe('foo')
})
})
}

0 comments on commit 1b28535

Please sign in to comment.