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 b915e02
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,11 @@ added: v0.0.1

<!-- YAML
added: v17.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/47214
description: Throws a DOM exception when used with `URL` and
`URLSearchParams` to conform with WHATWG specification.
-->

<!-- type=global -->
Expand Down
8 changes: 8 additions & 0 deletions doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ added:
- v7.0.0
- v6.13.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/47214
description: The class is now not serializable/deserializable through
`structuredClone` to conform to the WHATWG specification.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18281
description: The class is now available on the global object.
Expand Down Expand Up @@ -669,6 +673,10 @@ added:
- v7.5.0
- v6.13.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/47214
description: The class is now not serializable/deserializable through
`structuredClone` to conform to the WHATWG specification.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18281
description: The class is now available on the global object.
Expand Down
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 b915e02

Please sign in to comment.