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: https://github.com/nodejs/node/pull/47497
Refs: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Chengzhong Wu 2023-07-15 22:04:13 +08:00 committed by GitHub
parent 5da84a6341
commit c5b0b894ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -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');
}

View File

@ -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"
]
}
},