From 2425f2aa6cb75de4693d1458144cb8b2376ade10 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Sat, 15 Jul 2023 22:04:13 +0800 Subject: [PATCH] lib: mark URL/URLSearchParams as uncloneable and untransferable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mark URL/URLSearchParams as uncloneable and untransferable to reject them in `structuredClone` and `port.postMessage`. PR-URL: https://github.com/nodejs/node/pull/47497 Refs: https://github.com/nodejs/node/pull/47214 Reviewed-By: Michaƫl Zasso Reviewed-By: Yagiz Nizipli Reviewed-By: Rafael Gonzaga Reviewed-By: Antoine du Hamel --- lib/internal/url.js | 8 ++++++++ test/wpt/status/url.json | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 302d3fa08753a5..8b1cbe457af7a2 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -47,6 +47,10 @@ const { SideEffectFreeRegExpPrototypeSymbolReplace, } = require('internal/util'); +const { + markTransferMode, +} = require('internal/worker/js_transferable'); + const { codes: { ERR_ARG_NOT_ITERABLE, @@ -326,6 +330,8 @@ class URLSearchParams { // Default parameter is necessary to keep URLSearchParams.length === 0 in // accordance with Web IDL spec. constructor(init = undefined) { + markTransferMode(this, false, false); + if (init == null) { // Do nothing } else if (typeof init === 'object' || typeof init === 'function') { @@ -761,6 +767,8 @@ class URL { #searchParams; constructor(input, base = undefined) { + markTransferMode(this, false, false); + if (arguments.length === 0) { throw new ERR_MISSING_ARGS('url'); } diff --git a/test/wpt/status/url.json b/test/wpt/status/url.json index 0b4beb54549495..43f22c5afe5de3 100644 --- a/test/wpt/status/url.json +++ b/test/wpt/status/url.json @@ -6,9 +6,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" ] } },