Skip to content

Commit 137d2de

Browse files
committed
url: conform structuredClone url serialization
1 parent 1a18b44 commit 137d2de

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/internal/structured_clone.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,36 @@ const {
44
codes: { ERR_MISSING_ARGS },
55
} = require('internal/errors');
66

7+
const {
8+
lazyDOMException,
9+
} = require('internal/util');
10+
711
const {
812
MessageChannel,
913
receiveMessageOnPort,
1014
} = require('internal/worker/io');
1115

16+
const {
17+
isURL,
18+
isURLSearchParams,
19+
} = require('internal/url');
20+
1221
let channel;
1322
function structuredClone(value, options = undefined) {
1423
if (arguments.length === 0) {
1524
throw new ERR_MISSING_ARGS('value');
1625
}
1726

27+
if (isURL(value)) {
28+
throw new lazyDOMException(
29+
'URL: no structured serialize/deserialize support',
30+
'DataCloneError');
31+
} else if (isURLSearchParams(value)) {
32+
throw new lazyDOMException(
33+
'URLSearchParams: no structured serialize/deserialize support',
34+
'DataCloneError');
35+
}
36+
1837
// TODO: Improve this with a more efficient solution that avoids
1938
// instantiating a MessageChannel
2039
channel ??= new MessageChannel();

lib/internal/url.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,4 +1279,5 @@ module.exports = {
12791279
urlToHttpOptions,
12801280
encodeStr,
12811281
isURL,
1282+
isURLSearchParams,
12821283
};

test/wpt/status/url.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"fail": {
1212
"note": "We are faking location with a URL object for the sake of the testharness and it has searchParams.",
1313
"expected": [
14-
"searchParams on location object",
15-
"URL: no structured serialize/deserialize support",
16-
"URLSearchParams: no structured serialize/deserialize support"
14+
"searchParams on location object"
1715
]
1816
}
1917
},

0 commit comments

Comments
 (0)