From 73117f6b5b1e36c9400248ed9e815839c49a12c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Exbrayat?= Date: Fri, 5 Feb 2021 19:59:46 +0100 Subject: [PATCH] fix(runtime-core): allow overriding properties other than props (#3105) This is useful for testing, as Jest can't spy on an object without `hasOwnProperty`. VTU can add it, but this commit is needed first. --- packages/runtime-core/__tests__/componentProps.spec.ts | 4 ++++ packages/runtime-core/src/componentPublicInstance.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/componentProps.spec.ts b/packages/runtime-core/__tests__/componentProps.spec.ts index 2c072d45aae..f89607c57e0 100644 --- a/packages/runtime-core/__tests__/componentProps.spec.ts +++ b/packages/runtime-core/__tests__/componentProps.spec.ts @@ -295,6 +295,10 @@ describe('component props', () => { ;(instance!.proxy as any).foo = 2 }).toThrow(TypeError) expect(`Attempting to mutate prop "foo"`).toHaveBeenWarned() + // should not throw when overriding properties other than props + expect(() => { + ;(instance!.proxy as any).hasOwnProperty = () => {} + }).not.toThrow(TypeError) }) test('merging props from mixins and extends', () => { diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 0269fdf66db..ba7eda893b1 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -368,7 +368,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { setupState[key] = value } else if (data !== EMPTY_OBJ && hasOwn(data, key)) { data[key] = value - } else if (key in instance.props) { + } else if (hasOwn(instance.props, key)) { __DEV__ && warn( `Attempting to mutate prop "${key}". Props are readonly.`,