Skip to content

Commit

Permalink
lib: mark URL/URLSearchParams as uncloneable and untransferable
Browse files Browse the repository at this point in the history
Mark URL/URLSearchParams as uncloneable and untransferable to reject
them in `structuredClone` and `port.postMessage`.
  • Loading branch information
legendecas committed Jul 12, 2023
1 parent 0e9138d commit 7920c5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const {
SideEffectFreeRegExpPrototypeSymbolReplace,
} = require('internal/util');

const {
markTransferMode,
} = require('internal/worker/js_transferable');

const {
codes: {
ERR_ARG_NOT_ITERABLE,
Expand Down Expand Up @@ -326,6 +330,8 @@ class URLSearchParams {
// Default parameter is necessary to keep URLSearchParams.length === 0 in
// accordance with Web IDL spec.
constructor(init = undefined) {
markTransferMode(this, false, false);

if (init == null) {
// Do nothing
} else if (typeof init === 'object' || typeof init === 'function') {
Expand Down Expand Up @@ -761,6 +767,8 @@ class URL {
#searchParams;

constructor(input, base = undefined) {
markTransferMode(this, false, false);

if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('url');
}
Expand Down
4 changes: 1 addition & 3 deletions test/wpt/status/url.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"fail": {
"note": "We are faking location with a URL object for the sake of the testharness and it has searchParams.",
"expected": [
"searchParams on location object",
"URL: no structured serialize/deserialize support",
"URLSearchParams: no structured serialize/deserialize support"
"searchParams on location object"
]
}
},
Expand Down

0 comments on commit 7920c5a

Please sign in to comment.