fix(runtime-core): avoid accidental access of Object.prototype properties

This commit is contained in:
Evan You 2020-07-01 20:12:47 -04:00
parent b0fb1e06b4
commit f3e9c1b59d
2 changed files with 6 additions and 8 deletions

View File

@ -723,9 +723,8 @@ export function resolveMergedOptions(
function mergeOptions(to: any, from: any, instance: ComponentInternalInstance) { function mergeOptions(to: any, from: any, instance: ComponentInternalInstance) {
const strats = instance.appContext.config.optionMergeStrategies const strats = instance.appContext.config.optionMergeStrategies
for (const key in from) { for (const key in from) {
const strat = strats && strats[key] if (strats && hasOwn(strats, key)) {
if (strat) { to[key] = strats[key](to[key], from[key], instance.proxy, key)
to[key] = strat(to[key], from[key], instance.proxy, key)
} else if (!hasOwn(to, key)) { } else if (!hasOwn(to, key)) {
to[key] = from[key] to[key] = from[key]
} }

View File

@ -166,10 +166,9 @@ export type ComponentPublicInstanceConstructor<
new (): T new (): T
} }
const publicPropertiesMap: Record< type PublicPropertiesMap = Record<string, (i: ComponentInternalInstance) => any>
string,
(i: ComponentInternalInstance) => any const publicPropertiesMap: PublicPropertiesMap = extend(Object.create(null), {
> = {
$: i => i, $: i => i,
$el: i => i.vnode.el, $el: i => i.vnode.el,
$data: i => i.data, $data: i => i.data,
@ -184,7 +183,7 @@ const publicPropertiesMap: Record<
$forceUpdate: i => () => queueJob(i.update), $forceUpdate: i => () => queueJob(i.update),
$nextTick: () => nextTick, $nextTick: () => nextTick,
$watch: __FEATURE_OPTIONS__ ? i => instanceWatch.bind(i) : NOOP $watch: __FEATURE_OPTIONS__ ? i => instanceWatch.bind(i) : NOOP
} } as PublicPropertiesMap)
const enum AccessTypes { const enum AccessTypes {
SETUP, SETUP,