diff --git a/packages/runtime-core/__tests__/componentPublicInstance.spec.ts b/packages/runtime-core/__tests__/componentPublicInstance.spec.ts index c4c456b5f7a..c1797073a4a 100644 --- a/packages/runtime-core/__tests__/componentPublicInstance.spec.ts +++ b/packages/runtime-core/__tests__/componentPublicInstance.spec.ts @@ -209,6 +209,22 @@ describe('component: proxy', () => { ]) }) + test('allow calling hasOwnProperty', () => { + let instanceProxy: any + const Comp = { + render() {}, + mounted() { + instanceProxy = this + } + } + + const app = createApp(Comp) + + app.mount(nodeOps.createElement('div')) + + expect(instanceProxy.hasOwnProperty).not.toBeNull() + }) + // #864 test('should not warn declared but absent props', () => { const Comp = { diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 9b67c9132c7..a8ac52d1f51 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -387,6 +387,8 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { `but is not defined on instance.` ) } + } else if (key === 'hasOwnProperty') { + return ctx.hasOwnProperty } },