-
-
Notifications
You must be signed in to change notification settings - Fork 163
Fix proxy Array.from and dynamic Request headers #10280
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
Closed
proggeramlug
wants to merge
2
commits into
PerryTS:main
from
proggeramlug:fix/10270-proxy-value-shapes
Closed
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Fix Proxy values in `Array.from` and dynamic `RequestInit.headers` (#10270, | ||
| #10274; OpenCode bring-up tracker #10107). | ||
|
|
||
| - Route array proxies through iterator materialization before inspecting heap | ||
| headers, including mapped `Array.from`, Headers iterable pairs, call spread, | ||
| and collection constructors. Preserve the proxy receiver when a get trap | ||
| forwards the default iterator, and safely dispatch array-like proxy indices. | ||
| Keep concat on trapped indexed reads, preserving | ||
| holes and ignoring a custom iterator. | ||
| - Convert dynamic Request header records/iterables with | ||
| `js_headers_init_from_value`; retain the existing inline literal-header path. | ||
| - Keep proxy registry lookups behind the existing proxy-id band predicate; | ||
| Array.from checks only within its existing small-handle branch. | ||
| - Add compiled regression probes for both issue reproductions, nested proxies, | ||
| get/ownKeys traps, custom iterators, mapped conversion, and sibling consumers. |
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
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
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
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
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
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,63 @@ | ||
| //! #10270: IsArray is not proof that a Proxy id is an ArrayHeader. | ||
|
|
||
| mod support { | ||
| include!("support/proxy_value_probe.rs"); | ||
| } | ||
|
|
||
| const SOURCE: &str = r#" | ||
| const t = (name: string, f: () => any) => { try { console.log(name, JSON.stringify(f())) } catch (e: any) { console.log(name, "THROW", e.message) } } | ||
| const pa = () => new Proxy([["x-a", "1"]], {}) | ||
| t("Q1 [...proxyOverArray]", () => [...(pa() as any)].length) | ||
| t("Q2 for..of proxyOverArray", () => { let n = 0; for (const _ of pa() as any) n++; return n }) | ||
| t("Q3 Array.isArray(proxyOverArray)", () => Array.isArray(pa())) | ||
| t("Q4 proxy[Symbol.iterator] typeof", () => typeof (pa() as any)[Symbol.iterator]) | ||
| t("Q5 Array.from(proxyOverArray)", () => Array.from(pa() as any).length) | ||
| t("nested", () => Array.from(new Proxy(new Proxy([1, 2], {}), {}))) | ||
| t("trapped indices", () => Array.from(new Proxy([1, 2], { get(t: any, k: any) { return k === "0" ? 9 : t[k]; } }))) | ||
| t("custom iterator", () => Array.from(new Proxy([1, 2], { get(t: any, k: any) { return k === Symbol.iterator ? () => [7, 8, 9].values() : t[k]; } }))) | ||
| t("mapped", () => Array.from(new Proxy([1, 2], {}), (v: number, i: number) => v + i)) | ||
| t("mapped custom iterator", () => Array.from(new Proxy([1, 2], { get(t: any, k: any) { return k === Symbol.iterator ? () => [7, 8, 9].values() : t[k]; } }), (v: number) => v * 2)) | ||
| t("arraylike", () => Array.from(new Proxy({ 0: "a", 1: "b", length: 2 }, {}))) | ||
| t("removed iterator", () => Array.from(new Proxy([1, 2], { get(t: any, k: any) { return k === Symbol.iterator ? undefined : t[k]; } }))) | ||
| t("record iterator", () => Array.from(new Proxy({}, { get(t: any, k: any) { return k === Symbol.iterator ? () => [5, 6].values() : t[k]; } }))) | ||
| t("headers outer", () => new Headers(new Proxy([["x-a", "1"]], {}) as any).get("x-a")) | ||
| t("headers pair", () => new Headers([new Proxy(["x-a", "1"], {})] as any).get("x-a")) | ||
| t("plain array", () => Array.from([3, 4])) | ||
| t("of preserves proxy", () => { const p = new Proxy([1, 2], {}); return Array.of(p)[0] === p; }) | ||
| t("concat indices", () => [0].concat(new Proxy([1, 2], { get(t: any, k: any) { return k === Symbol.iterator ? () => [9].values() : k === "0" ? 7 : t[k]; } }))) | ||
| t("concat holes", () => { const a = [0].concat(new Proxy([, 2], {})); return [a.length, 1 in a, a[2]]; }) | ||
| t("call spread", () => { const count = (...xs: any[]) => xs.length; return count(...new Proxy([1, 2], {})); }) | ||
| t("set iterator", () => Array.from(new Set(new Proxy([1, 2], { get(t: any, k: any) { return k === Symbol.iterator ? () => [7, 8].values() : t[k]; } })))) | ||
| Promise.all(new Proxy([Promise.resolve(1), Promise.resolve(2)], {})).then(v => console.log("all", JSON.stringify(v))) | ||
| "#; | ||
|
|
||
| #[test] | ||
| fn proxy_array_from_and_headers_iterables() { | ||
| assert_eq!( | ||
| support::compile_and_run(SOURCE), | ||
| concat!( | ||
| "Q1 [...proxyOverArray] 1\n", | ||
| "Q2 for..of proxyOverArray 1\n", | ||
| "Q3 Array.isArray(proxyOverArray) true\n", | ||
| "Q4 proxy[Symbol.iterator] typeof \"function\"\n", | ||
| "Q5 Array.from(proxyOverArray) 1\n", | ||
| "nested [1,2]\n", | ||
| "trapped indices [9,2]\n", | ||
| "custom iterator [7,8,9]\n", | ||
| "mapped [1,3]\n", | ||
| "mapped custom iterator [14,16,18]\n", | ||
| "arraylike [\"a\",\"b\"]\n", | ||
| "removed iterator [1,2]\n", | ||
| "record iterator [5,6]\n", | ||
| "headers outer \"1\"\n", | ||
| "headers pair \"1\"\n", | ||
| "plain array [3,4]\n", | ||
| "of preserves proxy true\n", | ||
| "concat indices [0,7,2]\n", | ||
| "concat holes [3,false,2]\n", | ||
| "call spread 2\n", | ||
| "set iterator [7,8]\n", | ||
| "all [1,2]\n", | ||
| ) | ||
| ); | ||
| } |
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,43 @@ | ||
| //! #10274: a dynamic HeadersInit in a literal RequestInit needs conversion. | ||
|
|
||
| mod support { | ||
| include!("support/proxy_value_probe.rs"); | ||
| } | ||
|
|
||
| const SOURCE: &str = r#" | ||
| const dump = (h: any) => { const out: string[] = []; h.forEach((v: string, k: string) => out.push(k + "=" + v)); return out.sort() } | ||
| const proxy = new Proxy({ "x-a": "1" }, {}) | ||
| console.log("direct", JSON.stringify(dump(new Headers(proxy as any)))) | ||
| console.log("request", JSON.stringify(dump(new Request("https://x.dev", { headers: proxy as any }).headers))) | ||
| function make(headers: any) { return new Request("https://x.dev", { headers }).headers; } | ||
| function init(headers: any): any { return { headers }; } | ||
| console.log("parameter", JSON.stringify(dump(make(proxy)))) | ||
| console.log("runtime init", JSON.stringify(dump(new Request("https://x.dev", init(proxy)).headers))) | ||
| const trapped = new Proxy({ "authorization": "secret", "x-hidden": "hidden" }, { | ||
| ownKeys() { return ["authorization"]; }, | ||
| get(t: any, k: any) { return k === "authorization" ? "Bearer token" : t[k]; } | ||
| }); | ||
| console.log("traps", JSON.stringify(dump(make(trapped)))) | ||
| console.log("record", JSON.stringify(dump(make({ "x-a": "1" })))) | ||
| console.log("pairs", JSON.stringify(dump(make([["x-a", "1"], ["x-a", "2"]])))) | ||
| console.log("handle", JSON.stringify(dump(make(new Headers({ "x-a": "1" }))))) | ||
| console.log("literal", JSON.stringify(dump(new Request("https://x.dev", { headers: { "x-a": "1" } }).headers))) | ||
| "#; | ||
|
|
||
| #[test] | ||
| fn request_converts_dynamic_headers_init() { | ||
| assert_eq!( | ||
| support::compile_and_run(SOURCE), | ||
| concat!( | ||
| "direct [\"x-a=1\"]\n", | ||
| "request [\"x-a=1\"]\n", | ||
| "parameter [\"x-a=1\"]\n", | ||
| "runtime init [\"x-a=1\"]\n", | ||
| "traps [\"authorization=Bearer token\"]\n", | ||
| "record [\"x-a=1\"]\n", | ||
| "pairs [\"x-a=1, 2\"]\n", | ||
| "handle [\"x-a=1\"]\n", | ||
| "literal [\"x-a=1\"]\n", | ||
| ) | ||
| ); | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Root the generic iterator across protocol calls.
The
Genericbranch stores the result ofjs_get_iteratorin the rawiterlocal.iterator_next_valueanditerator_closepass that value tojs_native_call_method, which can invoke JavaScript and trigger GC. RootiterwithRuntimeHandleScopeand reload it for each call.🤖 Prompt for AI Agents