Skip to content

Commit

Permalink
url: conform structuredClone url serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Mar 22, 2023
1 parent 1a18b44 commit 137d2de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
19 changes: 19 additions & 0 deletions lib/internal/structured_clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@ const {
codes: { ERR_MISSING_ARGS },
} = require('internal/errors');

const {
lazyDOMException,
} = require('internal/util');

const {
MessageChannel,
receiveMessageOnPort,
} = require('internal/worker/io');

const {
isURL,
isURLSearchParams,
} = require('internal/url');

let channel;
function structuredClone(value, options = undefined) {
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('value');
}

if (isURL(value)) {
throw new lazyDOMException(
'URL: no structured serialize/deserialize support',
'DataCloneError');
} else if (isURLSearchParams(value)) {
throw new lazyDOMException(
'URLSearchParams: no structured serialize/deserialize support',
'DataCloneError');
}

// TODO: Improve this with a more efficient solution that avoids
// instantiating a MessageChannel
channel ??= new MessageChannel();
Expand Down
1 change: 1 addition & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1279,4 +1279,5 @@ module.exports = {
urlToHttpOptions,
encodeStr,
isURL,
isURLSearchParams,
};
4 changes: 1 addition & 3 deletions test/wpt/status/url.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,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 137d2de

Please sign in to comment.