Skip to content

Commit fd30f50

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

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

doc/api/globals.md

+5
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,11 @@ added: v0.0.1
811811

812812
<!-- YAML
813813
added: v17.0.0
814+
changes:
815+
- version: REPLACEME
816+
pr-url: https://github.com/nodejs/node/pull/47214
817+
description: Throws a DOM exception when used with `URL` and
818+
`URLSearhParams` to conform with WHATWG specification.
814819
-->
815820

816821
<!-- type=global -->

doc/api/url.md

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ added:
111111
- v7.0.0
112112
- v6.13.0
113113
changes:
114+
- version: REPLACEME
115+
pr-url: https://github.com/nodejs/node/pull/47214
116+
description: The class is now not serializable/deserializable through
117+
`structuredClone` to conform to the WHATWG specification.
114118
- version: v10.0.0
115119
pr-url: https://github.com/nodejs/node/pull/18281
116120
description: The class is now available on the global object.
@@ -669,6 +673,10 @@ added:
669673
- v7.5.0
670674
- v6.13.0
671675
changes:
676+
- version: REPLACEME
677+
pr-url: https://github.com/nodejs/node/pull/47214
678+
description: The class is now not serializable/deserializable through
679+
`structuredClone` to conform to the WHATWG specification.
672680
- version: v10.0.0
673681
pr-url: https://github.com/nodejs/node/pull/18281
674682
description: The class is now available on the global object.

lib/internal/structured_clone.js

+19
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

+1
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

+1-3
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)