Repository navigation
fix(runtime): #5588 Object.assign drives Proxy-source traps #5596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Gap test for #5588 — Object.assign with a PROXY source. | ||
| // A Proxy's NaN-box payload is a small registry id, not a heap ObjectHeader | ||
| // pointer, so the raw keys_array walk used to skip it silently: no traps fired | ||
| // and a throwing ownKeys/getOwnPropertyDescriptor never propagated. Spec drives | ||
| // the source through [[OwnPropertyKeys]] -> [[GetOwnProperty]] (enumerable test) | ||
| // -> [[Get]], propagating any abrupt completion (test262 | ||
| // built-ins/Object/assign/source-own-prop-error + source-own-prop-keys-error). | ||
| // Compared byte-for-byte against `node --experimental-strip-types`. | ||
|
|
||
| function thrown(fn: () => void): string { | ||
| try { fn(); return "no throw"; } catch (e: any) { return e.constructor.name; } | ||
| } | ||
|
|
||
| // ---- throwing ownKeys trap propagates ---- | ||
| const ownKeysThrows = new Proxy({}, { | ||
| ownKeys() { throw new TypeError("ownKeys"); }, | ||
| }); | ||
| console.log(thrown(() => Object.assign({}, ownKeysThrows))); // TypeError | ||
|
|
||
| // ---- throwing getOwnPropertyDescriptor trap propagates ---- | ||
| const gopdThrows = new Proxy({ attr: null }, { | ||
| getOwnPropertyDescriptor() { throw new TypeError("gopd"); }, | ||
| }); | ||
| console.log(thrown(() => Object.assign({}, gopdThrows))); // TypeError | ||
|
|
||
| // ---- throwing get trap propagates ---- | ||
| const getThrows = new Proxy({ a: 1 }, { | ||
| get() { throw new RangeError("get"); }, | ||
| }); | ||
| console.log(thrown(() => Object.assign({}, getThrows))); // RangeError | ||
|
|
||
| // ---- plain proxy source: enumerable own props copied via the traps ---- | ||
| const plain = new Proxy({ a: 1, b: 2 }, {}); | ||
| console.log(JSON.stringify(Object.assign({}, plain))); // {"a":1,"b":2} | ||
|
|
||
| // ---- non-enumerable own props are skipped (descriptor enumerable:false) ---- | ||
| const hidden: any = {}; | ||
| Object.defineProperty(hidden, "secret", { value: 9, enumerable: false }); | ||
| hidden.shown = 1; | ||
| console.log(JSON.stringify(Object.assign({}, new Proxy(hidden, {})))); // {"shown":1} | ||
|
|
||
| // ---- get trap actually sources the values ---- | ||
| const doubler = new Proxy({ x: 2, y: 3 }, { | ||
| get(t: any, k) { return typeof t[k] === "number" ? t[k] * 2 : t[k]; }, | ||
| }); | ||
| console.log(JSON.stringify(Object.assign({}, doubler))); // {"x":4,"y":6} | ||
|
|
||
| // ---- symbol keys are copied through the traps ---- | ||
| const sym = Symbol("s"); | ||
| const symSrc: any = { plain: 1 }; | ||
| symSrc[sym] = 42; | ||
| const symOut: any = Object.assign({}, new Proxy(symSrc, {})); | ||
| console.log("symbol copied: " + (symOut[sym] === 42 && symOut.plain === 1)); // true | ||
|
|
||
| // ---- strict Set: a symbol key onto a non-extensible target throws ---- | ||
| // Source carries ONLY a symbol key, so the throw must come from the symbol | ||
| // write path (a stray string key would otherwise throw first and mask it). | ||
| const symOnly: any = {}; | ||
| symOnly[Symbol("only")] = 1; | ||
| const symOnlyProxy = new Proxy(symOnly, {}); | ||
| const frozenTarget = Object.preventExtensions({}); | ||
| console.log(thrown(() => Object.assign(frozenTarget, symOnlyProxy))); // TypeError | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| // ---- trap order: ownKeys -> getOwnPropertyDescriptor -> get, per key ---- | ||
| const order: string[] = []; | ||
| const ordered = new Proxy({ k: 7 }, { | ||
| ownKeys(t) { order.push("ownKeys"); return Reflect.ownKeys(t); }, | ||
| getOwnPropertyDescriptor(t, k) { | ||
| order.push("gopd:" + String(k)); | ||
| return Reflect.getOwnPropertyDescriptor(t, k); | ||
| }, | ||
| get(t: any, k) { order.push("get:" + String(k)); return t[k]; }, | ||
| }); | ||
| Object.assign({}, ordered); | ||
| console.log("trap order: " + order.join(",")); // ownKeys,gopd:k,get:k | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.