@secure-exec/nodejs 0.2.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +7 -0
- package/dist/bindings.d.ts +31 -0
- package/dist/bindings.js +67 -0
- package/dist/bridge/active-handles.d.ts +22 -0
- package/dist/bridge/active-handles.js +112 -0
- package/dist/bridge/child-process.d.ts +99 -0
- package/dist/bridge/child-process.js +672 -0
- package/dist/bridge/dispatch.d.ts +2 -0
- package/dist/bridge/dispatch.js +40 -0
- package/dist/bridge/fs.d.ts +502 -0
- package/dist/bridge/fs.js +3307 -0
- package/dist/bridge/index.d.ts +10 -0
- package/dist/bridge/index.js +41 -0
- package/dist/bridge/module.d.ts +75 -0
- package/dist/bridge/module.js +325 -0
- package/dist/bridge/network.d.ts +1093 -0
- package/dist/bridge/network.js +8651 -0
- package/dist/bridge/os.d.ts +13 -0
- package/dist/bridge/os.js +256 -0
- package/dist/bridge/polyfills.d.ts +9 -0
- package/dist/bridge/polyfills.js +67 -0
- package/dist/bridge/process.d.ts +121 -0
- package/dist/bridge/process.js +1382 -0
- package/dist/bridge/whatwg-url.d.ts +67 -0
- package/dist/bridge/whatwg-url.js +712 -0
- package/dist/bridge-contract.d.ts +774 -0
- package/dist/bridge-contract.js +172 -0
- package/dist/bridge-handlers.d.ts +199 -0
- package/dist/bridge-handlers.js +4263 -0
- package/dist/bridge-loader.d.ts +9 -0
- package/dist/bridge-loader.js +87 -0
- package/dist/bridge-setup.d.ts +1 -0
- package/dist/bridge-setup.js +3 -0
- package/dist/bridge.js +21652 -0
- package/dist/builtin-modules.d.ts +25 -0
- package/dist/builtin-modules.js +312 -0
- package/dist/default-network-adapter.d.ts +13 -0
- package/dist/default-network-adapter.js +351 -0
- package/dist/driver.d.ts +87 -0
- package/dist/driver.js +191 -0
- package/dist/esm-compiler.d.ts +14 -0
- package/dist/esm-compiler.js +68 -0
- package/dist/execution-driver.d.ts +37 -0
- package/dist/execution-driver.js +977 -0
- package/dist/host-network-adapter.d.ts +7 -0
- package/dist/host-network-adapter.js +279 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +23 -0
- package/dist/isolate-bootstrap.d.ts +86 -0
- package/dist/isolate-bootstrap.js +125 -0
- package/dist/ivm-compat.d.ts +7 -0
- package/dist/ivm-compat.js +31 -0
- package/dist/kernel-runtime.d.ts +58 -0
- package/dist/kernel-runtime.js +535 -0
- package/dist/module-access.d.ts +75 -0
- package/dist/module-access.js +606 -0
- package/dist/module-resolver.d.ts +8 -0
- package/dist/module-resolver.js +150 -0
- package/dist/os-filesystem.d.ts +42 -0
- package/dist/os-filesystem.js +161 -0
- package/dist/package-bundler.d.ts +36 -0
- package/dist/package-bundler.js +497 -0
- package/dist/polyfills.d.ts +17 -0
- package/dist/polyfills.js +97 -0
- package/dist/worker-adapter.d.ts +21 -0
- package/dist/worker-adapter.js +34 -0
- package/package.json +123 -0
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
// @ts-ignore whatwg-url ships without bundled TypeScript declarations in this repo.
|
|
2
|
+
import { URL as WhatwgURL, URLSearchParams as WhatwgURLSearchParams, } from "whatwg-url";
|
|
3
|
+
const inspectCustomSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
4
|
+
const toStringTagSymbol = Symbol.toStringTag;
|
|
5
|
+
const ERR_INVALID_THIS = "ERR_INVALID_THIS";
|
|
6
|
+
const ERR_MISSING_ARGS = "ERR_MISSING_ARGS";
|
|
7
|
+
const ERR_INVALID_URL = "ERR_INVALID_URL";
|
|
8
|
+
const ERR_ARG_NOT_ITERABLE = "ERR_ARG_NOT_ITERABLE";
|
|
9
|
+
const ERR_INVALID_TUPLE = "ERR_INVALID_TUPLE";
|
|
10
|
+
const URL_SEARCH_PARAMS_TYPE = "URLSearchParams";
|
|
11
|
+
const kLinkedSearchParams = Symbol("secureExecLinkedURLSearchParams");
|
|
12
|
+
const kBlobUrlStore = Symbol.for("secureExec.blobUrlStore");
|
|
13
|
+
const kBlobUrlCounter = Symbol.for("secureExec.blobUrlCounter");
|
|
14
|
+
const SEARCH_PARAM_METHOD_NAMES = ["append", "delete", "get", "getAll", "has"];
|
|
15
|
+
const SEARCH_PARAM_PAIR_METHOD_NAMES = ["append", "set"];
|
|
16
|
+
const URL_SCHEME_TYPES = {
|
|
17
|
+
"http:": 0,
|
|
18
|
+
"https:": 2,
|
|
19
|
+
"ws:": 4,
|
|
20
|
+
"wss:": 5,
|
|
21
|
+
"file:": 6,
|
|
22
|
+
"ftp:": 8,
|
|
23
|
+
};
|
|
24
|
+
const searchParamsBrand = new WeakSet();
|
|
25
|
+
const searchParamsState = new WeakMap();
|
|
26
|
+
const searchParamsIteratorBrand = new WeakSet();
|
|
27
|
+
const searchParamsIteratorState = new WeakMap();
|
|
28
|
+
function createNodeTypeError(message, code) {
|
|
29
|
+
const error = new TypeError(message);
|
|
30
|
+
error.code = code;
|
|
31
|
+
return error;
|
|
32
|
+
}
|
|
33
|
+
function createInvalidUrlError() {
|
|
34
|
+
const error = new TypeError("Invalid URL");
|
|
35
|
+
error.code = ERR_INVALID_URL;
|
|
36
|
+
return error;
|
|
37
|
+
}
|
|
38
|
+
function createUrlReceiverTypeError() {
|
|
39
|
+
return new TypeError("Receiver must be an instance of class URL");
|
|
40
|
+
}
|
|
41
|
+
function createMissingArgsError(message) {
|
|
42
|
+
return createNodeTypeError(message, ERR_MISSING_ARGS);
|
|
43
|
+
}
|
|
44
|
+
function createIterableTypeError() {
|
|
45
|
+
return createNodeTypeError("Query pairs must be iterable", ERR_ARG_NOT_ITERABLE);
|
|
46
|
+
}
|
|
47
|
+
function createTupleTypeError() {
|
|
48
|
+
return createNodeTypeError("Each query pair must be an iterable [name, value] tuple", ERR_INVALID_TUPLE);
|
|
49
|
+
}
|
|
50
|
+
function createSymbolStringError() {
|
|
51
|
+
return new TypeError("Cannot convert a Symbol value to a string");
|
|
52
|
+
}
|
|
53
|
+
function toNodeString(value) {
|
|
54
|
+
if (typeof value === "symbol") {
|
|
55
|
+
throw createSymbolStringError();
|
|
56
|
+
}
|
|
57
|
+
return String(value);
|
|
58
|
+
}
|
|
59
|
+
function toWellFormedString(value) {
|
|
60
|
+
let result = "";
|
|
61
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
62
|
+
const codeUnit = value.charCodeAt(index);
|
|
63
|
+
if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
|
|
64
|
+
const nextIndex = index + 1;
|
|
65
|
+
if (nextIndex < value.length) {
|
|
66
|
+
const nextCodeUnit = value.charCodeAt(nextIndex);
|
|
67
|
+
if (nextCodeUnit >= 0xdc00 && nextCodeUnit <= 0xdfff) {
|
|
68
|
+
result += value[index] + value[nextIndex];
|
|
69
|
+
index = nextIndex;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
result += "\uFFFD";
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
|
|
77
|
+
result += "\uFFFD";
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
result += value[index];
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
function toNodeUSVString(value) {
|
|
85
|
+
return toWellFormedString(toNodeString(value));
|
|
86
|
+
}
|
|
87
|
+
function assertUrlSearchParamsReceiver(receiver) {
|
|
88
|
+
if (!searchParamsBrand.has(receiver)) {
|
|
89
|
+
throw createNodeTypeError('Value of "this" must be of type URLSearchParams', ERR_INVALID_THIS);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function assertUrlSearchParamsIteratorReceiver(receiver) {
|
|
93
|
+
if (!searchParamsIteratorBrand.has(receiver)) {
|
|
94
|
+
throw createNodeTypeError('Value of "this" must be of type URLSearchParamsIterator', ERR_INVALID_THIS);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function getUrlSearchParamsImpl(receiver) {
|
|
98
|
+
const state = searchParamsState.get(receiver);
|
|
99
|
+
if (!state) {
|
|
100
|
+
throw createNodeTypeError('Value of "this" must be of type URLSearchParams', ERR_INVALID_THIS);
|
|
101
|
+
}
|
|
102
|
+
return state.getImpl();
|
|
103
|
+
}
|
|
104
|
+
function countSearchParams(params) {
|
|
105
|
+
let count = 0;
|
|
106
|
+
for (const _entry of params) {
|
|
107
|
+
count++;
|
|
108
|
+
}
|
|
109
|
+
return count;
|
|
110
|
+
}
|
|
111
|
+
function normalizeSearchParamsInit(init) {
|
|
112
|
+
if (init &&
|
|
113
|
+
typeof init === "object" &&
|
|
114
|
+
kLinkedSearchParams in init) {
|
|
115
|
+
return init;
|
|
116
|
+
}
|
|
117
|
+
if (init == null) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
if (typeof init === "string") {
|
|
121
|
+
return toNodeUSVString(init);
|
|
122
|
+
}
|
|
123
|
+
if (typeof init === "object" || typeof init === "function") {
|
|
124
|
+
const iterator = init[Symbol.iterator];
|
|
125
|
+
if (iterator !== undefined) {
|
|
126
|
+
if (typeof iterator !== "function") {
|
|
127
|
+
throw createIterableTypeError();
|
|
128
|
+
}
|
|
129
|
+
const pairs = [];
|
|
130
|
+
for (const pair of init) {
|
|
131
|
+
if (pair == null) {
|
|
132
|
+
throw createTupleTypeError();
|
|
133
|
+
}
|
|
134
|
+
const pairIterator = pair[Symbol.iterator];
|
|
135
|
+
if (typeof pairIterator !== "function") {
|
|
136
|
+
throw createTupleTypeError();
|
|
137
|
+
}
|
|
138
|
+
const values = Array.from(pair);
|
|
139
|
+
if (values.length !== 2) {
|
|
140
|
+
throw createTupleTypeError();
|
|
141
|
+
}
|
|
142
|
+
pairs.push([toNodeUSVString(values[0]), toNodeUSVString(values[1])]);
|
|
143
|
+
}
|
|
144
|
+
return pairs;
|
|
145
|
+
}
|
|
146
|
+
const pairs = [];
|
|
147
|
+
for (const key of Reflect.ownKeys(init)) {
|
|
148
|
+
if (!Object.prototype.propertyIsEnumerable.call(init, key)) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
pairs.push([
|
|
152
|
+
toNodeUSVString(key),
|
|
153
|
+
toNodeUSVString(init[key]),
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
return pairs;
|
|
157
|
+
}
|
|
158
|
+
return toNodeUSVString(init);
|
|
159
|
+
}
|
|
160
|
+
function createStandaloneSearchParams(init) {
|
|
161
|
+
if (typeof init === "string") {
|
|
162
|
+
return new WhatwgURLSearchParams(init);
|
|
163
|
+
}
|
|
164
|
+
return init === undefined
|
|
165
|
+
? new WhatwgURLSearchParams()
|
|
166
|
+
: new WhatwgURLSearchParams(init);
|
|
167
|
+
}
|
|
168
|
+
function createCollectionBody(items, options, emptyBody) {
|
|
169
|
+
if (items.length === 0) {
|
|
170
|
+
return emptyBody;
|
|
171
|
+
}
|
|
172
|
+
const oneLine = `{ ${items.join(", ")} }`;
|
|
173
|
+
const breakLength = options?.breakLength ?? Infinity;
|
|
174
|
+
if (oneLine.length <= breakLength) {
|
|
175
|
+
return oneLine;
|
|
176
|
+
}
|
|
177
|
+
return `{\n ${items.join(",\n ")} }`;
|
|
178
|
+
}
|
|
179
|
+
function createUrlContext(url) {
|
|
180
|
+
const href = url.href;
|
|
181
|
+
const protocolEnd = href.indexOf(":") + 1;
|
|
182
|
+
const authIndex = href.indexOf("@");
|
|
183
|
+
const pathnameStart = href.indexOf("/", protocolEnd + 2);
|
|
184
|
+
const searchStart = href.indexOf("?");
|
|
185
|
+
const hashStart = href.indexOf("#");
|
|
186
|
+
const usernameEnd = url.username.length > 0
|
|
187
|
+
? href.indexOf(":", protocolEnd + 2)
|
|
188
|
+
: protocolEnd + 2;
|
|
189
|
+
const hostStart = authIndex === -1 ? protocolEnd + 2 : authIndex;
|
|
190
|
+
const hostEnd = pathnameStart === -1
|
|
191
|
+
? href.length
|
|
192
|
+
: pathnameStart - (url.port.length > 0 ? url.port.length + 1 : 0);
|
|
193
|
+
const port = url.port.length > 0 ? Number(url.port) : null;
|
|
194
|
+
return {
|
|
195
|
+
href,
|
|
196
|
+
protocol_end: protocolEnd,
|
|
197
|
+
username_end: usernameEnd,
|
|
198
|
+
host_start: hostStart,
|
|
199
|
+
host_end: hostEnd,
|
|
200
|
+
pathname_start: pathnameStart === -1 ? href.length : pathnameStart,
|
|
201
|
+
search_start: searchStart === -1 ? href.length : searchStart,
|
|
202
|
+
hash_start: hashStart === -1 ? href.length : hashStart,
|
|
203
|
+
port,
|
|
204
|
+
scheme_type: URL_SCHEME_TYPES[url.protocol] ?? 1,
|
|
205
|
+
hasPort: url.port.length > 0,
|
|
206
|
+
hasSearch: url.search.length > 0,
|
|
207
|
+
hasHash: url.hash.length > 0,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function formatUrlContext(url, inspect, options) {
|
|
211
|
+
const context = createUrlContext(url);
|
|
212
|
+
const formatValue = typeof inspect === "function"
|
|
213
|
+
? (value) => inspect(value, options)
|
|
214
|
+
: (value) => JSON.stringify(value);
|
|
215
|
+
const portValue = context.port === null ? "null" : String(context.port);
|
|
216
|
+
return [
|
|
217
|
+
"URLContext {",
|
|
218
|
+
` href: ${formatValue(context.href)},`,
|
|
219
|
+
` protocol_end: ${context.protocol_end},`,
|
|
220
|
+
` username_end: ${context.username_end},`,
|
|
221
|
+
` host_start: ${context.host_start},`,
|
|
222
|
+
` host_end: ${context.host_end},`,
|
|
223
|
+
` pathname_start: ${context.pathname_start},`,
|
|
224
|
+
` search_start: ${context.search_start},`,
|
|
225
|
+
` hash_start: ${context.hash_start},`,
|
|
226
|
+
` port: ${portValue},`,
|
|
227
|
+
` scheme_type: ${context.scheme_type},`,
|
|
228
|
+
" [hasPort]: [Getter],",
|
|
229
|
+
" [hasSearch]: [Getter],",
|
|
230
|
+
" [hasHash]: [Getter]",
|
|
231
|
+
" }",
|
|
232
|
+
].join("\n");
|
|
233
|
+
}
|
|
234
|
+
function getBlobUrlStore() {
|
|
235
|
+
const globalRecord = globalThis;
|
|
236
|
+
const existing = globalRecord[kBlobUrlStore];
|
|
237
|
+
if (existing instanceof Map) {
|
|
238
|
+
return existing;
|
|
239
|
+
}
|
|
240
|
+
const store = new Map();
|
|
241
|
+
globalRecord[kBlobUrlStore] = store;
|
|
242
|
+
return store;
|
|
243
|
+
}
|
|
244
|
+
function nextBlobUrlId() {
|
|
245
|
+
const globalRecord = globalThis;
|
|
246
|
+
const nextId = typeof globalRecord[kBlobUrlCounter] === "number" ? globalRecord[kBlobUrlCounter] : 1;
|
|
247
|
+
globalRecord[kBlobUrlCounter] = nextId + 1;
|
|
248
|
+
return nextId;
|
|
249
|
+
}
|
|
250
|
+
export class URLSearchParamsIterator {
|
|
251
|
+
constructor(values) {
|
|
252
|
+
searchParamsIteratorBrand.add(this);
|
|
253
|
+
searchParamsIteratorState.set(this, { values, index: 0 });
|
|
254
|
+
}
|
|
255
|
+
next() {
|
|
256
|
+
assertUrlSearchParamsIteratorReceiver(this);
|
|
257
|
+
const state = searchParamsIteratorState.get(this);
|
|
258
|
+
if (state.index >= state.values.length) {
|
|
259
|
+
return { value: undefined, done: true };
|
|
260
|
+
}
|
|
261
|
+
const value = state.values[state.index];
|
|
262
|
+
state.index += 1;
|
|
263
|
+
return { value, done: false };
|
|
264
|
+
}
|
|
265
|
+
[inspectCustomSymbol](depth, options, inspect) {
|
|
266
|
+
assertUrlSearchParamsIteratorReceiver(this);
|
|
267
|
+
if (depth < 0) {
|
|
268
|
+
return "[Object]";
|
|
269
|
+
}
|
|
270
|
+
const state = searchParamsIteratorState.get(this);
|
|
271
|
+
const formatValue = typeof inspect === "function"
|
|
272
|
+
? (value) => inspect(value, options)
|
|
273
|
+
: (value) => JSON.stringify(value);
|
|
274
|
+
const remaining = state.values.slice(state.index).map((value) => formatValue(value));
|
|
275
|
+
return `URLSearchParams Iterator ${createCollectionBody(remaining, options, "{ }")}`;
|
|
276
|
+
}
|
|
277
|
+
get [toStringTagSymbol]() {
|
|
278
|
+
if (this !== URLSearchParamsIterator.prototype) {
|
|
279
|
+
assertUrlSearchParamsIteratorReceiver(this);
|
|
280
|
+
}
|
|
281
|
+
return "URLSearchParams Iterator";
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
Object.defineProperties(URLSearchParamsIterator.prototype, {
|
|
285
|
+
next: {
|
|
286
|
+
value: URLSearchParamsIterator.prototype.next,
|
|
287
|
+
writable: true,
|
|
288
|
+
configurable: true,
|
|
289
|
+
enumerable: true,
|
|
290
|
+
},
|
|
291
|
+
[Symbol.iterator]: {
|
|
292
|
+
value: function iterator() {
|
|
293
|
+
assertUrlSearchParamsIteratorReceiver(this);
|
|
294
|
+
return this;
|
|
295
|
+
},
|
|
296
|
+
writable: true,
|
|
297
|
+
configurable: true,
|
|
298
|
+
enumerable: false,
|
|
299
|
+
},
|
|
300
|
+
[inspectCustomSymbol]: {
|
|
301
|
+
value: URLSearchParamsIterator.prototype[inspectCustomSymbol],
|
|
302
|
+
writable: true,
|
|
303
|
+
configurable: true,
|
|
304
|
+
enumerable: false,
|
|
305
|
+
},
|
|
306
|
+
[toStringTagSymbol]: {
|
|
307
|
+
get: Object.getOwnPropertyDescriptor(URLSearchParamsIterator.prototype, toStringTagSymbol)?.get,
|
|
308
|
+
configurable: true,
|
|
309
|
+
enumerable: false,
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
Object.defineProperty(Object.getOwnPropertyDescriptor(URLSearchParamsIterator.prototype, Symbol.iterator)?.value, "name", {
|
|
313
|
+
value: "entries",
|
|
314
|
+
configurable: true,
|
|
315
|
+
});
|
|
316
|
+
export class URLSearchParams {
|
|
317
|
+
constructor(init) {
|
|
318
|
+
searchParamsBrand.add(this);
|
|
319
|
+
const normalized = normalizeSearchParamsInit(init);
|
|
320
|
+
if (normalized &&
|
|
321
|
+
typeof normalized === "object" &&
|
|
322
|
+
kLinkedSearchParams in normalized) {
|
|
323
|
+
searchParamsState.set(this, {
|
|
324
|
+
getImpl: normalized[kLinkedSearchParams],
|
|
325
|
+
});
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const impl = createStandaloneSearchParams(normalized);
|
|
329
|
+
searchParamsState.set(this, { getImpl: () => impl });
|
|
330
|
+
}
|
|
331
|
+
append(name, value) {
|
|
332
|
+
assertUrlSearchParamsReceiver(this);
|
|
333
|
+
if (arguments.length < 2) {
|
|
334
|
+
throw createMissingArgsError('The "name" and "value" arguments must be specified');
|
|
335
|
+
}
|
|
336
|
+
getUrlSearchParamsImpl(this).append(toNodeUSVString(name), toNodeUSVString(value));
|
|
337
|
+
}
|
|
338
|
+
delete(name) {
|
|
339
|
+
assertUrlSearchParamsReceiver(this);
|
|
340
|
+
if (arguments.length < 1) {
|
|
341
|
+
throw createMissingArgsError('The "name" argument must be specified');
|
|
342
|
+
}
|
|
343
|
+
getUrlSearchParamsImpl(this).delete(toNodeUSVString(name));
|
|
344
|
+
}
|
|
345
|
+
get(name) {
|
|
346
|
+
assertUrlSearchParamsReceiver(this);
|
|
347
|
+
if (arguments.length < 1) {
|
|
348
|
+
throw createMissingArgsError('The "name" argument must be specified');
|
|
349
|
+
}
|
|
350
|
+
return getUrlSearchParamsImpl(this).get(toNodeUSVString(name));
|
|
351
|
+
}
|
|
352
|
+
getAll(name) {
|
|
353
|
+
assertUrlSearchParamsReceiver(this);
|
|
354
|
+
if (arguments.length < 1) {
|
|
355
|
+
throw createMissingArgsError('The "name" argument must be specified');
|
|
356
|
+
}
|
|
357
|
+
return getUrlSearchParamsImpl(this).getAll(toNodeUSVString(name));
|
|
358
|
+
}
|
|
359
|
+
has(name) {
|
|
360
|
+
assertUrlSearchParamsReceiver(this);
|
|
361
|
+
if (arguments.length < 1) {
|
|
362
|
+
throw createMissingArgsError('The "name" argument must be specified');
|
|
363
|
+
}
|
|
364
|
+
return getUrlSearchParamsImpl(this).has(toNodeUSVString(name));
|
|
365
|
+
}
|
|
366
|
+
set(name, value) {
|
|
367
|
+
assertUrlSearchParamsReceiver(this);
|
|
368
|
+
if (arguments.length < 2) {
|
|
369
|
+
throw createMissingArgsError('The "name" and "value" arguments must be specified');
|
|
370
|
+
}
|
|
371
|
+
getUrlSearchParamsImpl(this).set(toNodeUSVString(name), toNodeUSVString(value));
|
|
372
|
+
}
|
|
373
|
+
sort() {
|
|
374
|
+
assertUrlSearchParamsReceiver(this);
|
|
375
|
+
getUrlSearchParamsImpl(this).sort();
|
|
376
|
+
}
|
|
377
|
+
entries() {
|
|
378
|
+
assertUrlSearchParamsReceiver(this);
|
|
379
|
+
return new URLSearchParamsIterator(Array.from(getUrlSearchParamsImpl(this)));
|
|
380
|
+
}
|
|
381
|
+
keys() {
|
|
382
|
+
assertUrlSearchParamsReceiver(this);
|
|
383
|
+
return new URLSearchParamsIterator(Array.from(getUrlSearchParamsImpl(this).keys()));
|
|
384
|
+
}
|
|
385
|
+
values() {
|
|
386
|
+
assertUrlSearchParamsReceiver(this);
|
|
387
|
+
return new URLSearchParamsIterator(Array.from(getUrlSearchParamsImpl(this).values()));
|
|
388
|
+
}
|
|
389
|
+
forEach(callback, thisArg) {
|
|
390
|
+
assertUrlSearchParamsReceiver(this);
|
|
391
|
+
if (typeof callback !== "function") {
|
|
392
|
+
throw createNodeTypeError('The "callback" argument must be of type function. Received ' +
|
|
393
|
+
(callback === undefined ? "undefined" : typeof callback), "ERR_INVALID_ARG_TYPE");
|
|
394
|
+
}
|
|
395
|
+
for (const [key, value] of getUrlSearchParamsImpl(this)) {
|
|
396
|
+
callback.call(thisArg, value, key, this);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
toString() {
|
|
400
|
+
assertUrlSearchParamsReceiver(this);
|
|
401
|
+
return getUrlSearchParamsImpl(this).toString();
|
|
402
|
+
}
|
|
403
|
+
get size() {
|
|
404
|
+
assertUrlSearchParamsReceiver(this);
|
|
405
|
+
return countSearchParams(getUrlSearchParamsImpl(this));
|
|
406
|
+
}
|
|
407
|
+
[inspectCustomSymbol](depth, options, inspect) {
|
|
408
|
+
assertUrlSearchParamsReceiver(this);
|
|
409
|
+
if (depth < 0) {
|
|
410
|
+
return "[Object]";
|
|
411
|
+
}
|
|
412
|
+
const formatValue = typeof inspect === "function"
|
|
413
|
+
? (value) => inspect(value, options)
|
|
414
|
+
: (value) => JSON.stringify(value);
|
|
415
|
+
const items = Array.from(getUrlSearchParamsImpl(this)).map(([key, value]) => `${formatValue(key)} => ${formatValue(value)}`);
|
|
416
|
+
return `URLSearchParams ${createCollectionBody(items, options, "{}")}`;
|
|
417
|
+
}
|
|
418
|
+
get [toStringTagSymbol]() {
|
|
419
|
+
if (this !== URLSearchParams.prototype) {
|
|
420
|
+
assertUrlSearchParamsReceiver(this);
|
|
421
|
+
}
|
|
422
|
+
return URL_SEARCH_PARAMS_TYPE;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
for (const name of SEARCH_PARAM_METHOD_NAMES) {
|
|
426
|
+
Object.defineProperty(URLSearchParams.prototype, name, {
|
|
427
|
+
value: URLSearchParams.prototype[name],
|
|
428
|
+
writable: true,
|
|
429
|
+
configurable: true,
|
|
430
|
+
enumerable: true,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
for (const name of SEARCH_PARAM_PAIR_METHOD_NAMES) {
|
|
434
|
+
Object.defineProperty(URLSearchParams.prototype, name, {
|
|
435
|
+
value: URLSearchParams.prototype[name],
|
|
436
|
+
writable: true,
|
|
437
|
+
configurable: true,
|
|
438
|
+
enumerable: true,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
for (const name of ["sort", "entries", "forEach", "keys", "values", "toString"]) {
|
|
442
|
+
Object.defineProperty(URLSearchParams.prototype, name, {
|
|
443
|
+
value: URLSearchParams.prototype[name],
|
|
444
|
+
writable: true,
|
|
445
|
+
configurable: true,
|
|
446
|
+
enumerable: true,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
Object.defineProperties(URLSearchParams.prototype, {
|
|
450
|
+
size: {
|
|
451
|
+
get: Object.getOwnPropertyDescriptor(URLSearchParams.prototype, "size")?.get,
|
|
452
|
+
configurable: true,
|
|
453
|
+
enumerable: true,
|
|
454
|
+
},
|
|
455
|
+
[Symbol.iterator]: {
|
|
456
|
+
value: URLSearchParams.prototype.entries,
|
|
457
|
+
writable: true,
|
|
458
|
+
configurable: true,
|
|
459
|
+
enumerable: false,
|
|
460
|
+
},
|
|
461
|
+
[inspectCustomSymbol]: {
|
|
462
|
+
value: URLSearchParams.prototype[inspectCustomSymbol],
|
|
463
|
+
writable: true,
|
|
464
|
+
configurable: true,
|
|
465
|
+
enumerable: false,
|
|
466
|
+
},
|
|
467
|
+
[toStringTagSymbol]: {
|
|
468
|
+
get: Object.getOwnPropertyDescriptor(URLSearchParams.prototype, toStringTagSymbol)?.get,
|
|
469
|
+
configurable: true,
|
|
470
|
+
enumerable: false,
|
|
471
|
+
},
|
|
472
|
+
});
|
|
473
|
+
export class URL {
|
|
474
|
+
#impl;
|
|
475
|
+
#searchParams;
|
|
476
|
+
constructor(input, base) {
|
|
477
|
+
if (arguments.length < 1) {
|
|
478
|
+
throw createMissingArgsError('The "url" argument must be specified');
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
this.#impl =
|
|
482
|
+
arguments.length >= 2
|
|
483
|
+
? new WhatwgURL(toNodeUSVString(input), toNodeUSVString(base))
|
|
484
|
+
: new WhatwgURL(toNodeUSVString(input));
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
throw createInvalidUrlError();
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
static canParse(input, base) {
|
|
491
|
+
if (arguments.length < 1) {
|
|
492
|
+
throw createMissingArgsError('The "url" argument must be specified');
|
|
493
|
+
}
|
|
494
|
+
try {
|
|
495
|
+
if (arguments.length >= 2) {
|
|
496
|
+
new URL(input, base);
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
new URL(input);
|
|
500
|
+
}
|
|
501
|
+
return true;
|
|
502
|
+
}
|
|
503
|
+
catch {
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
static createObjectURL(obj) {
|
|
508
|
+
if (typeof Blob === "undefined" ||
|
|
509
|
+
!(obj instanceof Blob)) {
|
|
510
|
+
throw createNodeTypeError('The "obj" argument must be an instance of Blob. Received ' +
|
|
511
|
+
(obj === null ? "null" : typeof obj), "ERR_INVALID_ARG_TYPE");
|
|
512
|
+
}
|
|
513
|
+
const id = `blob:nodedata:${nextBlobUrlId()}`;
|
|
514
|
+
getBlobUrlStore().set(id, obj);
|
|
515
|
+
return id;
|
|
516
|
+
}
|
|
517
|
+
static revokeObjectURL(url) {
|
|
518
|
+
if (arguments.length < 1) {
|
|
519
|
+
throw createMissingArgsError('The "url" argument must be specified');
|
|
520
|
+
}
|
|
521
|
+
if (typeof url !== "string") {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
getBlobUrlStore().delete(url);
|
|
525
|
+
}
|
|
526
|
+
get href() {
|
|
527
|
+
if (!(this instanceof URL)) {
|
|
528
|
+
throw createUrlReceiverTypeError();
|
|
529
|
+
}
|
|
530
|
+
return this.#impl.href;
|
|
531
|
+
}
|
|
532
|
+
set href(value) {
|
|
533
|
+
this.#impl.href = toNodeUSVString(value);
|
|
534
|
+
}
|
|
535
|
+
get origin() {
|
|
536
|
+
return this.#impl.origin;
|
|
537
|
+
}
|
|
538
|
+
get protocol() {
|
|
539
|
+
return this.#impl.protocol;
|
|
540
|
+
}
|
|
541
|
+
set protocol(value) {
|
|
542
|
+
this.#impl.protocol = toNodeUSVString(value);
|
|
543
|
+
}
|
|
544
|
+
get username() {
|
|
545
|
+
return this.#impl.username;
|
|
546
|
+
}
|
|
547
|
+
set username(value) {
|
|
548
|
+
this.#impl.username = toNodeUSVString(value);
|
|
549
|
+
}
|
|
550
|
+
get password() {
|
|
551
|
+
return this.#impl.password;
|
|
552
|
+
}
|
|
553
|
+
set password(value) {
|
|
554
|
+
this.#impl.password = toNodeUSVString(value);
|
|
555
|
+
}
|
|
556
|
+
get host() {
|
|
557
|
+
return this.#impl.host;
|
|
558
|
+
}
|
|
559
|
+
set host(value) {
|
|
560
|
+
this.#impl.host = toNodeUSVString(value);
|
|
561
|
+
}
|
|
562
|
+
get hostname() {
|
|
563
|
+
return this.#impl.hostname;
|
|
564
|
+
}
|
|
565
|
+
set hostname(value) {
|
|
566
|
+
this.#impl.hostname = toNodeUSVString(value);
|
|
567
|
+
}
|
|
568
|
+
get port() {
|
|
569
|
+
return this.#impl.port;
|
|
570
|
+
}
|
|
571
|
+
set port(value) {
|
|
572
|
+
this.#impl.port = toNodeUSVString(value);
|
|
573
|
+
}
|
|
574
|
+
get pathname() {
|
|
575
|
+
return this.#impl.pathname;
|
|
576
|
+
}
|
|
577
|
+
set pathname(value) {
|
|
578
|
+
this.#impl.pathname = toNodeUSVString(value);
|
|
579
|
+
}
|
|
580
|
+
get search() {
|
|
581
|
+
if (!(this instanceof URL)) {
|
|
582
|
+
throw createUrlReceiverTypeError();
|
|
583
|
+
}
|
|
584
|
+
return this.#impl.search;
|
|
585
|
+
}
|
|
586
|
+
set search(value) {
|
|
587
|
+
this.#impl.search = toNodeUSVString(value);
|
|
588
|
+
}
|
|
589
|
+
get searchParams() {
|
|
590
|
+
if (!this.#searchParams) {
|
|
591
|
+
this.#searchParams = new URLSearchParams({
|
|
592
|
+
[kLinkedSearchParams]: () => this.#impl.searchParams,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
return this.#searchParams;
|
|
596
|
+
}
|
|
597
|
+
get hash() {
|
|
598
|
+
return this.#impl.hash;
|
|
599
|
+
}
|
|
600
|
+
set hash(value) {
|
|
601
|
+
this.#impl.hash = toNodeUSVString(value);
|
|
602
|
+
}
|
|
603
|
+
toString() {
|
|
604
|
+
if (!(this instanceof URL)) {
|
|
605
|
+
throw createUrlReceiverTypeError();
|
|
606
|
+
}
|
|
607
|
+
return this.#impl.href;
|
|
608
|
+
}
|
|
609
|
+
toJSON() {
|
|
610
|
+
if (!(this instanceof URL)) {
|
|
611
|
+
throw createUrlReceiverTypeError();
|
|
612
|
+
}
|
|
613
|
+
return this.#impl.href;
|
|
614
|
+
}
|
|
615
|
+
[inspectCustomSymbol](depth, options, inspect) {
|
|
616
|
+
const inspectName = this.constructor === URL ? "URL" : this.constructor.name;
|
|
617
|
+
if (depth < 0) {
|
|
618
|
+
return `${inspectName} {}`;
|
|
619
|
+
}
|
|
620
|
+
const formatValue = typeof inspect === "function"
|
|
621
|
+
? (value) => inspect(value, options)
|
|
622
|
+
: (value) => JSON.stringify(value);
|
|
623
|
+
const lines = [
|
|
624
|
+
`${inspectName} {`,
|
|
625
|
+
` href: ${formatValue(this.href)},`,
|
|
626
|
+
` origin: ${formatValue(this.origin)},`,
|
|
627
|
+
` protocol: ${formatValue(this.protocol)},`,
|
|
628
|
+
` username: ${formatValue(this.username)},`,
|
|
629
|
+
` password: ${formatValue(this.password)},`,
|
|
630
|
+
` host: ${formatValue(this.host)},`,
|
|
631
|
+
` hostname: ${formatValue(this.hostname)},`,
|
|
632
|
+
` port: ${formatValue(this.port)},`,
|
|
633
|
+
` pathname: ${formatValue(this.pathname)},`,
|
|
634
|
+
` search: ${formatValue(this.search)},`,
|
|
635
|
+
` searchParams: ${this.searchParams[inspectCustomSymbol](depth - 1, undefined, inspect)},`,
|
|
636
|
+
` hash: ${formatValue(this.hash)}`,
|
|
637
|
+
];
|
|
638
|
+
if (options?.showHidden) {
|
|
639
|
+
lines[lines.length - 1] += ",";
|
|
640
|
+
lines.push(` [Symbol(context)]: ${formatUrlContext(this, inspect, options)}`);
|
|
641
|
+
}
|
|
642
|
+
lines.push("}");
|
|
643
|
+
return lines.join("\n");
|
|
644
|
+
}
|
|
645
|
+
get [toStringTagSymbol]() {
|
|
646
|
+
return "URL";
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
for (const name of ["toString", "toJSON"]) {
|
|
650
|
+
Object.defineProperty(URL.prototype, name, {
|
|
651
|
+
value: URL.prototype[name],
|
|
652
|
+
writable: true,
|
|
653
|
+
configurable: true,
|
|
654
|
+
enumerable: true,
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
for (const name of [
|
|
658
|
+
"href",
|
|
659
|
+
"protocol",
|
|
660
|
+
"username",
|
|
661
|
+
"password",
|
|
662
|
+
"host",
|
|
663
|
+
"hostname",
|
|
664
|
+
"port",
|
|
665
|
+
"pathname",
|
|
666
|
+
"search",
|
|
667
|
+
"hash",
|
|
668
|
+
"origin",
|
|
669
|
+
"searchParams",
|
|
670
|
+
]) {
|
|
671
|
+
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, name);
|
|
672
|
+
if (!descriptor) {
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
descriptor.enumerable = true;
|
|
676
|
+
Object.defineProperty(URL.prototype, name, descriptor);
|
|
677
|
+
}
|
|
678
|
+
Object.defineProperties(URL.prototype, {
|
|
679
|
+
[inspectCustomSymbol]: {
|
|
680
|
+
value: URL.prototype[inspectCustomSymbol],
|
|
681
|
+
writable: true,
|
|
682
|
+
configurable: true,
|
|
683
|
+
enumerable: false,
|
|
684
|
+
},
|
|
685
|
+
[toStringTagSymbol]: {
|
|
686
|
+
get: Object.getOwnPropertyDescriptor(URL.prototype, toStringTagSymbol)?.get,
|
|
687
|
+
configurable: true,
|
|
688
|
+
enumerable: false,
|
|
689
|
+
},
|
|
690
|
+
});
|
|
691
|
+
for (const name of ["canParse", "createObjectURL", "revokeObjectURL"]) {
|
|
692
|
+
Object.defineProperty(URL, name, {
|
|
693
|
+
value: URL[name],
|
|
694
|
+
writable: true,
|
|
695
|
+
configurable: true,
|
|
696
|
+
enumerable: true,
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
export function installWhatwgUrlGlobals(target = globalThis) {
|
|
700
|
+
Object.defineProperty(target, "URL", {
|
|
701
|
+
value: URL,
|
|
702
|
+
writable: true,
|
|
703
|
+
configurable: true,
|
|
704
|
+
enumerable: false,
|
|
705
|
+
});
|
|
706
|
+
Object.defineProperty(target, "URLSearchParams", {
|
|
707
|
+
value: URLSearchParams,
|
|
708
|
+
writable: true,
|
|
709
|
+
configurable: true,
|
|
710
|
+
enumerable: false,
|
|
711
|
+
});
|
|
712
|
+
}
|