refactor: use global whitelist for render proxy has check

This commit is contained in:
Evan You
2019-10-02 10:37:06 -04:00
parent d87255ce46
commit 191db785bd
4 changed files with 20 additions and 23 deletions

View File

@@ -1,7 +1,7 @@
import { ComponentInternalInstance, Data } from './component'
import { nextTick } from './scheduler'
import { instanceWatch } from './apiWatch'
import { EMPTY_OBJ, hasOwn } from '@vue/shared'
import { EMPTY_OBJ, hasOwn, globalsWhitelist } from '@vue/shared'
import { ExtracComputedReturns } from './apiOptions'
import { UnwrapRef } from '@vue/reactivity'
@@ -78,15 +78,10 @@ export const PublicInstanceProxyHandlers = {
}
}
},
has(target: ComponentInternalInstance, key: string): boolean {
const { renderContext, data, props } = target
// TODO handle $xxx properties
return (
key[0] !== '_' &&
((data !== EMPTY_OBJ && hasOwn(data, key)) ||
hasOwn(renderContext, key) ||
hasOwn(props, key))
)
// this trap is only called in browser-compiled render functions that use
// `with (this) {}`
has(_: any, key: string): boolean {
return key[0] !== '_' && !globalsWhitelist.has(key)
},
set(target: ComponentInternalInstance, key: string, value: any): boolean {
const { data, renderContext } = target