From ac683a917b1f4cf567c2e28b10fa6cb6c035642d Mon Sep 17 00:00:00 2001 From: Yang Jun Date: Thu, 14 May 2026 02:23:08 +0800 Subject: [PATCH] test(context): cover Object.prototype keys under ownPropertyOnly - Add getSync cases for constructor and valueOf on plain objects - Remove scope storage tests that used the in operator Co-authored-by: Cursor --- src/context/context.spec.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/context/context.spec.ts b/src/context/context.spec.ts index 2692b0704..b7e182e5b 100644 --- a/src/context/context.spec.ts +++ b/src/context/context.spec.ts @@ -138,6 +138,11 @@ describe('Context', function () { ctx.push({ foo: [] }) return expect(ctx.getSync(['foo', 'reduce'])).toEqual(undefined) }) + it('should return undefined for typical Object.prototype properties (e.g. constructor, valueOf)', function () { + ctx.push({ obj: {} }) + expect(ctx.getSync(['obj', 'constructor'])).toEqual(undefined) + expect(ctx.getSync(['obj', 'valueOf'])).toEqual(undefined) + }) it('should return undefined for function prototype property', function () { function Foo () {} Foo.prototype.bar = 'BAR' @@ -216,17 +221,4 @@ describe('Context', function () { expect(ctx.getSync(['foo'])).toEqual('zoo') }) }) - describe('scope storage', function () { - it('should not treat Object.prototype properties as implicit keys on bottom scope', function () { - const bottom = new Context().bottom() as Record - expect('toString' in bottom).toBe(false) - expect('hasOwnProperty' in bottom).toBe(false) - }) - it('should merge into a scope result without implicit Object.prototype keys', function () { - const all = new Context({ a: 1 }).getAll() as Record - expect(all.a).toBe(1) - expect('toString' in all).toBe(false) - expect('hasOwnProperty' in all).toBe(false) - }) - }) })