Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: conform structuredClone url serialization #47214

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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