From 137d2dea6048d2f05c9384d5beea843b1a29d546 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Wed, 22 Mar 2023 10:03:26 -0400 Subject: [PATCH] url: conform structuredClone url serialization --- lib/internal/structured_clone.js | 19 +++++++++++++++++++ lib/internal/url.js | 1 + test/wpt/status/url.json | 4 +--- 3 files changed, 21 insertions(+), 3 deletions(-) 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" ] } },