Skip to content

fix(core): align structuredClone, URLSearchParams and Headers with spec - #1865

Merged
richarddd merged 2 commits into
awslabs:mainfrom
arxhr007:fix/clone-url-headers
Nov 4, 2026
Merged

richarddd merged 2 commits into
awslabs:mainfrom
arxhr007:fix/clone-url-headers

Conversation

@arxhr007

@arxhr007 arxhr007 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Issue # (if available)

None — found via differential fuzzing of web API behavior against Node.js.

Description of changes

Four small spec-alignment fixes:

  • structuredClone(DataView) crashed. append_buffer assumed every ArrayBuffer view exposes slice(); DataView doesn't, so cloning any DataView threw TypeError: Error converting from js 'undefined' into type 'function'. The viewed ArrayBuffer is now cloned and the view rebuilt at the same byteOffset/byteLength, per the HTML spec.
  • structuredClone silently returned un-clonable values. Functions, symbols and promises were passed through instead of throwing; they now throw DataCloneError ("Value could not be cloned").
  • URLSearchParams treated # as a fragment delimiter. new URLSearchParams("2éC&Y#C6yR") dropped #C6yR because the input was parsed by joining it as a relative URL. The input is now parsed as a query string via set_query, so # stays a literal — matching the spec's query parsing.
  • Headers tuple names weren't coerced. new Headers([[1, 2]]) rejected a numeric name; names are now coerced to strings the same way values already were.

Checklist

  • Created unit tests in tests/unit and/or in Rust for my feature if needed
  • Ran make fix to format JS and apply Clippy auto fixes
  • Made sure my code didn't add any additional warnings: make check
  • Added relevant type info in types/ directory (no signature changes)
  • Updated documentation if needed (API.md/README.md/Other) (not needed)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- structuredClone(DataView) crashed calling slice() which DataView does
  not have; clone the viewed ArrayBuffer and rebuild the view at the
  same offset/length per the HTML spec.
- structuredClone silently returned functions, symbols and promises
  instead of throwing DataCloneError.
- new URLSearchParams("a#b") treated '#' as a fragment delimiter and
  dropped the tail; parse the input as a query string instead of a
  relative URL so '#' stays literal.
- new Headers([[1, 2]]) rejected a numeric name; coerce names to
  strings like values are.
Comment thread llrt_core/src/clone.rs Resolved

@richarddd richarddd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! Small comment

Review feedback: fetch the DataView constructor from base primordials
instead of looking it up on ctx.globals() per call.
@arxhr007

arxhr007 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Done — added constructor_data_view to BasePrimordials and clone.rs now uses it instead of the per-call globals lookup.

@richarddd
richarddd merged commit 74af683 into awslabs:main Nov 4, 2026
32 checks passed
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.

2 participants