Skip to content

Commit c5b0b89

Browse files
authored
lib: mark URL/URLSearchParams as uncloneable and untransferable
Mark URL/URLSearchParams as uncloneable and untransferable to reject them in `structuredClone` and `port.postMessage`. PR-URL: #47497 Refs: #47214 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 5da84a6 commit c5b0b89

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/internal/url.js

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const {
4747
SideEffectFreeRegExpPrototypeSymbolReplace,
4848
} = require('internal/util');
4949

50+
const {
51+
markTransferMode,
52+
} = require('internal/worker/js_transferable');
53+
5054
const {
5155
codes: {
5256
ERR_ARG_NOT_ITERABLE,
@@ -326,6 +330,8 @@ class URLSearchParams {
326330
// Default parameter is necessary to keep URLSearchParams.length === 0 in
327331
// accordance with Web IDL spec.
328332
constructor(init = undefined) {
333+
markTransferMode(this, false, false);
334+
329335
if (init == null) {
330336
// Do nothing
331337
} else if (typeof init === 'object' || typeof init === 'function') {
@@ -761,6 +767,8 @@ class URL {
761767
#searchParams;
762768

763769
constructor(input, base = undefined) {
770+
markTransferMode(this, false, false);
771+
764772
if (arguments.length === 0) {
765773
throw new ERR_MISSING_ARGS('url');
766774
}

test/wpt/status/url.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"fail": {
77
"note": "We are faking location with a URL object for the sake of the testharness and it has searchParams.",
88
"expected": [
9-
"searchParams on location object",
10-
"URL: no structured serialize/deserialize support",
11-
"URLSearchParams: no structured serialize/deserialize support"
9+
"searchParams on location object"
1210
]
1311
}
1412
},

0 commit comments

Comments
 (0)