From 1b2853541d10e27520537e6b2e514126549f273b Mon Sep 17 00:00:00 2001 From: dherman Date: Thu, 22 Mar 2018 09:53:28 -0400 Subject: [PATCH] fix: correct the `has` implementation in the `_renderProxy` (#7878) 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`. --- src/core/instance/proxy.js | 2 +- .../unit/features/instance/render-proxy.spec.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/instance/proxy.js b/src/core/instance/proxy.js index 0d6dcf80639..8c821baa09b 100644 --- a/src/core/instance/proxy.js +++ b/src/core/instance/proxy.js @@ -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) } diff --git a/test/unit/features/instance/render-proxy.spec.js b/test/unit/features/instance/render-proxy.spec.js index d4d01ebcf2a..9a2365ae4c1 100644 --- a/test/unit/features/instance/render-proxy.spec.js +++ b/test/unit/features/instance/render-proxy.spec.js @@ -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') + }) }) }