diff --git a/doc/api/globals.md b/doc/api/globals.md index ec42fd53ab24eb..b6ba6593c9cc4d 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -811,6 +811,11 @@ added: v0.0.1 diff --git a/doc/api/url.md b/doc/api/url.md index ac2884e64f5533..39418189622e4a 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -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. @@ -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. diff --git a/lib/internal/structured_clone.js b/lib/internal/structured_clone.js index 0392232badf9fc..0a867df5c7e10a 100644 --- a/lib/internal/structured_clone.js +++ b/lib/internal/structured_clone.js @@ -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(); diff --git a/lib/internal/url.js b/lib/internal/url.js index fe4dab1224be39..6c1821020bd3cf 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1279,4 +1279,5 @@ module.exports = { urlToHttpOptions, encodeStr, isURL, + isURLSearchParams, }; diff --git a/test/wpt/status/url.json b/test/wpt/status/url.json index 257c1961b97604..f2df4f4a5e510c 100644 --- a/test/wpt/status/url.json +++ b/test/wpt/status/url.json @@ -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" ] } },