Skip to content

Define own __proto__ key as a data property in __rest - #294

Open
suraiya-ctrl wants to merge 1 commit into
microsoft:mainfrom
suraiya-ctrl:rest-proto-key
Open

suraiya-ctrl wants to merge 1 commit into
microsoft:mainfrom
suraiya-ctrl:rest-proto-key

Conversation

@suraiya-ctrl

Copy link
Copy Markdown

__rest copies the remaining keys with t[p] = s[p], so an own __proto__ key on the source goes through the Object.prototype.__proto__ setter instead of becoming a property:

  • const { id, ...rest } = JSON.parse('{"id":1,"__proto__":{"isAdmin":true}}') natively gives rest.isAdmin === undefined and an own __proto__ key
  • downleveled through tslib, rest's prototype becomes the payload object, so rest.isAdmin === true and Object.keys(rest) is empty
  • native object rest uses CreateDataProperty, so defining that one key with Object.defineProperty matches spec behavior; all other keys keep the plain assignment

Added test/node/rest.test.js, which fails on all three builds before this change and passes after. Object spread (__assign) is unchanged since it defers to Object.assign, which uses [[Set]] natively too. The emitted helper in microsoft/TypeScript would need the same change.

@suraiya-ctrl

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Digiscrypt Technologies"

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.

1 participant