@depup/whatwg-url 16.0.1-depup.0

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.
@@ -0,0 +1,505 @@
1
+ "use strict";
2
+
3
+ const conversions = require("webidl-conversions");
4
+ const utils = require("./utils.js");
5
+
6
+ const Function = require("./Function.js");
7
+ const newObjectInRealm = utils.newObjectInRealm;
8
+ const implSymbol = utils.implSymbol;
9
+ const ctorRegistrySymbol = utils.ctorRegistrySymbol;
10
+
11
+ const interfaceName = "URLSearchParams";
12
+
13
+ exports.is = value => {
14
+ return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
15
+ };
16
+ exports.isImpl = value => {
17
+ return utils.isObject(value) && value instanceof Impl.implementation;
18
+ };
19
+ exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
20
+ if (exports.is(value)) {
21
+ return utils.implForWrapper(value);
22
+ }
23
+ throw new globalObject.TypeError(`${context} is not of type 'URLSearchParams'.`);
24
+ };
25
+
26
+ exports.createDefaultIterator = (globalObject, target, kind) => {
27
+ const ctorRegistry = globalObject[ctorRegistrySymbol];
28
+ const iteratorPrototype = ctorRegistry["URLSearchParams Iterator"];
29
+ const iterator = Object.create(iteratorPrototype);
30
+ Object.defineProperty(iterator, utils.iterInternalSymbol, {
31
+ value: { target, kind, index: 0 },
32
+ configurable: true
33
+ });
34
+ return iterator;
35
+ };
36
+
37
+ function makeWrapper(globalObject, newTarget) {
38
+ let proto;
39
+ if (newTarget !== undefined) {
40
+ proto = newTarget.prototype;
41
+ }
42
+
43
+ if (!utils.isObject(proto)) {
44
+ proto = globalObject[ctorRegistrySymbol]["URLSearchParams"].prototype;
45
+ }
46
+
47
+ return Object.create(proto);
48
+ }
49
+
50
+ exports.create = (globalObject, constructorArgs, privateData) => {
51
+ const wrapper = makeWrapper(globalObject);
52
+ return exports.setup(wrapper, globalObject, constructorArgs, privateData);
53
+ };
54
+
55
+ exports.createImpl = (globalObject, constructorArgs, privateData) => {
56
+ const wrapper = exports.create(globalObject, constructorArgs, privateData);
57
+ return utils.implForWrapper(wrapper);
58
+ };
59
+
60
+ exports._internalSetup = (wrapper, globalObject) => {};
61
+
62
+ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
63
+ privateData.wrapper = wrapper;
64
+
65
+ exports._internalSetup(wrapper, globalObject);
66
+ Object.defineProperty(wrapper, implSymbol, {
67
+ value: new Impl.implementation(globalObject, constructorArgs, privateData),
68
+ configurable: true
69
+ });
70
+
71
+ wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
72
+ if (Impl.init) {
73
+ Impl.init(wrapper[implSymbol]);
74
+ }
75
+ return wrapper;
76
+ };
77
+
78
+ exports.new = (globalObject, newTarget) => {
79
+ const wrapper = makeWrapper(globalObject, newTarget);
80
+
81
+ exports._internalSetup(wrapper, globalObject);
82
+ Object.defineProperty(wrapper, implSymbol, {
83
+ value: Object.create(Impl.implementation.prototype),
84
+ configurable: true
85
+ });
86
+
87
+ wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
88
+ if (Impl.init) {
89
+ Impl.init(wrapper[implSymbol]);
90
+ }
91
+ return wrapper[implSymbol];
92
+ };
93
+
94
+ const exposed = new Set(["Window", "Worker"]);
95
+
96
+ exports.install = (globalObject, globalNames) => {
97
+ if (!globalNames.some(globalName => exposed.has(globalName))) {
98
+ return;
99
+ }
100
+
101
+ const ctorRegistry = utils.initCtorRegistry(globalObject);
102
+ class URLSearchParams {
103
+ constructor() {
104
+ const args = [];
105
+ {
106
+ let curArg = arguments[0];
107
+ if (curArg !== undefined) {
108
+ if (utils.isObject(curArg)) {
109
+ if (curArg[Symbol.iterator] !== undefined) {
110
+ if (!utils.isObject(curArg)) {
111
+ throw new globalObject.TypeError(
112
+ "Failed to construct 'URLSearchParams': parameter 1" + " sequence" + " is not an iterable object."
113
+ );
114
+ } else {
115
+ const V = [];
116
+ const tmp = curArg;
117
+ for (let nextItem of tmp) {
118
+ if (!utils.isObject(nextItem)) {
119
+ throw new globalObject.TypeError(
120
+ "Failed to construct 'URLSearchParams': parameter 1" +
121
+ " sequence" +
122
+ "'s element" +
123
+ " is not an iterable object."
124
+ );
125
+ } else {
126
+ const V = [];
127
+ const tmp = nextItem;
128
+ for (let nextItem of tmp) {
129
+ nextItem = conversions["USVString"](nextItem, {
130
+ context:
131
+ "Failed to construct 'URLSearchParams': parameter 1" +
132
+ " sequence" +
133
+ "'s element" +
134
+ "'s element",
135
+ globals: globalObject
136
+ });
137
+
138
+ V.push(nextItem);
139
+ }
140
+ nextItem = V;
141
+ }
142
+
143
+ V.push(nextItem);
144
+ }
145
+ curArg = V;
146
+ }
147
+ } else {
148
+ if (!utils.isObject(curArg)) {
149
+ throw new globalObject.TypeError(
150
+ "Failed to construct 'URLSearchParams': parameter 1" + " record" + " is not an object."
151
+ );
152
+ } else {
153
+ const result = Object.create(null);
154
+ for (const key of Reflect.ownKeys(curArg)) {
155
+ const desc = Object.getOwnPropertyDescriptor(curArg, key);
156
+ if (desc && desc.enumerable) {
157
+ let typedKey = key;
158
+
159
+ typedKey = conversions["USVString"](typedKey, {
160
+ context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s key",
161
+ globals: globalObject
162
+ });
163
+
164
+ let typedValue = curArg[key];
165
+
166
+ typedValue = conversions["USVString"](typedValue, {
167
+ context: "Failed to construct 'URLSearchParams': parameter 1" + " record" + "'s value",
168
+ globals: globalObject
169
+ });
170
+
171
+ result[typedKey] = typedValue;
172
+ }
173
+ }
174
+ curArg = result;
175
+ }
176
+ }
177
+ } else {
178
+ curArg = conversions["USVString"](curArg, {
179
+ context: "Failed to construct 'URLSearchParams': parameter 1",
180
+ globals: globalObject
181
+ });
182
+ }
183
+ } else {
184
+ curArg = "";
185
+ }
186
+ args.push(curArg);
187
+ }
188
+ return exports.setup(Object.create(new.target.prototype), globalObject, args);
189
+ }
190
+
191
+ append(name, value) {
192
+ const esValue = this !== null && this !== undefined ? this : globalObject;
193
+ if (!exports.is(esValue)) {
194
+ throw new globalObject.TypeError(
195
+ "'append' called on an object that is not a valid instance of URLSearchParams."
196
+ );
197
+ }
198
+
199
+ if (arguments.length < 2) {
200
+ throw new globalObject.TypeError(
201
+ `Failed to execute 'append' on 'URLSearchParams': 2 arguments required, but only ${arguments.length} present.`
202
+ );
203
+ }
204
+ const args = [];
205
+ {
206
+ let curArg = arguments[0];
207
+ curArg = conversions["USVString"](curArg, {
208
+ context: "Failed to execute 'append' on 'URLSearchParams': parameter 1",
209
+ globals: globalObject
210
+ });
211
+ args.push(curArg);
212
+ }
213
+ {
214
+ let curArg = arguments[1];
215
+ curArg = conversions["USVString"](curArg, {
216
+ context: "Failed to execute 'append' on 'URLSearchParams': parameter 2",
217
+ globals: globalObject
218
+ });
219
+ args.push(curArg);
220
+ }
221
+ return utils.tryWrapperForImpl(esValue[implSymbol].append(...args));
222
+ }
223
+
224
+ delete(name) {
225
+ const esValue = this !== null && this !== undefined ? this : globalObject;
226
+ if (!exports.is(esValue)) {
227
+ throw new globalObject.TypeError(
228
+ "'delete' called on an object that is not a valid instance of URLSearchParams."
229
+ );
230
+ }
231
+
232
+ if (arguments.length < 1) {
233
+ throw new globalObject.TypeError(
234
+ `Failed to execute 'delete' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
235
+ );
236
+ }
237
+ const args = [];
238
+ {
239
+ let curArg = arguments[0];
240
+ curArg = conversions["USVString"](curArg, {
241
+ context: "Failed to execute 'delete' on 'URLSearchParams': parameter 1",
242
+ globals: globalObject
243
+ });
244
+ args.push(curArg);
245
+ }
246
+ {
247
+ let curArg = arguments[1];
248
+ if (curArg !== undefined) {
249
+ curArg = conversions["USVString"](curArg, {
250
+ context: "Failed to execute 'delete' on 'URLSearchParams': parameter 2",
251
+ globals: globalObject
252
+ });
253
+ }
254
+ args.push(curArg);
255
+ }
256
+ return utils.tryWrapperForImpl(esValue[implSymbol].delete(...args));
257
+ }
258
+
259
+ get(name) {
260
+ const esValue = this !== null && this !== undefined ? this : globalObject;
261
+ if (!exports.is(esValue)) {
262
+ throw new globalObject.TypeError("'get' called on an object that is not a valid instance of URLSearchParams.");
263
+ }
264
+
265
+ if (arguments.length < 1) {
266
+ throw new globalObject.TypeError(
267
+ `Failed to execute 'get' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
268
+ );
269
+ }
270
+ const args = [];
271
+ {
272
+ let curArg = arguments[0];
273
+ curArg = conversions["USVString"](curArg, {
274
+ context: "Failed to execute 'get' on 'URLSearchParams': parameter 1",
275
+ globals: globalObject
276
+ });
277
+ args.push(curArg);
278
+ }
279
+ return esValue[implSymbol].get(...args);
280
+ }
281
+
282
+ getAll(name) {
283
+ const esValue = this !== null && this !== undefined ? this : globalObject;
284
+ if (!exports.is(esValue)) {
285
+ throw new globalObject.TypeError(
286
+ "'getAll' called on an object that is not a valid instance of URLSearchParams."
287
+ );
288
+ }
289
+
290
+ if (arguments.length < 1) {
291
+ throw new globalObject.TypeError(
292
+ `Failed to execute 'getAll' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
293
+ );
294
+ }
295
+ const args = [];
296
+ {
297
+ let curArg = arguments[0];
298
+ curArg = conversions["USVString"](curArg, {
299
+ context: "Failed to execute 'getAll' on 'URLSearchParams': parameter 1",
300
+ globals: globalObject
301
+ });
302
+ args.push(curArg);
303
+ }
304
+ return utils.tryWrapperForImpl(esValue[implSymbol].getAll(...args));
305
+ }
306
+
307
+ has(name) {
308
+ const esValue = this !== null && this !== undefined ? this : globalObject;
309
+ if (!exports.is(esValue)) {
310
+ throw new globalObject.TypeError("'has' called on an object that is not a valid instance of URLSearchParams.");
311
+ }
312
+
313
+ if (arguments.length < 1) {
314
+ throw new globalObject.TypeError(
315
+ `Failed to execute 'has' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
316
+ );
317
+ }
318
+ const args = [];
319
+ {
320
+ let curArg = arguments[0];
321
+ curArg = conversions["USVString"](curArg, {
322
+ context: "Failed to execute 'has' on 'URLSearchParams': parameter 1",
323
+ globals: globalObject
324
+ });
325
+ args.push(curArg);
326
+ }
327
+ {
328
+ let curArg = arguments[1];
329
+ if (curArg !== undefined) {
330
+ curArg = conversions["USVString"](curArg, {
331
+ context: "Failed to execute 'has' on 'URLSearchParams': parameter 2",
332
+ globals: globalObject
333
+ });
334
+ }
335
+ args.push(curArg);
336
+ }
337
+ return esValue[implSymbol].has(...args);
338
+ }
339
+
340
+ set(name, value) {
341
+ const esValue = this !== null && this !== undefined ? this : globalObject;
342
+ if (!exports.is(esValue)) {
343
+ throw new globalObject.TypeError("'set' called on an object that is not a valid instance of URLSearchParams.");
344
+ }
345
+
346
+ if (arguments.length < 2) {
347
+ throw new globalObject.TypeError(
348
+ `Failed to execute 'set' on 'URLSearchParams': 2 arguments required, but only ${arguments.length} present.`
349
+ );
350
+ }
351
+ const args = [];
352
+ {
353
+ let curArg = arguments[0];
354
+ curArg = conversions["USVString"](curArg, {
355
+ context: "Failed to execute 'set' on 'URLSearchParams': parameter 1",
356
+ globals: globalObject
357
+ });
358
+ args.push(curArg);
359
+ }
360
+ {
361
+ let curArg = arguments[1];
362
+ curArg = conversions["USVString"](curArg, {
363
+ context: "Failed to execute 'set' on 'URLSearchParams': parameter 2",
364
+ globals: globalObject
365
+ });
366
+ args.push(curArg);
367
+ }
368
+ return utils.tryWrapperForImpl(esValue[implSymbol].set(...args));
369
+ }
370
+
371
+ sort() {
372
+ const esValue = this !== null && this !== undefined ? this : globalObject;
373
+ if (!exports.is(esValue)) {
374
+ throw new globalObject.TypeError("'sort' called on an object that is not a valid instance of URLSearchParams.");
375
+ }
376
+
377
+ return utils.tryWrapperForImpl(esValue[implSymbol].sort());
378
+ }
379
+
380
+ toString() {
381
+ const esValue = this !== null && this !== undefined ? this : globalObject;
382
+ if (!exports.is(esValue)) {
383
+ throw new globalObject.TypeError(
384
+ "'toString' called on an object that is not a valid instance of URLSearchParams."
385
+ );
386
+ }
387
+
388
+ return esValue[implSymbol].toString();
389
+ }
390
+
391
+ keys() {
392
+ if (!exports.is(this)) {
393
+ throw new globalObject.TypeError("'keys' called on an object that is not a valid instance of URLSearchParams.");
394
+ }
395
+ return exports.createDefaultIterator(globalObject, this, "key");
396
+ }
397
+
398
+ values() {
399
+ if (!exports.is(this)) {
400
+ throw new globalObject.TypeError(
401
+ "'values' called on an object that is not a valid instance of URLSearchParams."
402
+ );
403
+ }
404
+ return exports.createDefaultIterator(globalObject, this, "value");
405
+ }
406
+
407
+ entries() {
408
+ if (!exports.is(this)) {
409
+ throw new globalObject.TypeError(
410
+ "'entries' called on an object that is not a valid instance of URLSearchParams."
411
+ );
412
+ }
413
+ return exports.createDefaultIterator(globalObject, this, "key+value");
414
+ }
415
+
416
+ forEach(callback) {
417
+ if (!exports.is(this)) {
418
+ throw new globalObject.TypeError(
419
+ "'forEach' called on an object that is not a valid instance of URLSearchParams."
420
+ );
421
+ }
422
+ if (arguments.length < 1) {
423
+ throw new globalObject.TypeError(
424
+ "Failed to execute 'forEach' on 'iterable': 1 argument required, but only 0 present."
425
+ );
426
+ }
427
+ callback = Function.convert(globalObject, callback, {
428
+ context: "Failed to execute 'forEach' on 'iterable': The callback provided as parameter 1"
429
+ });
430
+ const thisArg = arguments[1];
431
+ let pairs = Array.from(this[implSymbol]);
432
+ let i = 0;
433
+ while (i < pairs.length) {
434
+ const [key, value] = pairs[i].map(utils.tryWrapperForImpl);
435
+ callback.call(thisArg, value, key, this);
436
+ pairs = Array.from(this[implSymbol]);
437
+ i++;
438
+ }
439
+ }
440
+
441
+ get size() {
442
+ const esValue = this !== null && this !== undefined ? this : globalObject;
443
+
444
+ if (!exports.is(esValue)) {
445
+ throw new globalObject.TypeError(
446
+ "'get size' called on an object that is not a valid instance of URLSearchParams."
447
+ );
448
+ }
449
+
450
+ return esValue[implSymbol]["size"];
451
+ }
452
+ }
453
+ Object.defineProperties(URLSearchParams.prototype, {
454
+ append: { enumerable: true },
455
+ delete: { enumerable: true },
456
+ get: { enumerable: true },
457
+ getAll: { enumerable: true },
458
+ has: { enumerable: true },
459
+ set: { enumerable: true },
460
+ sort: { enumerable: true },
461
+ toString: { enumerable: true },
462
+ keys: { enumerable: true },
463
+ values: { enumerable: true },
464
+ entries: { enumerable: true },
465
+ forEach: { enumerable: true },
466
+ size: { enumerable: true },
467
+ [Symbol.toStringTag]: { value: "URLSearchParams", configurable: true },
468
+ [Symbol.iterator]: { value: URLSearchParams.prototype.entries, configurable: true, writable: true }
469
+ });
470
+ ctorRegistry[interfaceName] = URLSearchParams;
471
+
472
+ ctorRegistry["URLSearchParams Iterator"] = Object.create(ctorRegistry["%IteratorPrototype%"], {
473
+ [Symbol.toStringTag]: {
474
+ configurable: true,
475
+ value: "URLSearchParams Iterator"
476
+ }
477
+ });
478
+ utils.define(ctorRegistry["URLSearchParams Iterator"], {
479
+ next() {
480
+ const internal = this && this[utils.iterInternalSymbol];
481
+ if (!internal) {
482
+ throw new globalObject.TypeError("next() called on a value that is not a URLSearchParams iterator object");
483
+ }
484
+
485
+ const { target, kind, index } = internal;
486
+ const values = Array.from(target[implSymbol]);
487
+ const len = values.length;
488
+ if (index >= len) {
489
+ return newObjectInRealm(globalObject, { value: undefined, done: true });
490
+ }
491
+
492
+ const pair = values[index];
493
+ internal.index = index + 1;
494
+ return newObjectInRealm(globalObject, utils.iteratorResult(pair.map(utils.tryWrapperForImpl), kind));
495
+ }
496
+ });
497
+
498
+ Object.defineProperty(globalObject, interfaceName, {
499
+ configurable: true,
500
+ writable: true,
501
+ value: URLSearchParams
502
+ });
503
+ };
504
+
505
+ const Impl = require("./URLSearchParams-impl.js");
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ const conversions = require("webidl-conversions");
4
+ const utils = require("./utils.js");
5
+
6
+ exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
7
+ if (typeof value !== "function") {
8
+ throw new globalObject.TypeError(context + " is not a function");
9
+ }
10
+
11
+ function invokeTheCallbackFunction() {
12
+ const thisArg = utils.tryWrapperForImpl(this);
13
+ let callResult;
14
+
15
+ callResult = Reflect.apply(value, thisArg, []);
16
+ }
17
+
18
+ invokeTheCallbackFunction.construct = () => {
19
+ let callResult = Reflect.construct(value, []);
20
+ };
21
+
22
+ invokeTheCallbackFunction[utils.wrapperSymbol] = value;
23
+ invokeTheCallbackFunction.objectReference = value;
24
+
25
+ return invokeTheCallbackFunction;
26
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ const utf8Encoder = new TextEncoder();
3
+ const utf8Decoder = new TextDecoder("utf-8", { ignoreBOM: true });
4
+
5
+ function utf8Encode(string) {
6
+ return utf8Encoder.encode(string);
7
+ }
8
+
9
+ function utf8DecodeWithoutBOM(bytes) {
10
+ return utf8Decoder.decode(bytes);
11
+ }
12
+
13
+ module.exports = {
14
+ utf8Encode,
15
+ utf8DecodeWithoutBOM
16
+ };
package/lib/infra.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ // Note that we take code points as JS numbers, not JS strings.
4
+
5
+ function isASCIIDigit(c) {
6
+ return c >= 0x30 && c <= 0x39;
7
+ }
8
+
9
+ function isASCIIAlpha(c) {
10
+ return (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A);
11
+ }
12
+
13
+ function isASCIIAlphanumeric(c) {
14
+ return isASCIIAlpha(c) || isASCIIDigit(c);
15
+ }
16
+
17
+ function isASCIIHex(c) {
18
+ return isASCIIDigit(c) || (c >= 0x41 && c <= 0x46) || (c >= 0x61 && c <= 0x66);
19
+ }
20
+
21
+ module.exports = {
22
+ isASCIIDigit,
23
+ isASCIIAlpha,
24
+ isASCIIAlphanumeric,
25
+ isASCIIHex
26
+ };