2016-05-31 18:52:19 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-22 17:04:46 +00:00
|
|
|
const {
|
2019-11-23 09:09:05 +00:00
|
|
|
Array,
|
2023-04-03 15:59:46 +00:00
|
|
|
ArrayIsArray,
|
2020-11-20 09:20:15 +00:00
|
|
|
ArrayPrototypeJoin,
|
|
|
|
ArrayPrototypeMap,
|
|
|
|
ArrayPrototypePush,
|
|
|
|
ArrayPrototypeReduce,
|
|
|
|
ArrayPrototypeSlice,
|
2023-03-03 21:34:56 +00:00
|
|
|
Boolean,
|
2020-07-05 00:47:39 +00:00
|
|
|
Int8Array,
|
2023-01-22 13:13:24 +00:00
|
|
|
IteratorPrototype,
|
2019-11-28 09:30:51 +00:00
|
|
|
Number,
|
2019-11-22 17:04:46 +00:00
|
|
|
ObjectDefineProperties,
|
2023-04-07 04:17:14 +00:00
|
|
|
ObjectSetPrototypeOf,
|
2019-11-22 17:04:46 +00:00
|
|
|
ReflectGetOwnPropertyDescriptor,
|
|
|
|
ReflectOwnKeys,
|
2023-04-07 03:32:26 +00:00
|
|
|
SafeMap,
|
2023-06-29 18:45:31 +00:00
|
|
|
SafeSet,
|
2023-01-22 13:13:24 +00:00
|
|
|
StringPrototypeCharAt,
|
2020-11-20 09:20:15 +00:00
|
|
|
StringPrototypeCharCodeAt,
|
2023-01-22 13:13:24 +00:00
|
|
|
StringPrototypeCodePointAt,
|
2020-11-20 09:20:15 +00:00
|
|
|
StringPrototypeIncludes,
|
2023-01-22 13:13:24 +00:00
|
|
|
StringPrototypeIndexOf,
|
2020-11-20 09:20:15 +00:00
|
|
|
StringPrototypeSlice,
|
|
|
|
StringPrototypeStartsWith,
|
2023-11-29 16:00:57 +00:00
|
|
|
StringPrototypeToWellFormed,
|
2019-11-30 15:55:29 +00:00
|
|
|
Symbol,
|
2019-12-08 21:35:19 +00:00
|
|
|
SymbolIterator,
|
2019-12-11 20:08:38 +00:00
|
|
|
SymbolToStringTag,
|
2021-02-16 13:31:29 +00:00
|
|
|
decodeURIComponent,
|
2019-11-22 17:04:46 +00:00
|
|
|
} = primordials;
|
2019-03-31 11:30:12 +00:00
|
|
|
|
2019-03-20 12:34:03 +00:00
|
|
|
const { inspect } = require('internal/util/inspect');
|
2017-03-15 04:01:04 +00:00
|
|
|
const {
|
2018-11-08 06:17:14 +00:00
|
|
|
encodeStr,
|
2017-03-15 04:01:04 +00:00
|
|
|
hexTable,
|
2023-02-26 10:34:02 +00:00
|
|
|
isHexTable,
|
2017-03-15 04:01:04 +00:00
|
|
|
} = require('internal/querystring');
|
2017-04-28 03:14:26 +00:00
|
|
|
|
2021-08-19 19:40:18 +00:00
|
|
|
const {
|
|
|
|
getConstructorOf,
|
|
|
|
removeColors,
|
2022-02-11 17:30:47 +00:00
|
|
|
kEnumerableProperty,
|
2024-04-24 15:47:48 +00:00
|
|
|
kEmptyObject,
|
2023-01-22 13:13:24 +00:00
|
|
|
SideEffectFreeRegExpPrototypeSymbolReplace,
|
2024-07-15 18:58:11 +00:00
|
|
|
isWindows,
|
2021-08-19 19:40:18 +00:00
|
|
|
} = require('internal/util');
|
|
|
|
|
2024-07-15 23:09:54 +00:00
|
|
|
const {
|
|
|
|
platform,
|
|
|
|
} = require('internal/process/per_thread');
|
|
|
|
|
2023-07-15 14:04:13 +00:00
|
|
|
const {
|
|
|
|
markTransferMode,
|
|
|
|
} = require('internal/worker/js_transferable');
|
|
|
|
|
2018-03-04 21:16:24 +00:00
|
|
|
const {
|
2021-08-07 02:26:37 +00:00
|
|
|
codes: {
|
|
|
|
ERR_ARG_NOT_ITERABLE,
|
|
|
|
ERR_INVALID_ARG_TYPE,
|
|
|
|
ERR_INVALID_ARG_VALUE,
|
|
|
|
ERR_INVALID_FILE_URL_HOST,
|
|
|
|
ERR_INVALID_FILE_URL_PATH,
|
|
|
|
ERR_INVALID_THIS,
|
|
|
|
ERR_INVALID_TUPLE,
|
|
|
|
ERR_INVALID_URL,
|
|
|
|
ERR_INVALID_URL_SCHEME,
|
|
|
|
ERR_MISSING_ARGS,
|
|
|
|
ERR_NO_CRYPTO,
|
|
|
|
},
|
|
|
|
} = require('internal/errors');
|
2018-03-12 15:59:31 +00:00
|
|
|
const {
|
|
|
|
CHAR_AMPERSAND,
|
2024-10-21 07:10:47 +00:00
|
|
|
CHAR_BACKWARD_SLASH,
|
2018-03-12 15:59:31 +00:00
|
|
|
CHAR_EQUAL,
|
2024-10-21 07:10:47 +00:00
|
|
|
CHAR_FORWARD_SLASH,
|
2018-03-12 15:59:31 +00:00
|
|
|
CHAR_LOWERCASE_A,
|
|
|
|
CHAR_LOWERCASE_Z,
|
2018-08-24 16:13:32 +00:00
|
|
|
CHAR_PERCENT,
|
2023-02-26 10:34:02 +00:00
|
|
|
CHAR_PLUS,
|
2018-03-12 15:59:31 +00:00
|
|
|
} = require('internal/constants');
|
2018-08-24 16:13:32 +00:00
|
|
|
const path = require('path');
|
2018-05-06 21:08:42 +00:00
|
|
|
|
2021-01-21 11:03:00 +00:00
|
|
|
const {
|
2022-01-24 16:09:16 +00:00
|
|
|
validateFunction,
|
2021-01-21 11:03:00 +00:00
|
|
|
} = require('internal/validators');
|
2020-12-23 11:22:00 +00:00
|
|
|
|
2021-05-19 18:50:13 +00:00
|
|
|
const querystring = require('querystring');
|
2017-04-28 03:14:26 +00:00
|
|
|
|
2023-03-31 13:03:06 +00:00
|
|
|
const bindingUrl = internalBinding('url');
|
2017-04-28 03:14:26 +00:00
|
|
|
|
2023-01-22 13:13:24 +00:00
|
|
|
const FORWARD_SLASH = /\//g;
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
const contextForInspect = Symbol('context');
|
2016-05-31 18:52:19 +00:00
|
|
|
|
2023-06-29 18:45:31 +00:00
|
|
|
// `unsafeProtocol`, `hostlessProtocol` and `slashedProtocol` is
|
|
|
|
// deliberately moved to `internal/url` rather than `url`.
|
|
|
|
// Workers does not bootstrap URL module. Therefore, `SafeSet`
|
|
|
|
// is not initialized on bootstrap. This case breaks the
|
|
|
|
// test-require-delete-array-iterator test.
|
|
|
|
|
|
|
|
// Protocols that can allow "unsafe" and "unwise" chars.
|
|
|
|
const unsafeProtocol = new SafeSet([
|
|
|
|
'javascript',
|
|
|
|
'javascript:',
|
|
|
|
]);
|
|
|
|
// Protocols that never have a hostname.
|
|
|
|
const hostlessProtocol = new SafeSet([
|
|
|
|
'javascript',
|
|
|
|
'javascript:',
|
|
|
|
]);
|
|
|
|
// Protocols that always contain a // bit.
|
|
|
|
const slashedProtocol = new SafeSet([
|
|
|
|
'http',
|
|
|
|
'http:',
|
|
|
|
'https',
|
|
|
|
'https:',
|
|
|
|
'ftp',
|
|
|
|
'ftp:',
|
|
|
|
'gopher',
|
|
|
|
'gopher:',
|
|
|
|
'file',
|
|
|
|
'file:',
|
|
|
|
'ws',
|
|
|
|
'ws:',
|
|
|
|
'wss',
|
|
|
|
'wss:',
|
|
|
|
]);
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
const updateActions = {
|
|
|
|
kProtocol: 0,
|
|
|
|
kHost: 1,
|
|
|
|
kHostname: 2,
|
|
|
|
kPort: 3,
|
|
|
|
kUsername: 4,
|
|
|
|
kPassword: 5,
|
|
|
|
kPathname: 6,
|
|
|
|
kSearch: 7,
|
|
|
|
kHash: 8,
|
|
|
|
kHref: 9,
|
|
|
|
};
|
2021-08-07 02:26:37 +00:00
|
|
|
let blob;
|
|
|
|
let cryptoRandom;
|
|
|
|
|
|
|
|
function lazyBlob() {
|
|
|
|
blob ??= require('internal/blob');
|
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
function lazyCryptoRandom() {
|
|
|
|
try {
|
|
|
|
cryptoRandom ??= require('internal/crypto/random');
|
|
|
|
} catch {
|
|
|
|
// If Node.js built without crypto support, we'll fall
|
|
|
|
// through here and handle it later.
|
|
|
|
}
|
|
|
|
return cryptoRandom;
|
|
|
|
}
|
|
|
|
|
2017-03-22 18:39:13 +00:00
|
|
|
// This class provides the internal state of a URL object. An instance of this
|
|
|
|
// class is stored in every URL object and is accessed internally by setters
|
|
|
|
// and getters. It roughly corresponds to the concept of a URL record in the
|
|
|
|
// URL Standard, with a few differences. It is also the object transported to
|
|
|
|
// the C++ binding.
|
|
|
|
// Refs: https://url.spec.whatwg.org/#concept-url
|
|
|
|
class URLContext {
|
2023-03-31 13:03:06 +00:00
|
|
|
// This is the maximum value uint32_t can get.
|
|
|
|
// Ada uses uint32_t(-1) for declaring omitted values.
|
|
|
|
static #omitted = 4294967295;
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
href = '';
|
2023-03-31 13:03:06 +00:00
|
|
|
protocol_end = 0;
|
|
|
|
username_end = 0;
|
|
|
|
host_start = 0;
|
|
|
|
host_end = 0;
|
|
|
|
pathname_start = 0;
|
|
|
|
search_start = 0;
|
|
|
|
hash_start = 0;
|
|
|
|
port = 0;
|
|
|
|
/**
|
|
|
|
* Refers to `ada::scheme::type`
|
|
|
|
*
|
|
|
|
* enum type : uint8_t {
|
|
|
|
* HTTP = 0,
|
|
|
|
* NOT_SPECIAL = 1,
|
|
|
|
* HTTPS = 2,
|
|
|
|
* WS = 3,
|
|
|
|
* FTP = 4,
|
|
|
|
* WSS = 5,
|
|
|
|
* FILE = 6
|
|
|
|
* };
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
scheme_type = 1;
|
|
|
|
|
|
|
|
get hasPort() {
|
|
|
|
return this.port !== URLContext.#omitted;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasSearch() {
|
|
|
|
return this.search_start !== URLContext.#omitted;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasHash() {
|
|
|
|
return this.hash_start !== URLContext.#omitted;
|
|
|
|
}
|
2017-03-22 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 14:36:36 +00:00
|
|
|
let setURLSearchParamsModified;
|
2023-04-07 04:17:14 +00:00
|
|
|
let setURLSearchParamsContext;
|
|
|
|
let getURLSearchParamsList;
|
|
|
|
let setURLSearchParams;
|
|
|
|
|
|
|
|
class URLSearchParamsIterator {
|
|
|
|
#target;
|
|
|
|
#kind;
|
|
|
|
#index;
|
|
|
|
|
|
|
|
// https://heycam.github.io/webidl/#dfn-default-iterator-object
|
|
|
|
constructor(target, kind) {
|
|
|
|
this.#target = target;
|
|
|
|
this.#kind = kind;
|
|
|
|
this.#index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
next() {
|
|
|
|
if (typeof this !== 'object' || this === null || !(#target in this))
|
|
|
|
throw new ERR_INVALID_THIS('URLSearchParamsIterator');
|
|
|
|
|
|
|
|
const index = this.#index;
|
|
|
|
const values = getURLSearchParamsList(this.#target);
|
|
|
|
const len = values.length;
|
|
|
|
if (index >= len) {
|
|
|
|
return {
|
|
|
|
value: undefined,
|
|
|
|
done: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const name = values[index];
|
|
|
|
const value = values[index + 1];
|
|
|
|
this.#index = index + 2;
|
|
|
|
|
|
|
|
let result;
|
|
|
|
if (this.#kind === 'key') {
|
|
|
|
result = name;
|
|
|
|
} else if (this.#kind === 'value') {
|
|
|
|
result = value;
|
|
|
|
} else {
|
|
|
|
result = [name, value];
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
value: result,
|
|
|
|
done: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[inspect.custom](recurseTimes, ctx) {
|
|
|
|
if (!this || typeof this !== 'object' || !(#target in this))
|
|
|
|
throw new ERR_INVALID_THIS('URLSearchParamsIterator');
|
|
|
|
|
|
|
|
if (typeof recurseTimes === 'number' && recurseTimes < 0)
|
|
|
|
return ctx.stylize('[Object]', 'special');
|
|
|
|
|
|
|
|
const innerOpts = { ...ctx };
|
|
|
|
if (recurseTimes !== null) {
|
|
|
|
innerOpts.depth = recurseTimes - 1;
|
|
|
|
}
|
|
|
|
const index = this.#index;
|
|
|
|
const values = getURLSearchParamsList(this.#target);
|
|
|
|
const output = ArrayPrototypeReduce(
|
|
|
|
ArrayPrototypeSlice(values, index),
|
|
|
|
(prev, cur, i) => {
|
|
|
|
const key = i % 2 === 0;
|
|
|
|
if (this.#kind === 'key' && key) {
|
|
|
|
ArrayPrototypePush(prev, cur);
|
|
|
|
} else if (this.#kind === 'value' && !key) {
|
|
|
|
ArrayPrototypePush(prev, cur);
|
|
|
|
} else if (this.#kind === 'key+value' && !key) {
|
|
|
|
ArrayPrototypePush(prev, [values[index + i - 1], cur]);
|
|
|
|
}
|
|
|
|
return prev;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
const breakLn = StringPrototypeIncludes(inspect(output, innerOpts), '\n');
|
|
|
|
const outputStrs = ArrayPrototypeMap(output, (p) => inspect(p, innerOpts));
|
|
|
|
let outputStr;
|
|
|
|
if (breakLn) {
|
|
|
|
outputStr = `\n ${ArrayPrototypeJoin(outputStrs, ',\n ')}`;
|
|
|
|
} else {
|
|
|
|
outputStr = ` ${ArrayPrototypeJoin(outputStrs, ', ')}`;
|
|
|
|
}
|
|
|
|
return `${this[SymbolToStringTag]} {${outputStr} }`;
|
|
|
|
}
|
2021-08-04 09:34:51 +00:00
|
|
|
}
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
// https://heycam.github.io/webidl/#dfn-iterator-prototype-object
|
|
|
|
delete URLSearchParamsIterator.prototype.constructor;
|
|
|
|
ObjectSetPrototypeOf(URLSearchParamsIterator.prototype, IteratorPrototype);
|
|
|
|
|
|
|
|
ObjectDefineProperties(URLSearchParamsIterator.prototype, {
|
|
|
|
[SymbolToStringTag]: { __proto__: null, configurable: true, value: 'URLSearchParams Iterator' },
|
|
|
|
next: kEnumerableProperty,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-07-01 18:51:22 +00:00
|
|
|
class URLSearchParams {
|
2023-04-07 04:17:14 +00:00
|
|
|
#searchParams = [];
|
2023-04-03 15:59:46 +00:00
|
|
|
|
|
|
|
// "associated url object"
|
2023-04-07 04:17:14 +00:00
|
|
|
#context;
|
|
|
|
|
|
|
|
static {
|
|
|
|
setURLSearchParamsContext = (obj, ctx) => {
|
|
|
|
obj.#context = ctx;
|
|
|
|
};
|
|
|
|
getURLSearchParamsList = (obj) => obj.#searchParams;
|
|
|
|
setURLSearchParams = (obj, query) => {
|
|
|
|
if (query === undefined) {
|
|
|
|
obj.#searchParams = [];
|
|
|
|
} else {
|
|
|
|
obj.#searchParams = parseParams(query);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-04-03 15:59:46 +00:00
|
|
|
|
2017-07-01 18:51:22 +00:00
|
|
|
// URL Standard says the default value is '', but as undefined and '' have
|
|
|
|
// the same result, undefined is used to prevent unnecessary parsing.
|
|
|
|
// Default parameter is necessary to keep URLSearchParams.length === 0 in
|
|
|
|
// accordance with Web IDL spec.
|
|
|
|
constructor(init = undefined) {
|
2023-07-15 14:04:13 +00:00
|
|
|
markTransferMode(this, false, false);
|
|
|
|
|
2023-04-03 15:59:46 +00:00
|
|
|
if (init == null) {
|
|
|
|
// Do nothing
|
2018-02-10 16:38:45 +00:00
|
|
|
} else if (typeof init === 'object' || typeof init === 'function') {
|
2019-12-08 21:35:19 +00:00
|
|
|
const method = init[SymbolIterator];
|
2023-04-07 04:17:14 +00:00
|
|
|
if (method === this[SymbolIterator] && #searchParams in init) {
|
2017-07-01 18:51:22 +00:00
|
|
|
// While the spec does not have this branch, we can use it as a
|
|
|
|
// shortcut to avoid having to go through the costly generic iterator.
|
2023-04-07 04:17:14 +00:00
|
|
|
const childParams = init.#searchParams;
|
|
|
|
this.#searchParams = childParams.slice();
|
2023-04-03 15:59:46 +00:00
|
|
|
} else if (method != null) {
|
|
|
|
// Sequence<sequence<USVString>>
|
2017-07-01 18:51:22 +00:00
|
|
|
if (typeof method !== 'function') {
|
2018-03-04 21:16:24 +00:00
|
|
|
throw new ERR_ARG_NOT_ITERABLE('Query pairs');
|
2017-07-01 18:51:22 +00:00
|
|
|
}
|
|
|
|
|
2024-07-14 15:18:19 +00:00
|
|
|
// The following implementation differs from the URL specification:
|
2023-04-03 15:59:46 +00:00
|
|
|
// Sequences must first be converted from ECMAScript objects before
|
|
|
|
// and operations are done on them, and the operation of converting
|
|
|
|
// the sequences would first exhaust the iterators. If the iterator
|
|
|
|
// returns something invalid in the middle, whether it would be called
|
|
|
|
// after that would be an observable change to the users.
|
|
|
|
// Exhausting the iterator and later converting them to USVString comes
|
|
|
|
// with a significant cost (~40-80%). In order optimize URLSearchParams
|
|
|
|
// creation duration, Node.js merges the iteration and converting
|
|
|
|
// iterations into a single iteration.
|
2017-07-01 18:51:22 +00:00
|
|
|
for (const pair of init) {
|
2023-04-03 15:59:46 +00:00
|
|
|
if (pair == null) {
|
2018-03-04 21:16:24 +00:00
|
|
|
throw new ERR_INVALID_TUPLE('Each query pair', '[name, value]');
|
2023-04-03 15:59:46 +00:00
|
|
|
} else if (ArrayIsArray(pair)) {
|
|
|
|
// If innerSequence's size is not 2, then throw a TypeError.
|
|
|
|
if (pair.length !== 2) {
|
|
|
|
throw new ERR_INVALID_TUPLE('Each query pair', '[name, value]');
|
|
|
|
}
|
2024-07-14 15:18:19 +00:00
|
|
|
// Append (innerSequence[0], innerSequence[1]) to query's list.
|
2023-11-29 16:00:57 +00:00
|
|
|
ArrayPrototypePush(
|
|
|
|
this.#searchParams,
|
|
|
|
StringPrototypeToWellFormed(`${pair[0]}`),
|
|
|
|
StringPrototypeToWellFormed(`${pair[1]}`),
|
|
|
|
);
|
2023-04-03 15:59:46 +00:00
|
|
|
} else {
|
|
|
|
if (((typeof pair !== 'object' && typeof pair !== 'function') ||
|
|
|
|
typeof pair[SymbolIterator] !== 'function')) {
|
|
|
|
throw new ERR_INVALID_TUPLE('Each query pair', '[name, value]');
|
|
|
|
}
|
2017-07-01 18:51:22 +00:00
|
|
|
|
2023-04-03 15:59:46 +00:00
|
|
|
let length = 0;
|
|
|
|
|
|
|
|
for (const element of pair) {
|
|
|
|
length++;
|
2023-11-29 16:00:57 +00:00
|
|
|
ArrayPrototypePush(this.#searchParams, StringPrototypeToWellFormed(`${element}`));
|
2023-04-03 15:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If innerSequence's size is not 2, then throw a TypeError.
|
|
|
|
if (length !== 2) {
|
|
|
|
throw new ERR_INVALID_TUPLE('Each query pair', '[name, value]');
|
|
|
|
}
|
2017-07-01 18:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-03-22 02:44:26 +00:00
|
|
|
// Record<USVString, USVString>
|
2017-07-01 18:51:22 +00:00
|
|
|
// Need to use reflection APIs for full spec compliance.
|
2023-04-07 03:32:26 +00:00
|
|
|
const visited = new SafeMap();
|
2019-11-22 17:04:46 +00:00
|
|
|
const keys = ReflectOwnKeys(init);
|
2019-11-12 16:20:02 +00:00
|
|
|
for (let i = 0; i < keys.length; i++) {
|
2017-07-01 18:51:22 +00:00
|
|
|
const key = keys[i];
|
2019-11-22 17:04:46 +00:00
|
|
|
const desc = ReflectGetOwnPropertyDescriptor(init, key);
|
2017-07-01 18:51:22 +00:00
|
|
|
if (desc !== undefined && desc.enumerable) {
|
2023-11-29 16:00:57 +00:00
|
|
|
const typedKey = StringPrototypeToWellFormed(key);
|
|
|
|
const typedValue = StringPrototypeToWellFormed(`${init[key]}`);
|
2021-08-30 18:07:39 +00:00
|
|
|
|
2023-04-07 03:32:26 +00:00
|
|
|
// Two different keys may become the same USVString after normalization.
|
|
|
|
// In that case, we retain the later one. Refer to WPT.
|
|
|
|
const keyIdx = visited.get(typedKey);
|
|
|
|
if (keyIdx !== undefined) {
|
2023-04-07 04:17:14 +00:00
|
|
|
this.#searchParams[keyIdx] = typedValue;
|
2021-08-30 18:07:39 +00:00
|
|
|
} else {
|
2023-04-07 04:17:14 +00:00
|
|
|
visited.set(typedKey, ArrayPrototypePush(this.#searchParams,
|
2023-04-07 03:32:26 +00:00
|
|
|
typedKey,
|
|
|
|
typedValue) - 1);
|
2021-08-30 18:07:39 +00:00
|
|
|
}
|
2017-07-01 18:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2023-04-03 15:59:46 +00:00
|
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
|
2023-11-29 16:00:57 +00:00
|
|
|
init = StringPrototypeToWellFormed(`${init}`);
|
2023-04-07 04:17:14 +00:00
|
|
|
this.#searchParams = init ? parseParams(init) : [];
|
2017-07-01 18:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-20 12:34:03 +00:00
|
|
|
[inspect.custom](recurseTimes, ctx) {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2018-03-04 21:16:24 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2017-07-01 18:51:22 +00:00
|
|
|
|
|
|
|
if (typeof recurseTimes === 'number' && recurseTimes < 0)
|
|
|
|
return ctx.stylize('[Object]', 'special');
|
|
|
|
|
2019-03-26 04:21:27 +00:00
|
|
|
const separator = ', ';
|
|
|
|
const innerOpts = { ...ctx };
|
2017-07-01 18:51:22 +00:00
|
|
|
if (recurseTimes !== null) {
|
|
|
|
innerOpts.depth = recurseTimes - 1;
|
|
|
|
}
|
2019-03-26 04:21:27 +00:00
|
|
|
const innerInspect = (v) => inspect(v, innerOpts);
|
2017-07-01 18:51:22 +00:00
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
const list = this.#searchParams;
|
2019-03-26 04:21:27 +00:00
|
|
|
const output = [];
|
2019-11-12 16:20:02 +00:00
|
|
|
for (let i = 0; i < list.length; i += 2)
|
2020-11-20 09:20:15 +00:00
|
|
|
ArrayPrototypePush(
|
|
|
|
output,
|
|
|
|
`${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`);
|
2017-07-01 18:51:22 +00:00
|
|
|
|
2020-11-20 09:20:15 +00:00
|
|
|
const length = ArrayPrototypeReduce(
|
|
|
|
output,
|
2017-12-11 08:32:59 +00:00
|
|
|
(prev, cur) => prev + removeColors(cur).length + separator.length,
|
2023-02-14 17:45:16 +00:00
|
|
|
-separator.length,
|
2017-07-01 18:51:22 +00:00
|
|
|
);
|
|
|
|
if (length > ctx.breakLength) {
|
2020-11-20 09:20:15 +00:00
|
|
|
return `${this.constructor.name} {\n` +
|
|
|
|
` ${ArrayPrototypeJoin(output, ',\n ')} }`;
|
2017-07-01 18:51:22 +00:00
|
|
|
} else if (output.length) {
|
2020-11-20 09:20:15 +00:00
|
|
|
return `${this.constructor.name} { ` +
|
|
|
|
`${ArrayPrototypeJoin(output, separator)} }`;
|
2017-07-01 18:51:22 +00:00
|
|
|
}
|
2020-04-08 16:58:03 +00:00
|
|
|
return `${this.constructor.name} {}`;
|
2017-07-01 18:51:22 +00:00
|
|
|
}
|
|
|
|
|
2023-01-22 20:14:11 +00:00
|
|
|
get size() {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2023-01-22 20:14:11 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2023-04-07 04:17:14 +00:00
|
|
|
return this.#searchParams.length / 2;
|
2023-01-22 20:14:11 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
append(name, value) {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2021-08-04 09:34:51 +00:00
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
if (arguments.length < 2) {
|
|
|
|
throw new ERR_MISSING_ARGS('name', 'value');
|
|
|
|
}
|
|
|
|
|
2023-11-29 16:00:57 +00:00
|
|
|
name = StringPrototypeToWellFormed(`${name}`);
|
|
|
|
value = StringPrototypeToWellFormed(`${value}`);
|
2023-04-07 04:17:14 +00:00
|
|
|
ArrayPrototypePush(this.#searchParams, name, value);
|
2024-01-24 14:36:36 +00:00
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
if (this.#context) {
|
2024-01-24 14:36:36 +00:00
|
|
|
setURLSearchParamsModified(this.#context);
|
2023-02-24 22:35:05 +00:00
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
2023-05-14 14:35:19 +00:00
|
|
|
delete(name, value = undefined) {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2021-08-04 09:34:51 +00:00
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
if (arguments.length < 1) {
|
|
|
|
throw new ERR_MISSING_ARGS('name');
|
|
|
|
}
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
const list = this.#searchParams;
|
2023-11-29 16:00:57 +00:00
|
|
|
name = StringPrototypeToWellFormed(`${name}`);
|
2023-05-14 14:35:19 +00:00
|
|
|
|
|
|
|
if (value !== undefined) {
|
2023-11-29 16:00:57 +00:00
|
|
|
value = StringPrototypeToWellFormed(`${value}`);
|
2023-05-14 14:35:19 +00:00
|
|
|
for (let i = 0; i < list.length;) {
|
|
|
|
if (list[i] === name && list[i + 1] === value) {
|
|
|
|
list.splice(i, 2);
|
|
|
|
} else {
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (let i = 0; i < list.length;) {
|
|
|
|
if (list[i] === name) {
|
|
|
|
list.splice(i, 2);
|
|
|
|
} else {
|
|
|
|
i += 2;
|
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
2024-01-24 14:36:36 +00:00
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
if (this.#context) {
|
2024-01-24 14:36:36 +00:00
|
|
|
setURLSearchParamsModified(this.#context);
|
2023-02-24 22:35:05 +00:00
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
get(name) {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2021-08-04 09:34:51 +00:00
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
if (arguments.length < 1) {
|
|
|
|
throw new ERR_MISSING_ARGS('name');
|
|
|
|
}
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
const list = this.#searchParams;
|
2023-11-29 16:00:57 +00:00
|
|
|
name = StringPrototypeToWellFormed(`${name}`);
|
2021-01-06 08:20:00 +00:00
|
|
|
for (let i = 0; i < list.length; i += 2) {
|
|
|
|
if (list[i] === name) {
|
|
|
|
return list[i + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
getAll(name) {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2021-08-04 09:34:51 +00:00
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
if (arguments.length < 1) {
|
|
|
|
throw new ERR_MISSING_ARGS('name');
|
|
|
|
}
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
const list = this.#searchParams;
|
2021-01-06 08:20:00 +00:00
|
|
|
const values = [];
|
2023-11-29 16:00:57 +00:00
|
|
|
name = StringPrototypeToWellFormed(`${name}`);
|
2021-01-06 08:20:00 +00:00
|
|
|
for (let i = 0; i < list.length; i += 2) {
|
|
|
|
if (list[i] === name) {
|
|
|
|
values.push(list[i + 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return values;
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
2023-05-14 14:35:19 +00:00
|
|
|
has(name, value = undefined) {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2021-08-04 09:34:51 +00:00
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
if (arguments.length < 1) {
|
|
|
|
throw new ERR_MISSING_ARGS('name');
|
|
|
|
}
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
const list = this.#searchParams;
|
2023-11-29 16:00:57 +00:00
|
|
|
name = StringPrototypeToWellFormed(`${name}`);
|
2023-05-14 14:35:19 +00:00
|
|
|
|
|
|
|
if (value !== undefined) {
|
2023-11-29 16:00:57 +00:00
|
|
|
value = StringPrototypeToWellFormed(`${value}`);
|
2023-05-14 14:35:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
for (let i = 0; i < list.length; i += 2) {
|
|
|
|
if (list[i] === name) {
|
2023-05-14 14:35:19 +00:00
|
|
|
if (value === undefined || list[i + 1] === value) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-14 14:35:19 +00:00
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
return false;
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
set(name, value) {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2021-08-04 09:34:51 +00:00
|
|
|
|
2021-01-06 08:20:00 +00:00
|
|
|
if (arguments.length < 2) {
|
|
|
|
throw new ERR_MISSING_ARGS('name', 'value');
|
|
|
|
}
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
const list = this.#searchParams;
|
2023-11-29 16:00:57 +00:00
|
|
|
name = StringPrototypeToWellFormed(`${name}`);
|
|
|
|
value = StringPrototypeToWellFormed(`${value}`);
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
// If there are any name-value pairs whose name is `name`, in `list`, set
|
|
|
|
// the value of the first such name-value pair to `value` and remove the
|
|
|
|
// others.
|
|
|
|
let found = false;
|
|
|
|
for (let i = 0; i < list.length;) {
|
|
|
|
const cur = list[i];
|
|
|
|
if (cur === name) {
|
|
|
|
if (!found) {
|
|
|
|
list[i + 1] = value;
|
|
|
|
found = true;
|
|
|
|
i += 2;
|
|
|
|
} else {
|
|
|
|
list.splice(i, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, append a new name-value pair whose name is `name` and value
|
|
|
|
// is `value`, to `list`.
|
|
|
|
if (!found) {
|
|
|
|
ArrayPrototypePush(list, name, value);
|
|
|
|
}
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
if (this.#context) {
|
2024-01-24 14:36:36 +00:00
|
|
|
setURLSearchParamsModified(this.#context);
|
2023-02-24 22:35:05 +00:00
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
sort() {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
|
|
|
|
|
|
|
const a = this.#searchParams;
|
2021-01-06 08:20:00 +00:00
|
|
|
const len = a.length;
|
|
|
|
|
|
|
|
if (len <= 2) {
|
|
|
|
// Nothing needs to be done.
|
|
|
|
} else if (len < 100) {
|
|
|
|
// 100 is found through testing.
|
|
|
|
// Simple stable in-place insertion sort
|
|
|
|
// Derived from v8/src/js/array.js
|
|
|
|
for (let i = 2; i < len; i += 2) {
|
|
|
|
const curKey = a[i];
|
|
|
|
const curVal = a[i + 1];
|
|
|
|
let j;
|
|
|
|
for (j = i - 2; j >= 0; j -= 2) {
|
|
|
|
if (a[j] > curKey) {
|
|
|
|
a[j + 2] = a[j];
|
|
|
|
a[j + 3] = a[j + 1];
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a[j + 2] = curKey;
|
|
|
|
a[j + 3] = curVal;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Bottom-up iterative stable merge sort
|
|
|
|
const lBuffer = new Array(len);
|
|
|
|
const rBuffer = new Array(len);
|
|
|
|
for (let step = 2; step < len; step *= 2) {
|
|
|
|
for (let start = 0; start < len - 2; start += 2 * step) {
|
|
|
|
const mid = start + step;
|
|
|
|
let end = mid + step;
|
|
|
|
end = end < len ? end : len;
|
|
|
|
if (mid > end)
|
|
|
|
continue;
|
|
|
|
merge(a, start, mid, end, lBuffer, rBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
if (this.#context) {
|
2024-01-24 14:36:36 +00:00
|
|
|
setURLSearchParamsModified(this.#context);
|
2023-02-24 22:35:05 +00:00
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-iterators
|
|
|
|
// Define entries here rather than [Symbol.iterator] as the function name
|
|
|
|
// must be set to `entries`.
|
|
|
|
entries() {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
return new URLSearchParamsIterator(this, 'key+value');
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
forEach(callback, thisArg = undefined) {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
2021-08-04 09:34:51 +00:00
|
|
|
|
2022-01-24 16:09:16 +00:00
|
|
|
validateFunction(callback, 'callback');
|
2021-01-06 08:20:00 +00:00
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
let list = this.#searchParams;
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
while (i < list.length) {
|
|
|
|
const key = list[i];
|
|
|
|
const value = list[i + 1];
|
|
|
|
callback.call(thisArg, value, key, this);
|
|
|
|
// In case the URL object's `search` is updated
|
2023-04-07 04:17:14 +00:00
|
|
|
list = this.#searchParams;
|
2021-01-06 08:20:00 +00:00
|
|
|
i += 2;
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-iterable
|
|
|
|
keys() {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
return new URLSearchParamsIterator(this, 'key');
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
values() {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
return new URLSearchParamsIterator(this, 'value');
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-stringifier
|
|
|
|
// https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior
|
|
|
|
toString() {
|
2023-04-07 04:17:14 +00:00
|
|
|
if (typeof this !== 'object' || this === null || !(#searchParams in this))
|
2021-01-06 08:20:00 +00:00
|
|
|
throw new ERR_INVALID_THIS('URLSearchParams');
|
|
|
|
|
2023-04-07 04:17:14 +00:00
|
|
|
return serializeParams(this.#searchParams);
|
2021-01-06 08:20:00 +00:00
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2021-01-06 08:20:00 +00:00
|
|
|
|
2021-01-05 12:20:00 +00:00
|
|
|
ObjectDefineProperties(URLSearchParams.prototype, {
|
2022-02-11 17:30:47 +00:00
|
|
|
append: kEnumerableProperty,
|
|
|
|
delete: kEnumerableProperty,
|
|
|
|
get: kEnumerableProperty,
|
|
|
|
getAll: kEnumerableProperty,
|
|
|
|
has: kEnumerableProperty,
|
|
|
|
set: kEnumerableProperty,
|
2023-01-22 20:14:11 +00:00
|
|
|
size: kEnumerableProperty,
|
2022-02-11 17:30:47 +00:00
|
|
|
sort: kEnumerableProperty,
|
|
|
|
entries: kEnumerableProperty,
|
|
|
|
forEach: kEnumerableProperty,
|
|
|
|
keys: kEnumerableProperty,
|
|
|
|
values: kEnumerableProperty,
|
|
|
|
toString: kEnumerableProperty,
|
2022-06-03 08:23:58 +00:00
|
|
|
[SymbolToStringTag]: { __proto__: null, configurable: true, value: 'URLSearchParams' },
|
2021-01-05 12:20:00 +00:00
|
|
|
|
|
|
|
// https://heycam.github.io/webidl/#es-iterable-entries
|
|
|
|
[SymbolIterator]: {
|
2022-06-03 08:23:58 +00:00
|
|
|
__proto__: null,
|
2021-01-05 12:20:00 +00:00
|
|
|
configurable: true,
|
|
|
|
writable: true,
|
|
|
|
value: URLSearchParams.prototype.entries,
|
|
|
|
},
|
2021-01-06 08:20:00 +00:00
|
|
|
});
|
|
|
|
|
2023-03-03 21:34:56 +00:00
|
|
|
/**
|
|
|
|
* Checks if a value has the shape of a WHATWG URL object.
|
|
|
|
*
|
|
|
|
* Using a symbol or instanceof would not be able to recognize URL objects
|
|
|
|
* coming from other implementations (e.g. in Electron), so instead we are
|
|
|
|
* checking some well known properties for a lack of a better test.
|
|
|
|
*
|
2023-03-31 13:03:06 +00:00
|
|
|
* We use `href` and `protocol` as they are the only properties that are
|
|
|
|
* easy to retrieve and calculate due to the lazy nature of the getters.
|
2023-05-07 19:41:21 +00:00
|
|
|
*
|
2023-07-26 03:59:25 +00:00
|
|
|
* We check for `auth` and `path` attribute to distinguish legacy url instance with
|
2023-05-07 19:41:21 +00:00
|
|
|
* WHATWG URL instance.
|
2023-03-03 21:34:56 +00:00
|
|
|
* @param {*} self
|
|
|
|
* @returns {self is URL}
|
|
|
|
*/
|
2023-02-27 14:31:18 +00:00
|
|
|
function isURL(self) {
|
2023-07-26 03:59:25 +00:00
|
|
|
return Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined);
|
2021-08-12 22:45:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-13 12:57:12 +00:00
|
|
|
/**
|
|
|
|
* A unique symbol used as a private identifier to safely invoke the URL constructor
|
|
|
|
* with a special parsing behavior. When passed as the third argument to the URL
|
|
|
|
* constructor, it signals that the constructor should not throw an exception
|
|
|
|
* for invalid URL inputs.
|
|
|
|
*/
|
|
|
|
const kParseURLSymbol = Symbol('kParseURL');
|
2024-10-31 21:11:27 +00:00
|
|
|
const kCreateURLFromPosixPathSymbol = Symbol('kCreateURLFromPosixPath');
|
|
|
|
const kCreateURLFromWindowsPathSymbol = Symbol('kCreateURLFromWindowsPath');
|
2024-04-13 12:57:12 +00:00
|
|
|
|
2016-05-31 18:52:19 +00:00
|
|
|
class URL {
|
2023-03-03 21:34:56 +00:00
|
|
|
#context = new URLContext();
|
|
|
|
#searchParams;
|
2024-01-24 14:36:36 +00:00
|
|
|
#searchParamsModified;
|
|
|
|
|
|
|
|
static {
|
|
|
|
setURLSearchParamsModified = (obj) => {
|
|
|
|
// When URLSearchParams changes, we lazily update URL on the next read/write for performance.
|
|
|
|
obj.#searchParamsModified = true;
|
|
|
|
|
|
|
|
// If URL has an existing search, remove it without cascading back to URLSearchParams.
|
|
|
|
// Do this to avoid any internal confusion about whether URLSearchParams or URL is up-to-date.
|
|
|
|
if (obj.#context.hasSearch) {
|
|
|
|
obj.#updateContext(bindingUrl.update(obj.#context.href, updateActions.kSearch, ''));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-03-03 21:34:56 +00:00
|
|
|
|
2024-04-13 12:57:12 +00:00
|
|
|
constructor(input, base = undefined, parseSymbol = undefined) {
|
2023-07-15 14:04:13 +00:00
|
|
|
markTransferMode(this, false, false);
|
|
|
|
|
2023-04-11 15:35:46 +00:00
|
|
|
if (arguments.length === 0) {
|
|
|
|
throw new ERR_MISSING_ARGS('url');
|
|
|
|
}
|
|
|
|
|
2023-11-29 16:00:57 +00:00
|
|
|
// StringPrototypeToWellFormed is not needed.
|
2017-03-08 03:31:29 +00:00
|
|
|
input = `${input}`;
|
2016-05-31 18:52:19 +00:00
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
if (base !== undefined) {
|
|
|
|
base = `${base}`;
|
|
|
|
}
|
2016-05-31 18:52:19 +00:00
|
|
|
|
2024-10-31 21:11:27 +00:00
|
|
|
let href;
|
|
|
|
if (arguments.length < 3) {
|
|
|
|
href = bindingUrl.parse(input, base, true);
|
|
|
|
} else {
|
|
|
|
const raiseException = parseSymbol !== kParseURLSymbol;
|
|
|
|
const interpretAsWindowsPath = parseSymbol === kCreateURLFromWindowsPathSymbol;
|
|
|
|
const pathToFileURL = interpretAsWindowsPath || (parseSymbol === kCreateURLFromPosixPathSymbol);
|
|
|
|
href = pathToFileURL ?
|
|
|
|
bindingUrl.pathToFileURL(input, interpretAsWindowsPath, base) :
|
|
|
|
bindingUrl.parse(input, base, raiseException);
|
|
|
|
}
|
2024-04-13 12:57:12 +00:00
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static parse(input, base = undefined) {
|
|
|
|
if (arguments.length === 0) {
|
|
|
|
throw new ERR_MISSING_ARGS('url');
|
|
|
|
}
|
|
|
|
const parsedURLObject = new URL(input, base, kParseURLSymbol);
|
|
|
|
return parsedURLObject.href ? parsedURLObject : null;
|
2017-04-19 18:34:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 12:34:03 +00:00
|
|
|
[inspect.custom](depth, opts) {
|
2017-04-05 04:03:14 +00:00
|
|
|
if (typeof depth === 'number' && depth < 0)
|
2018-12-11 21:42:34 +00:00
|
|
|
return this;
|
2017-04-05 04:03:14 +00:00
|
|
|
|
2020-05-17 17:07:04 +00:00
|
|
|
const constructor = getConstructorOf(this) || URL;
|
2023-01-10 05:38:36 +00:00
|
|
|
const obj = { __proto__: { constructor } };
|
2017-04-05 04:03:14 +00:00
|
|
|
|
|
|
|
obj.href = this.href;
|
|
|
|
obj.origin = this.origin;
|
|
|
|
obj.protocol = this.protocol;
|
|
|
|
obj.username = this.username;
|
2017-04-15 04:42:25 +00:00
|
|
|
obj.password = this.password;
|
2017-04-05 04:03:14 +00:00
|
|
|
obj.host = this.host;
|
|
|
|
obj.hostname = this.hostname;
|
|
|
|
obj.port = this.port;
|
|
|
|
obj.pathname = this.pathname;
|
|
|
|
obj.search = this.search;
|
|
|
|
obj.searchParams = this.searchParams;
|
|
|
|
obj.hash = this.hash;
|
|
|
|
|
2016-05-31 18:52:19 +00:00
|
|
|
if (opts.showHidden) {
|
2023-04-07 04:17:14 +00:00
|
|
|
obj[contextForInspect] = this.#context;
|
2016-05-31 18:52:19 +00:00
|
|
|
}
|
2017-04-05 04:03:14 +00:00
|
|
|
|
2020-05-17 17:07:04 +00:00
|
|
|
return `${constructor.name} ${inspect(obj, opts)}`;
|
2016-05-31 18:52:19 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 14:36:36 +00:00
|
|
|
#getSearchFromContext() {
|
|
|
|
if (!this.#context.hasSearch) return '';
|
|
|
|
let endsAt = this.#context.href.length;
|
|
|
|
if (this.#context.hasHash) endsAt = this.#context.hash_start;
|
|
|
|
if (endsAt - this.#context.search_start <= 1) return '';
|
|
|
|
return StringPrototypeSlice(this.#context.href, this.#context.search_start, endsAt);
|
|
|
|
}
|
|
|
|
|
|
|
|
#getSearchFromParams() {
|
|
|
|
if (!this.#searchParams?.size) return '';
|
|
|
|
return `?${this.#searchParams}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ensureSearchParamsUpdated() {
|
|
|
|
// URL is updated lazily to greatly improve performance when URLSearchParams is updated repeatedly.
|
|
|
|
// If URLSearchParams has been modified, reflect that back into URL, without cascading back.
|
|
|
|
if (this.#searchParamsModified) {
|
|
|
|
this.#searchParamsModified = false;
|
|
|
|
this.#updateContext(bindingUrl.update(this.#context.href, updateActions.kSearch, this.#getSearchFromParams()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the internal context state for URL.
|
|
|
|
* @param {string} href New href string from `bindingUrl.update`.
|
|
|
|
* @param {boolean} [shouldUpdateSearchParams] If the update has potential to update search params (href/search).
|
|
|
|
*/
|
|
|
|
#updateContext(href, shouldUpdateSearchParams = false) {
|
|
|
|
const previousSearch = shouldUpdateSearchParams && this.#searchParams &&
|
|
|
|
(this.#searchParamsModified ? this.#getSearchFromParams() : this.#getSearchFromContext());
|
|
|
|
|
2023-03-03 21:34:56 +00:00
|
|
|
this.#context.href = href;
|
2023-03-31 13:03:06 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
0: protocol_end,
|
|
|
|
1: username_end,
|
|
|
|
2: host_start,
|
|
|
|
3: host_end,
|
|
|
|
4: port,
|
|
|
|
5: pathname_start,
|
|
|
|
6: search_start,
|
|
|
|
7: hash_start,
|
|
|
|
8: scheme_type,
|
|
|
|
} = bindingUrl.urlComponents;
|
|
|
|
|
|
|
|
this.#context.protocol_end = protocol_end;
|
|
|
|
this.#context.username_end = username_end;
|
|
|
|
this.#context.host_start = host_start;
|
|
|
|
this.#context.host_end = host_end;
|
2023-03-03 21:34:56 +00:00
|
|
|
this.#context.port = port;
|
2023-03-31 13:03:06 +00:00
|
|
|
this.#context.pathname_start = pathname_start;
|
|
|
|
this.#context.search_start = search_start;
|
|
|
|
this.#context.hash_start = hash_start;
|
|
|
|
this.#context.scheme_type = scheme_type;
|
|
|
|
|
2023-03-03 21:34:56 +00:00
|
|
|
if (this.#searchParams) {
|
2024-01-24 14:36:36 +00:00
|
|
|
// If the search string has updated, URL becomes the source of truth, and we update URLSearchParams.
|
|
|
|
// Only do this when we're expecting it to have changed, otherwise a change to hash etc.
|
|
|
|
// would incorrectly compare the URLSearchParams state to the empty URL search state.
|
|
|
|
if (shouldUpdateSearchParams) {
|
|
|
|
const currentSearch = this.#getSearchFromContext();
|
|
|
|
if (previousSearch !== currentSearch) {
|
|
|
|
setURLSearchParams(this.#searchParams, currentSearch);
|
|
|
|
this.#searchParamsModified = false;
|
|
|
|
}
|
2023-03-31 13:03:06 +00:00
|
|
|
}
|
2024-01-24 14:36:36 +00:00
|
|
|
|
|
|
|
// If we have a URLSearchParams, ensure that URL is up-to-date with any modification to it.
|
|
|
|
this.#ensureSearchParamsUpdated();
|
2016-12-22 09:16:08 +00:00
|
|
|
}
|
2023-03-31 13:03:06 +00:00
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
|
|
|
|
toString() {
|
2024-01-24 14:36:36 +00:00
|
|
|
// Updates to URLSearchParams are lazily propagated to URL, so we need to check we're in sync.
|
|
|
|
this.#ensureSearchParamsUpdated();
|
2023-03-03 21:34:56 +00:00
|
|
|
return this.#context.href;
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get href() {
|
2024-01-24 14:36:36 +00:00
|
|
|
// Updates to URLSearchParams are lazily propagated to URL, so we need to check we're in sync.
|
|
|
|
this.#ensureSearchParamsUpdated();
|
2023-03-03 21:34:56 +00:00
|
|
|
return this.#context.href;
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set href(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
value = `${value}`;
|
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kHref, value);
|
2023-09-28 09:57:38 +00:00
|
|
|
if (!href) { throw new ERR_INVALID_URL(value); }
|
2024-01-24 14:36:36 +00:00
|
|
|
this.#updateContext(href, true);
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// readonly
|
|
|
|
get origin() {
|
2023-03-31 13:03:06 +00:00
|
|
|
const protocol = StringPrototypeSlice(this.#context.href, 0, this.#context.protocol_end);
|
|
|
|
|
|
|
|
// Check if scheme_type is not `NOT_SPECIAL`
|
|
|
|
if (this.#context.scheme_type !== 1) {
|
|
|
|
// Check if scheme_type is `FILE`
|
|
|
|
if (this.#context.scheme_type === 6) {
|
|
|
|
return 'null';
|
|
|
|
}
|
|
|
|
return `${protocol}//${this.host}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (protocol === 'blob:') {
|
|
|
|
const path = this.pathname;
|
|
|
|
if (path.length > 0) {
|
|
|
|
try {
|
|
|
|
const out = new URL(path);
|
2023-06-03 16:52:23 +00:00
|
|
|
// Only return origin of scheme is `http` or `https`
|
|
|
|
// Otherwise return a new opaque origin (null).
|
|
|
|
if (out.#context.scheme_type === 0 || out.#context.scheme_type === 2) {
|
2023-03-31 13:03:06 +00:00
|
|
|
return `${out.protocol}//${out.host}`;
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'null';
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get protocol() {
|
2023-03-31 13:03:06 +00:00
|
|
|
return StringPrototypeSlice(this.#context.href, 0, this.#context.protocol_end);
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set protocol(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kProtocol, `${value}`);
|
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get username() {
|
2023-03-31 13:03:06 +00:00
|
|
|
if (this.#context.protocol_end + 2 < this.#context.username_end) {
|
|
|
|
return StringPrototypeSlice(this.#context.href, this.#context.protocol_end + 2, this.#context.username_end);
|
|
|
|
}
|
|
|
|
return '';
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set username(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kUsername, `${value}`);
|
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get password() {
|
2023-03-31 13:03:06 +00:00
|
|
|
if (this.#context.host_start - this.#context.username_end > 0) {
|
|
|
|
return StringPrototypeSlice(this.#context.href, this.#context.username_end + 1, this.#context.host_start);
|
|
|
|
}
|
|
|
|
return '';
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set password(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kPassword, `${value}`);
|
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get host() {
|
2023-03-31 13:03:06 +00:00
|
|
|
let startsAt = this.#context.host_start;
|
|
|
|
if (this.#context.href[startsAt] === '@') {
|
|
|
|
startsAt++;
|
|
|
|
}
|
|
|
|
// If we have an empty host, then the space between components.host_end and
|
|
|
|
// components.pathname_start may be occupied by /.
|
|
|
|
if (startsAt === this.#context.host_end) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return StringPrototypeSlice(this.#context.href, startsAt, this.#context.pathname_start);
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set host(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kHost, `${value}`);
|
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get hostname() {
|
2023-03-31 13:03:06 +00:00
|
|
|
let startsAt = this.#context.host_start;
|
|
|
|
// host_start might be "@" if the URL has credentials
|
|
|
|
if (this.#context.href[startsAt] === '@') {
|
|
|
|
startsAt++;
|
|
|
|
}
|
|
|
|
return StringPrototypeSlice(this.#context.href, startsAt, this.#context.host_end);
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set hostname(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kHostname, `${value}`);
|
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get port() {
|
2023-03-31 13:03:06 +00:00
|
|
|
if (this.#context.hasPort) {
|
|
|
|
return `${this.#context.port}`;
|
|
|
|
}
|
|
|
|
return '';
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set port(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kPort, `${value}`);
|
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get pathname() {
|
2023-03-31 13:03:06 +00:00
|
|
|
let endsAt;
|
|
|
|
if (this.#context.hasSearch) {
|
|
|
|
endsAt = this.#context.search_start;
|
|
|
|
} else if (this.#context.hasHash) {
|
|
|
|
endsAt = this.#context.hash_start;
|
|
|
|
}
|
|
|
|
return StringPrototypeSlice(this.#context.href, this.#context.pathname_start, endsAt);
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set pathname(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kPathname, `${value}`);
|
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get search() {
|
2024-01-24 14:36:36 +00:00
|
|
|
// Updates to URLSearchParams are lazily propagated to URL, so we need to check we're in sync.
|
|
|
|
this.#ensureSearchParamsUpdated();
|
|
|
|
return this.#getSearchFromContext();
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 14:31:18 +00:00
|
|
|
set search(value) {
|
2023-11-29 16:00:57 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kSearch, StringPrototypeToWellFormed(`${value}`));
|
2023-03-31 13:03:06 +00:00
|
|
|
if (href) {
|
2024-01-24 14:36:36 +00:00
|
|
|
this.#updateContext(href, true);
|
2023-03-31 13:03:06 +00:00
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// readonly
|
|
|
|
get searchParams() {
|
2023-02-27 14:31:18 +00:00
|
|
|
// Create URLSearchParams on demand to greatly improve the URL performance.
|
2023-03-03 21:34:56 +00:00
|
|
|
if (this.#searchParams == null) {
|
2024-01-24 14:36:36 +00:00
|
|
|
this.#searchParams = new URLSearchParams(this.#getSearchFromContext());
|
2023-04-07 04:17:14 +00:00
|
|
|
setURLSearchParamsContext(this.#searchParams, this);
|
2024-01-24 14:36:36 +00:00
|
|
|
this.#searchParamsModified = false;
|
2023-02-27 14:31:18 +00:00
|
|
|
}
|
2023-03-03 21:34:56 +00:00
|
|
|
return this.#searchParams;
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get hash() {
|
2023-03-31 13:03:06 +00:00
|
|
|
if (!this.#context.hasHash || (this.#context.href.length - this.#context.hash_start <= 1)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return StringPrototypeSlice(this.#context.href, this.#context.hash_start);
|
2016-12-22 09:16:08 +00:00
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
|
2023-02-06 13:30:55 +00:00
|
|
|
set hash(value) {
|
2023-03-31 13:03:06 +00:00
|
|
|
const href = bindingUrl.update(this.#context.href, updateActions.kHash, `${value}`);
|
|
|
|
if (href) {
|
|
|
|
this.#updateContext(href);
|
|
|
|
}
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
2024-01-24 14:36:36 +00:00
|
|
|
// Updates to URLSearchParams are lazily propagated to URL, so we need to check we're in sync.
|
|
|
|
this.#ensureSearchParamsUpdated();
|
2023-03-03 21:34:56 +00:00
|
|
|
return this.#context.href;
|
2021-01-05 12:20:00 +00:00
|
|
|
}
|
2023-03-22 19:44:44 +00:00
|
|
|
|
|
|
|
static canParse(url, base = undefined) {
|
2023-04-11 15:24:30 +00:00
|
|
|
if (arguments.length === 0) {
|
|
|
|
throw new ERR_MISSING_ARGS('url');
|
|
|
|
}
|
|
|
|
|
2023-03-22 19:44:44 +00:00
|
|
|
url = `${url}`;
|
|
|
|
|
|
|
|
if (base !== undefined) {
|
2023-08-01 22:06:08 +00:00
|
|
|
return bindingUrl.canParse(url, `${base}`);
|
2023-03-22 19:44:44 +00:00
|
|
|
}
|
|
|
|
|
2023-08-01 22:06:08 +00:00
|
|
|
// It is important to differentiate the canParse call statements
|
|
|
|
// since they resolve into different v8 fast api overloads.
|
2023-07-17 17:42:23 +00:00
|
|
|
return bindingUrl.canParse(url);
|
2023-03-22 19:44:44 +00:00
|
|
|
}
|
2023-03-15 16:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectDefineProperties(URL.prototype, {
|
|
|
|
[SymbolToStringTag]: { __proto__: null, configurable: true, value: 'URL' },
|
|
|
|
toString: kEnumerableProperty,
|
|
|
|
href: kEnumerableProperty,
|
|
|
|
origin: kEnumerableProperty,
|
|
|
|
protocol: kEnumerableProperty,
|
|
|
|
username: kEnumerableProperty,
|
|
|
|
password: kEnumerableProperty,
|
|
|
|
host: kEnumerableProperty,
|
|
|
|
hostname: kEnumerableProperty,
|
|
|
|
port: kEnumerableProperty,
|
|
|
|
pathname: kEnumerableProperty,
|
|
|
|
search: kEnumerableProperty,
|
|
|
|
searchParams: kEnumerableProperty,
|
|
|
|
hash: kEnumerableProperty,
|
|
|
|
toJSON: kEnumerableProperty,
|
|
|
|
});
|
|
|
|
|
2023-03-22 19:44:44 +00:00
|
|
|
ObjectDefineProperties(URL, {
|
|
|
|
canParse: {
|
|
|
|
__proto__: null,
|
|
|
|
configurable: true,
|
|
|
|
writable: true,
|
|
|
|
enumerable: true,
|
|
|
|
},
|
2024-07-04 12:56:57 +00:00
|
|
|
parse: {
|
|
|
|
__proto__: null,
|
|
|
|
configurable: true,
|
|
|
|
writable: true,
|
|
|
|
enumerable: true,
|
|
|
|
},
|
2023-03-22 19:44:44 +00:00
|
|
|
});
|
|
|
|
|
2023-03-15 16:21:53 +00:00
|
|
|
function installObjectURLMethods() {
|
2023-04-30 12:38:32 +00:00
|
|
|
const bindingBlob = internalBinding('blob');
|
2021-08-07 02:26:37 +00:00
|
|
|
|
2023-03-15 16:21:53 +00:00
|
|
|
function createObjectURL(obj) {
|
2021-08-07 02:26:37 +00:00
|
|
|
const cryptoRandom = lazyCryptoRandom();
|
|
|
|
if (cryptoRandom === undefined)
|
|
|
|
throw new ERR_NO_CRYPTO();
|
|
|
|
|
|
|
|
const blob = lazyBlob();
|
|
|
|
if (!blob.isBlob(obj))
|
|
|
|
throw new ERR_INVALID_ARG_TYPE('obj', 'Blob', obj);
|
|
|
|
|
|
|
|
const id = cryptoRandom.randomUUID();
|
|
|
|
|
2023-04-30 12:38:32 +00:00
|
|
|
bindingBlob.storeDataObject(id, obj[blob.kHandle], obj.size, obj.type);
|
2021-08-07 02:26:37 +00:00
|
|
|
|
|
|
|
return `blob:nodedata:${id}`;
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:21:53 +00:00
|
|
|
function revokeObjectURL(url) {
|
2023-11-30 21:26:56 +00:00
|
|
|
if (arguments.length === 0) {
|
|
|
|
throw new ERR_MISSING_ARGS('url');
|
|
|
|
}
|
|
|
|
|
2023-04-30 12:38:32 +00:00
|
|
|
bindingBlob.revokeObjectURL(`${url}`);
|
2021-08-07 02:26:37 +00:00
|
|
|
}
|
2016-12-22 09:16:08 +00:00
|
|
|
|
2023-03-15 16:21:53 +00:00
|
|
|
ObjectDefineProperties(URL, {
|
|
|
|
createObjectURL: {
|
|
|
|
__proto__: null,
|
|
|
|
configurable: true,
|
|
|
|
writable: true,
|
|
|
|
enumerable: true,
|
|
|
|
value: createObjectURL,
|
|
|
|
},
|
|
|
|
revokeObjectURL: {
|
|
|
|
__proto__: null,
|
|
|
|
configurable: true,
|
|
|
|
writable: true,
|
|
|
|
enumerable: true,
|
|
|
|
value: revokeObjectURL,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2022-10-14 23:49:39 +00:00
|
|
|
|
2017-03-15 04:01:04 +00:00
|
|
|
// application/x-www-form-urlencoded parser
|
|
|
|
// Ref: https://url.spec.whatwg.org/#concept-urlencoded-parser
|
|
|
|
function parseParams(qs) {
|
|
|
|
const out = [];
|
2019-11-12 16:20:02 +00:00
|
|
|
let seenSep = false;
|
|
|
|
let buf = '';
|
|
|
|
let encoded = false;
|
|
|
|
let encodeCheck = 0;
|
2023-02-06 13:30:55 +00:00
|
|
|
let i = qs[0] === '?' ? 1 : 0;
|
|
|
|
let pairStart = i;
|
|
|
|
let lastPos = i;
|
|
|
|
for (; i < qs.length; ++i) {
|
2020-11-20 09:20:15 +00:00
|
|
|
const code = StringPrototypeCharCodeAt(qs, i);
|
2017-03-15 04:01:04 +00:00
|
|
|
|
|
|
|
// Try matching key/value pair separator
|
2018-03-12 15:59:31 +00:00
|
|
|
if (code === CHAR_AMPERSAND) {
|
2017-03-15 04:01:04 +00:00
|
|
|
if (pairStart === i) {
|
|
|
|
// We saw an empty substring between pair separators
|
|
|
|
lastPos = pairStart = i + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastPos < i)
|
|
|
|
buf += qs.slice(lastPos, i);
|
|
|
|
if (encoded)
|
|
|
|
buf = querystring.unescape(buf);
|
|
|
|
out.push(buf);
|
|
|
|
|
|
|
|
// If `buf` is the key, add an empty value.
|
|
|
|
if (!seenSep)
|
|
|
|
out.push('');
|
|
|
|
|
|
|
|
seenSep = false;
|
|
|
|
buf = '';
|
|
|
|
encoded = false;
|
|
|
|
encodeCheck = 0;
|
|
|
|
lastPos = pairStart = i + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try matching key/value separator (e.g. '=') if we haven't already
|
2018-03-12 15:59:31 +00:00
|
|
|
if (!seenSep && code === CHAR_EQUAL) {
|
2017-03-15 04:01:04 +00:00
|
|
|
// Key/value separator match!
|
|
|
|
if (lastPos < i)
|
|
|
|
buf += qs.slice(lastPos, i);
|
|
|
|
if (encoded)
|
|
|
|
buf = querystring.unescape(buf);
|
|
|
|
out.push(buf);
|
|
|
|
|
|
|
|
seenSep = true;
|
|
|
|
buf = '';
|
|
|
|
encoded = false;
|
|
|
|
encodeCheck = 0;
|
|
|
|
lastPos = i + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle + and percent decoding.
|
2018-03-12 15:59:31 +00:00
|
|
|
if (code === CHAR_PLUS) {
|
2017-03-15 04:01:04 +00:00
|
|
|
if (lastPos < i)
|
2020-11-20 09:20:15 +00:00
|
|
|
buf += StringPrototypeSlice(qs, lastPos, i);
|
2017-03-15 04:01:04 +00:00
|
|
|
buf += ' ';
|
|
|
|
lastPos = i + 1;
|
|
|
|
} else if (!encoded) {
|
|
|
|
// Try to match an (valid) encoded byte (once) to minimize unnecessary
|
|
|
|
// calls to string decoding functions
|
2018-03-12 15:59:31 +00:00
|
|
|
if (code === CHAR_PERCENT) {
|
2017-03-15 04:01:04 +00:00
|
|
|
encodeCheck = 1;
|
|
|
|
} else if (encodeCheck > 0) {
|
2018-12-12 18:05:17 +00:00
|
|
|
if (isHexTable[code] === 1) {
|
2018-05-06 21:08:42 +00:00
|
|
|
if (++encodeCheck === 3) {
|
2017-03-15 04:01:04 +00:00
|
|
|
encoded = true;
|
2018-05-06 21:08:42 +00:00
|
|
|
}
|
2017-03-15 04:01:04 +00:00
|
|
|
} else {
|
|
|
|
encodeCheck = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-11-06 00:37:24 +00:00
|
|
|
}
|
2016-05-31 18:52:19 +00:00
|
|
|
}
|
2017-03-15 04:01:04 +00:00
|
|
|
|
|
|
|
// Deal with any leftover key or value data
|
|
|
|
|
|
|
|
// There is a trailing &. No more processing is needed.
|
|
|
|
if (pairStart === i)
|
|
|
|
return out;
|
|
|
|
|
|
|
|
if (lastPos < i)
|
2020-11-20 09:20:15 +00:00
|
|
|
buf += StringPrototypeSlice(qs, lastPos, i);
|
2017-03-15 04:01:04 +00:00
|
|
|
if (encoded)
|
|
|
|
buf = querystring.unescape(buf);
|
2020-11-20 09:20:15 +00:00
|
|
|
ArrayPrototypePush(out, buf);
|
2017-03-15 04:01:04 +00:00
|
|
|
|
|
|
|
// If `buf` is the key, add an empty value.
|
|
|
|
if (!seenSep)
|
2020-11-20 09:20:15 +00:00
|
|
|
ArrayPrototypePush(out, '');
|
2017-03-15 04:01:04 +00:00
|
|
|
|
|
|
|
return out;
|
2016-05-31 18:52:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-04 01:34:47 +00:00
|
|
|
// Adapted from querystring's implementation.
|
|
|
|
// Ref: https://url.spec.whatwg.org/#concept-urlencoded-byte-serializer
|
2020-07-05 00:47:39 +00:00
|
|
|
const noEscape = new Int8Array([
|
2018-03-25 14:27:38 +00:00
|
|
|
/*
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
|
|
|
|
*/
|
2017-02-04 01:34:47 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00 - 0x0F
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10 - 0x1F
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, // 0x20 - 0x2F
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 0x30 - 0x3F
|
|
|
|
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 0x4F
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50 - 0x5F
|
|
|
|
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6F
|
2021-02-06 13:36:58 +00:00
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 0x70 - 0x7F
|
2020-07-05 00:47:39 +00:00
|
|
|
]);
|
2017-02-04 01:34:47 +00:00
|
|
|
|
|
|
|
// Special version of hexTable that uses `+` for U+0020 SPACE.
|
|
|
|
const paramHexTable = hexTable.slice();
|
|
|
|
paramHexTable[0x20] = '+';
|
|
|
|
|
|
|
|
// application/x-www-form-urlencoded serializer
|
|
|
|
// Ref: https://url.spec.whatwg.org/#concept-urlencoded-serializer
|
|
|
|
function serializeParams(array) {
|
|
|
|
const len = array.length;
|
|
|
|
if (len === 0)
|
|
|
|
return '';
|
|
|
|
|
2018-03-01 18:56:39 +00:00
|
|
|
const firstEncodedParam = encodeStr(array[0], noEscape, paramHexTable);
|
|
|
|
const firstEncodedValue = encodeStr(array[1], noEscape, paramHexTable);
|
2018-03-01 19:18:37 +00:00
|
|
|
let output = `${firstEncodedParam}=${firstEncodedValue}`;
|
2018-03-01 18:56:39 +00:00
|
|
|
|
2019-11-12 16:20:02 +00:00
|
|
|
for (let i = 2; i < len; i += 2) {
|
2018-03-01 18:56:39 +00:00
|
|
|
const encodedParam = encodeStr(array[i], noEscape, paramHexTable);
|
|
|
|
const encodedValue = encodeStr(array[i + 1], noEscape, paramHexTable);
|
|
|
|
output += `&${encodedParam}=${encodedValue}`;
|
|
|
|
}
|
|
|
|
|
2017-02-04 01:34:47 +00:00
|
|
|
return output;
|
2016-12-22 09:16:08 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 21:59:13 +00:00
|
|
|
// for merge sort
|
|
|
|
function merge(out, start, mid, end, lBuffer, rBuffer) {
|
|
|
|
const sizeLeft = mid - start;
|
|
|
|
const sizeRight = end - mid;
|
2019-11-12 16:20:02 +00:00
|
|
|
let l, r, o;
|
2017-01-28 21:59:13 +00:00
|
|
|
|
|
|
|
for (l = 0; l < sizeLeft; l++)
|
|
|
|
lBuffer[l] = out[start + l];
|
|
|
|
for (r = 0; r < sizeRight; r++)
|
|
|
|
rBuffer[r] = out[mid + r];
|
|
|
|
|
|
|
|
l = 0;
|
|
|
|
r = 0;
|
|
|
|
o = start;
|
|
|
|
while (l < sizeLeft && r < sizeRight) {
|
|
|
|
if (lBuffer[l] <= rBuffer[r]) {
|
|
|
|
out[o++] = lBuffer[l++];
|
|
|
|
out[o++] = lBuffer[l++];
|
|
|
|
} else {
|
|
|
|
out[o++] = rBuffer[r++];
|
|
|
|
out[o++] = rBuffer[r++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (l < sizeLeft)
|
|
|
|
out[o++] = lBuffer[l++];
|
|
|
|
while (r < sizeRight)
|
|
|
|
out[o++] = rBuffer[r++];
|
|
|
|
}
|
|
|
|
|
2016-12-28 23:55:00 +00:00
|
|
|
function domainToASCII(domain) {
|
2017-03-20 21:29:54 +00:00
|
|
|
if (arguments.length < 1)
|
2018-03-04 21:16:24 +00:00
|
|
|
throw new ERR_MISSING_ARGS('domain');
|
2017-03-20 21:29:54 +00:00
|
|
|
|
2023-11-29 16:00:57 +00:00
|
|
|
// StringPrototypeToWellFormed is not needed.
|
2023-03-31 13:03:06 +00:00
|
|
|
return bindingUrl.domainToASCII(`${domain}`);
|
2016-12-28 23:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function domainToUnicode(domain) {
|
2017-03-20 21:29:54 +00:00
|
|
|
if (arguments.length < 1)
|
2018-03-04 21:16:24 +00:00
|
|
|
throw new ERR_MISSING_ARGS('domain');
|
2017-03-20 21:29:54 +00:00
|
|
|
|
2023-11-29 16:00:57 +00:00
|
|
|
// StringPrototypeToWellFormed is not needed.
|
2023-03-31 13:03:06 +00:00
|
|
|
return bindingUrl.domainToUnicode(`${domain}`);
|
2016-12-28 23:55:00 +00:00
|
|
|
}
|
2016-05-31 18:52:19 +00:00
|
|
|
|
2023-03-19 03:25:35 +00:00
|
|
|
/**
|
|
|
|
* Utility function that converts a URL object into an ordinary options object
|
|
|
|
* as expected by the `http.request` and `https.request` APIs.
|
|
|
|
* @param {URL} url
|
|
|
|
* @returns {Record<string, unknown>}
|
|
|
|
*/
|
2021-01-06 08:10:28 +00:00
|
|
|
function urlToHttpOptions(url) {
|
2023-03-19 03:25:35 +00:00
|
|
|
const { hostname, pathname, port, username, password, search } = url;
|
2019-03-26 04:21:27 +00:00
|
|
|
const options = {
|
2023-03-19 03:25:35 +00:00
|
|
|
__proto__: null,
|
|
|
|
...url, // In case the url object was extended by the user.
|
2017-01-05 18:25:46 +00:00
|
|
|
protocol: url.protocol,
|
2024-10-19 10:18:10 +00:00
|
|
|
hostname: hostname && hostname[0] === '[' ?
|
2023-03-19 03:25:35 +00:00
|
|
|
StringPrototypeSlice(hostname, 1, -1) :
|
|
|
|
hostname,
|
2017-01-05 18:25:46 +00:00
|
|
|
hash: url.hash,
|
2023-03-19 03:25:35 +00:00
|
|
|
search: search,
|
|
|
|
pathname: pathname,
|
|
|
|
path: `${pathname || ''}${search || ''}`,
|
2023-02-26 10:34:02 +00:00
|
|
|
href: url.href,
|
2017-01-05 18:25:46 +00:00
|
|
|
};
|
2023-03-19 03:25:35 +00:00
|
|
|
if (port !== '') {
|
|
|
|
options.port = Number(port);
|
2017-01-05 18:25:46 +00:00
|
|
|
}
|
2023-03-19 03:25:35 +00:00
|
|
|
if (username || password) {
|
|
|
|
options.auth = `${decodeURIComponent(username)}:${decodeURIComponent(password)}`;
|
2017-01-05 18:25:46 +00:00
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2017-01-11 15:02:40 +00:00
|
|
|
function getPathFromURLWin32(url) {
|
2019-03-26 04:21:27 +00:00
|
|
|
const hostname = url.hostname;
|
2019-11-12 16:20:02 +00:00
|
|
|
let pathname = url.pathname;
|
|
|
|
for (let n = 0; n < pathname.length; n++) {
|
2017-01-11 15:02:40 +00:00
|
|
|
if (pathname[n] === '%') {
|
2023-01-22 13:13:24 +00:00
|
|
|
const third = StringPrototypeCodePointAt(pathname, n + 2) | 0x20;
|
2017-01-11 15:02:40 +00:00
|
|
|
if ((pathname[n + 1] === '2' && third === 102) || // 2f 2F /
|
|
|
|
(pathname[n + 1] === '5' && third === 99)) { // 5c 5C \
|
2018-03-04 21:16:24 +00:00
|
|
|
throw new ERR_INVALID_FILE_URL_PATH(
|
2023-02-14 17:45:16 +00:00
|
|
|
'must not include encoded \\ or / characters',
|
2018-03-04 21:16:24 +00:00
|
|
|
);
|
2017-01-11 15:02:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-22 13:13:24 +00:00
|
|
|
pathname = SideEffectFreeRegExpPrototypeSymbolReplace(FORWARD_SLASH, pathname, '\\');
|
2017-01-11 15:02:40 +00:00
|
|
|
pathname = decodeURIComponent(pathname);
|
|
|
|
if (hostname !== '') {
|
|
|
|
// If hostname is set, then we have a UNC path
|
|
|
|
// Pass the hostname through domainToUnicode just in case
|
|
|
|
// it is an IDN using punycode encoding. We do not need to worry
|
|
|
|
// about percent encoding because the URL parser will have
|
|
|
|
// already taken care of that for us. Note that this only
|
|
|
|
// causes IDNs with an appropriate `xn--` prefix to be decoded.
|
2018-12-29 20:57:39 +00:00
|
|
|
return `\\\\${domainToUnicode(hostname)}${pathname}`;
|
2017-01-11 15:02:40 +00:00
|
|
|
}
|
2020-04-08 16:58:03 +00:00
|
|
|
// Otherwise, it's a local path that requires a drive letter
|
2023-01-22 13:13:24 +00:00
|
|
|
const letter = StringPrototypeCodePointAt(pathname, 1) | 0x20;
|
|
|
|
const sep = StringPrototypeCharAt(pathname, 2);
|
2020-04-08 16:58:03 +00:00
|
|
|
if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || // a..z A..Z
|
|
|
|
(sep !== ':')) {
|
|
|
|
throw new ERR_INVALID_FILE_URL_PATH('must be absolute');
|
|
|
|
}
|
2023-01-22 13:13:24 +00:00
|
|
|
return StringPrototypeSlice(pathname, 1);
|
2017-01-11 15:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPathFromURLPosix(url) {
|
|
|
|
if (url.hostname !== '') {
|
2024-07-15 23:09:54 +00:00
|
|
|
throw new ERR_INVALID_FILE_URL_HOST(platform);
|
2017-01-11 15:02:40 +00:00
|
|
|
}
|
2019-03-26 04:21:27 +00:00
|
|
|
const pathname = url.pathname;
|
2019-11-12 16:20:02 +00:00
|
|
|
for (let n = 0; n < pathname.length; n++) {
|
2017-01-11 15:02:40 +00:00
|
|
|
if (pathname[n] === '%') {
|
2023-01-22 13:13:24 +00:00
|
|
|
const third = StringPrototypeCodePointAt(pathname, n + 2) | 0x20;
|
2017-01-11 15:02:40 +00:00
|
|
|
if (pathname[n + 1] === '2' && third === 102) {
|
2018-03-04 21:16:24 +00:00
|
|
|
throw new ERR_INVALID_FILE_URL_PATH(
|
2023-02-14 17:45:16 +00:00
|
|
|
'must not include encoded / characters',
|
2018-03-04 21:16:24 +00:00
|
|
|
);
|
2017-01-11 15:02:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return decodeURIComponent(pathname);
|
|
|
|
}
|
|
|
|
|
2024-04-24 15:47:48 +00:00
|
|
|
function fileURLToPath(path, options = kEmptyObject) {
|
|
|
|
const windows = options?.windows;
|
2018-08-24 16:13:32 +00:00
|
|
|
if (typeof path === 'string')
|
|
|
|
path = new URL(path);
|
2023-03-03 21:34:56 +00:00
|
|
|
else if (!isURL(path))
|
2018-08-24 16:13:32 +00:00
|
|
|
throw new ERR_INVALID_ARG_TYPE('path', ['string', 'URL'], path);
|
2017-01-11 15:02:40 +00:00
|
|
|
if (path.protocol !== 'file:')
|
2018-03-04 21:16:24 +00:00
|
|
|
throw new ERR_INVALID_URL_SCHEME('file');
|
2024-04-24 15:47:48 +00:00
|
|
|
return (windows ?? isWindows) ? getPathFromURLWin32(path) : getPathFromURLPosix(path);
|
2017-01-11 15:02:40 +00:00
|
|
|
}
|
|
|
|
|
2024-04-24 15:47:48 +00:00
|
|
|
function pathToFileURL(filepath, options = kEmptyObject) {
|
2024-10-18 07:20:43 +00:00
|
|
|
const windows = options?.windows ?? isWindows;
|
|
|
|
if (windows && StringPrototypeStartsWith(filepath, '\\\\')) {
|
2020-08-12 01:12:47 +00:00
|
|
|
// UNC path format: \\server\share\resource
|
2024-08-12 14:48:39 +00:00
|
|
|
// Handle extended UNC path and standard UNC path
|
|
|
|
// "\\?\UNC\" path prefix should be ignored.
|
|
|
|
// Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
|
|
|
|
const isExtendedUNC = StringPrototypeStartsWith(filepath, '\\\\?\\UNC\\');
|
|
|
|
const prefixLength = isExtendedUNC ? 8 : 2;
|
|
|
|
const hostnameEndIndex = StringPrototypeIndexOf(filepath, '\\', prefixLength);
|
2023-01-22 13:13:24 +00:00
|
|
|
if (hostnameEndIndex === -1) {
|
2020-08-12 01:12:47 +00:00
|
|
|
throw new ERR_INVALID_ARG_VALUE(
|
2023-08-14 09:19:34 +00:00
|
|
|
'path',
|
2020-08-12 01:12:47 +00:00
|
|
|
filepath,
|
2023-02-14 17:45:16 +00:00
|
|
|
'Missing UNC resource path',
|
2020-08-12 01:12:47 +00:00
|
|
|
);
|
|
|
|
}
|
2023-01-22 13:13:24 +00:00
|
|
|
if (hostnameEndIndex === 2) {
|
2020-08-12 01:12:47 +00:00
|
|
|
throw new ERR_INVALID_ARG_VALUE(
|
2023-08-14 09:19:34 +00:00
|
|
|
'path',
|
2020-08-12 01:12:47 +00:00
|
|
|
filepath,
|
2023-02-14 17:45:16 +00:00
|
|
|
'Empty UNC servername',
|
2020-08-12 01:12:47 +00:00
|
|
|
);
|
|
|
|
}
|
2024-08-12 14:48:39 +00:00
|
|
|
const hostname = StringPrototypeSlice(filepath, prefixLength, hostnameEndIndex);
|
2024-10-31 21:11:27 +00:00
|
|
|
return new URL(StringPrototypeSlice(filepath, hostnameEndIndex), hostname, kCreateURLFromWindowsPathSymbol);
|
2023-07-16 23:24:48 +00:00
|
|
|
}
|
2024-10-21 07:10:47 +00:00
|
|
|
let resolved = windows ? path.win32.resolve(filepath) : path.posix.resolve(filepath);
|
|
|
|
// path.resolve strips trailing slashes so we must add them back
|
|
|
|
const filePathLast = StringPrototypeCharCodeAt(filepath,
|
|
|
|
filepath.length - 1);
|
|
|
|
if ((filePathLast === CHAR_FORWARD_SLASH ||
|
|
|
|
((windows ?? isWindows) && filePathLast === CHAR_BACKWARD_SLASH)) &&
|
|
|
|
resolved[resolved.length - 1] !== path.sep)
|
|
|
|
resolved += '/';
|
2023-07-16 23:24:48 +00:00
|
|
|
|
2024-10-31 21:11:27 +00:00
|
|
|
return new URL(resolved, undefined, windows ? kCreateURLFromWindowsPathSymbol : kCreateURLFromPosixPathSymbol);
|
2018-08-24 16:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toPathIfFileURL(fileURLOrPath) {
|
2023-03-03 21:34:56 +00:00
|
|
|
if (!isURL(fileURLOrPath))
|
2018-08-24 16:13:32 +00:00
|
|
|
return fileURLOrPath;
|
|
|
|
return fileURLToPath(fileURLOrPath);
|
2017-06-06 00:44:56 +00:00
|
|
|
}
|
|
|
|
|
2023-06-07 02:15:43 +00:00
|
|
|
/**
|
|
|
|
* This util takes a string containing a URL and return the URL origin,
|
|
|
|
* its meant to avoid calls to `new URL` constructor.
|
|
|
|
* @param {string} url
|
|
|
|
* @returns {URL['origin']}
|
|
|
|
*/
|
|
|
|
function getURLOrigin(url) {
|
|
|
|
return bindingUrl.getOrigin(url);
|
|
|
|
}
|
|
|
|
|
2017-02-04 05:53:27 +00:00
|
|
|
module.exports = {
|
2018-08-24 16:13:32 +00:00
|
|
|
fileURLToPath,
|
|
|
|
pathToFileURL,
|
|
|
|
toPathIfFileURL,
|
2023-03-15 16:21:53 +00:00
|
|
|
installObjectURLMethods,
|
2017-02-04 05:53:27 +00:00
|
|
|
URL,
|
|
|
|
URLSearchParams,
|
2024-06-13 18:32:59 +00:00
|
|
|
URLParse: URL.parse,
|
2017-02-04 05:53:27 +00:00
|
|
|
domainToASCII,
|
|
|
|
domainToUnicode,
|
2021-01-06 08:10:28 +00:00
|
|
|
urlToHttpOptions,
|
2023-02-26 10:34:02 +00:00
|
|
|
encodeStr,
|
2023-02-27 14:31:18 +00:00
|
|
|
isURL,
|
2023-03-31 13:03:06 +00:00
|
|
|
|
|
|
|
urlUpdateActions: updateActions,
|
2023-06-07 02:15:43 +00:00
|
|
|
getURLOrigin,
|
2023-06-29 18:45:31 +00:00
|
|
|
unsafeProtocol,
|
|
|
|
hostlessProtocol,
|
|
|
|
slashedProtocol,
|
2017-02-04 05:53:27 +00:00
|
|
|
};
|