import { OperationTypes } from './operations'
import { track, trigger } from './effect'
import { LOCKED } from './lock'
-import { isObject } from '@vue/shared'
+import { isObject, hasOwn } from '@vue/shared'
import { isRef } from './ref'
-const hasOwnProperty = Object.prototype.hasOwnProperty
-
const builtInSymbols = new Set(
Object.getOwnPropertyNames(Symbol)
.map(key => (Symbol as any)[key])
receiver: any
): boolean {
value = toRaw(value)
- const hadKey = hasOwnProperty.call(target, key)
+ const hadKey = hasOwn(target, key)
const oldValue = target[key]
if (isRef(oldValue) && !isRef(value)) {
oldValue.value = value
}
function deleteProperty(target: any, key: string | symbol): boolean {
- const hadKey = hasOwnProperty.call(target, key)
+ const hadKey = hasOwn(target, key)
const oldValue = target[key]
const result = Reflect.deleteProperty(target, key)
if (hadKey) {
import { track, trigger } from './effect'
import { OperationTypes } from './operations'
import { LOCKED } from './lock'
-import { isObject, capitalize } from '@vue/shared'
+import { isObject, capitalize, hasOwn } from '@vue/shared'
const toReactive = (value: any) => (isObject(value) ? reactive(value) : value)
const toReadonly = (value: any) => (isObject(value) ? readonly(value) : value)
receiver: any
) {
target =
- instrumentations.hasOwnProperty(key) && key in target
- ? instrumentations
- : target
+ hasOwn(instrumentations, key) && key in target ? instrumentations : target
return Reflect.get(target, key, receiver)
}
}
isFunction,
isArray,
isObject,
- isReservedProp
+ isReservedProp,
+ hasOwn
} from '@vue/shared'
import { warn } from './warning'
import { Data, ComponentInstance } from './component'
if (isReservedProp(key)) continue
// any non-declared data are put into a separate `attrs` object
// for spreading
- if (hasDeclaredProps && !options.hasOwnProperty(key)) {
+ if (hasDeclaredProps && !hasOwn(options, key)) {
;(attrs || (attrs = {}))[key] = rawProps[key]
} else {
setProp(key, rawProps[key])
for (const key in options) {
let opt = options[key]
if (opt == null) continue
- const isAbsent = !props.hasOwnProperty(key)
- const hasDefault = opt.hasOwnProperty('default')
+ const isAbsent = !hasOwn(props, key)
+ const hasDefault = hasOwn(opt, 'default')
const currentValue = props[key]
// default values
if (hasDefault && currentValue === undefined) {
) {
const rawInitialProps = toRaw(propsProxy)
for (const key in rawInitialProps) {
- if (!props.hasOwnProperty(key)) {
+ if (!hasOwn(props, key)) {
delete propsProxy[key]
}
}
import { ComponentInstance } from './component'
import { nextTick } from './scheduler'
import { instanceWatch } from './apiWatch'
-import { EMPTY_OBJ } from '@vue/shared'
+import { EMPTY_OBJ, hasOwn } from '@vue/shared'
export const RenderProxyHandlers = {
get(target: ComponentInstance, key: string) {
const { renderContext, data, props, propsProxy } = target
- if (data !== EMPTY_OBJ && data.hasOwnProperty(key)) {
+ if (data !== EMPTY_OBJ && hasOwn(data, key)) {
return data[key]
- } else if (renderContext.hasOwnProperty(key)) {
+ } else if (hasOwn(renderContext, key)) {
return renderContext[key]
- } else if (props.hasOwnProperty(key)) {
+ } else if (hasOwn(props, key)) {
// return the value from propsProxy for ref unwrapping and readonly
return (propsProxy as any)[key]
} else {
},
set(target: ComponentInstance, key: string, value: any): boolean {
const { data, renderContext } = target
- if (data !== EMPTY_OBJ && data.hasOwnProperty(key)) {
+ if (data !== EMPTY_OBJ && hasOwn(data, key)) {
data[key] = value
- } else if (renderContext.hasOwnProperty(key)) {
+ } else if (hasOwn(renderContext, key)) {
renderContext[key] = value
} else if (key[0] === '$' && key.slice(1) in target) {
// TODO warn attempt of mutating public property
return a as any
}
+const hasOwnProperty = Object.prototype.hasOwnProperty
+export const hasOwn = (
+ val: object,
+ key: string | symbol
+): key is keyof typeof val => hasOwnProperty.call(val, key)
+
export const isArray = Array.isArray
export const isFunction = (val: any): val is Function =>
typeof val === 'function'