Skip to content

Emit computed property name for __proto__ in generated object literals - #526

Open
Tejas Lamba (TejasLamba2006) wants to merge 1 commit into
microsoft:mainfrom
TejasLamba2006:fix-proto-property-generation
Open

Tejas Lamba (TejasLamba2006) wants to merge 1 commit into
microsoft:mainfrom
TejasLamba2006:fix-proto-property-generation

Conversation

@TejasLamba2006

Copy link
Copy Markdown

A JSON object with an own __proto__ field was emitted as a quoted property name, which JavaScript interprets as a prototype setter instead of a data property. Now emits ["__proto__"] (a computed property name) for this one key, which correctly defines it as an own data property. Other keys are unchanged. Fixes #497.

A JSON object with an own __proto__ field was emitted as a quoted
property name ("__proto__": value), which JavaScript interprets as a
prototype setter instead of a data property. Now emits ["__proto__"]
(a computed property name) for this one key, which correctly defines it
as an own data property. Other keys are unchanged. Fixes microsoft#497.
Copilot AI balanced review requested due to automatic review settings November 8, 2026 10:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The active finding identifies a test-coverage gap: the __proto__ own-property assertion exercises only evaluateJsonProgram, not the changed generated module’s emitted literal.

1 open issue

Review effort: Max

Comment on lines +212 to +217
it("evaluates an object with __proto__ as an own data property", async () => {
const program = JSON.parse('{"@steps":[{"@func":"first","@args":[{"__proto__":"value"}]}]}');
const result = await evaluateJsonProgram(program, async (_func, args) => args[0]);
assert.ok(Object.prototype.hasOwnProperty.call(result, "__proto__"));
assert.equal((result as Record<string, unknown>)["__proto__"], "value");
});

@robgruen robgruen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Tejas Lamba (@TejasLamba2006) for this focused fix. The production change is nicely scoped and looked sound in the local checks.

My belt-and-suspenders testing habit is showing a little here, but could we have the regression tests execute the generated module, rather than only checking its text? The interpreter already preserves this field, so the interpreter-only assertion does not directly cover the code-generation bug.

I'd like to see string, object, and null values covered, checking that the generated result has an own __proto__ data property, preserves the serialized data, and matches the interpreter result. Please keep execution limited to controlled test fixtures; production code should continue generating text as before.

JOJO (@moneymaker26754-crypto), thank you for the earlier work in draft #497, which already includes the same fix and these behavioral regression tests. Could you both coordinate the overlapping contributions? If the work is consolidated into one PR, let's preserve credit for both authors, including the implementation and regression coverage.

Since #497 is itself an open draft PR rather than an issue, "Related to #497" would describe the relationship more accurately than "Fixes #497".

I'm requesting changes for the regression coverage and coordination above, not a larger rewrite. Thanks to you both for working on this.

@robgruen

Copy link
Copy Markdown
Contributor

Just to be clear I'd like to consolidate onto #497 instead of #526

@TejasLamba2006

Copy link
Copy Markdown
Author

Makes sense to consolidate onto #497 since the same fix is already there. JOJO (@moneymaker26754-crypto) I can add the behavioral regression tests (executing the generated module with string, object, and null proto values) to your branch if that helps, or you can grab them from here. Let me know what works best.

Happy to close this one once #497 has the coverage sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants