PatchFlags,
camelize,
capitalize,
- def,
extend,
hasOwn,
hyphenate,
setCurrentInstance,
} from './component'
import { isEmitListener } from './componentEmits'
-import { InternalObjectKey } from './vnode'
import type { AppContext } from './apiCreateApp'
import { createPropsDefaultThis } from './compat/props'
import { isCompatEnabled, softAssertCompatEnabled } from './compat/compatConfig'
export type NormalizedProps = Record<string, NormalizedProp>
export type NormalizedPropsOptions = [NormalizedProps, string[]] | []
+/**
+ * Used during vnode props normalization to check if the vnode props is the
+ * attrs object of a component via `Object.getPrototypeOf`. This is more
+ * performant than defining a non-enumerable property.
+ */
+export const attrsProto = {}
+
export function initProps(
instance: ComponentInternalInstance,
rawProps: Data | null,
isSSR = false,
) {
const props: Data = {}
- const attrs: Data = {}
- def(attrs, InternalObjectKey, 1)
+ const attrs: Data = Object.create(attrsProto)
instance.propsDefaults = Object.create(null)
import { type ComponentInternalInstance, currentInstance } from './component'
import {
- InternalObjectKey,
type VNode,
type VNodeChild,
type VNodeNormalizedChildren,
// we should avoid the proxy object polluting the slots of the internal instance
instance.slots = toRaw(children as InternalSlots)
// make compiler marker non-enumerable
- def(children as InternalSlots, '_', type)
+ def(instance.slots, '_', type)
} else {
normalizeObjectSlots(
children as RawSlots,
normalizeVNodeSlots(instance, children)
}
}
- def(instance.slots, InternalObjectKey, 1)
}
export const updateSlots = (
import { defineLegacyVNodeProperties } from './compat/renderFn'
import { ErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
import type { ComponentPublicInstance } from './componentPublicInstance'
+import { attrsProto } from './componentProps'
export const Fragment = Symbol.for('v-fgt') as any as {
__isFragment: true
)
}
-export const InternalObjectKey = `__vInternal`
-
const normalizeKey = ({ key }: VNodeProps): VNode['key'] =>
key != null ? key : null
export function guardReactiveProps(props: (Data & VNodeProps) | null) {
if (!props) return null
- return isProxy(props) || InternalObjectKey in props
+ return isProxy(props) || Object.getPrototypeOf(props) === attrsProto
? extend({}, props)
: props
}
} else {
type = ShapeFlags.SLOTS_CHILDREN
const slotFlag = (children as RawSlots)._
- if (!slotFlag && !(InternalObjectKey in children!)) {
+ if (!slotFlag) {
// if slots are not normalized, attach context instance
// (compiled / normalized slots already have context)
;(children as RawSlots)._ctx = currentRenderingInstance