seroval 0.5.1 → 0.7.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.
- package/README.md +51 -1
- package/dist/cjs/development/index.cjs +762 -228
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +762 -228
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/compat.d.ts +3 -2
- package/dist/types/context.d.ts +14 -9
- package/dist/types/index.d.ts +9 -9
- package/dist/types/string.d.ts +3 -0
- package/dist/types/tree/async.d.ts +1 -2
- package/dist/types/tree/deserialize.d.ts +1 -2
- package/dist/types/tree/primitives.d.ts +7 -3
- package/dist/types/tree/reference.d.ts +6 -0
- package/dist/types/tree/sync.d.ts +1 -2
- package/dist/types/tree/types.d.ts +73 -12
- package/dist/types/tree/web-api.d.ts +6 -0
- package/dist/types/types.d.ts +2 -1
- package/package.json +4 -3
- package/src/compat.ts +2 -1
- package/src/context.ts +19 -12
- package/src/index.ts +10 -16
- package/src/{quote.ts → string.ts} +27 -30
- package/src/tree/async.ts +164 -62
- package/src/tree/deserialize.ts +195 -67
- package/src/tree/primitives.ts +108 -22
- package/src/tree/reference.ts +61 -0
- package/src/tree/serialize.ts +236 -59
- package/src/tree/sync.ts +160 -55
- package/src/tree/types.ts +139 -14
- package/src/tree/web-api.ts +92 -0
- package/src/types.ts +6 -1
- package/dist/types/quote.d.ts +0 -2
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Feature: () => Feature,
|
|
24
24
|
compileJSON: () => compileJSON,
|
|
25
|
+
createReference: () => createReference,
|
|
25
26
|
default: () => src_default,
|
|
26
27
|
deserialize: () => deserialize,
|
|
27
28
|
fromJSON: () => fromJSON,
|
|
@@ -47,9 +48,10 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
|
|
|
47
48
|
Feature2[Feature2["Symbol"] = 1024] = "Symbol";
|
|
48
49
|
Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
|
|
49
50
|
Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
|
|
51
|
+
Feature2[Feature2["WebAPI"] = 8192] = "WebAPI";
|
|
50
52
|
return Feature2;
|
|
51
53
|
})(Feature || {});
|
|
52
|
-
var ALL_ENABLED =
|
|
54
|
+
var ALL_ENABLED = 16383;
|
|
53
55
|
|
|
54
56
|
// src/get-identifier.ts
|
|
55
57
|
var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
|
|
@@ -115,7 +117,7 @@ function getRootID(ctx, current) {
|
|
|
115
117
|
}
|
|
116
118
|
return ref;
|
|
117
119
|
}
|
|
118
|
-
function
|
|
120
|
+
function createIndexedValue(ctx, current) {
|
|
119
121
|
const ref = ctx.refs.get(current);
|
|
120
122
|
if (ref == null) {
|
|
121
123
|
const id = ctx.refs.size;
|
|
@@ -133,39 +135,43 @@ function assert(cond, error) {
|
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
|
|
136
|
-
// src/
|
|
137
|
-
function
|
|
138
|
+
// src/string.ts
|
|
139
|
+
function serializeChar(str) {
|
|
140
|
+
switch (str) {
|
|
141
|
+
case '"':
|
|
142
|
+
return '\\"';
|
|
143
|
+
case "\\":
|
|
144
|
+
return "\\\\";
|
|
145
|
+
case "\n":
|
|
146
|
+
return "\\n";
|
|
147
|
+
case "\r":
|
|
148
|
+
return "\\r";
|
|
149
|
+
case "\b":
|
|
150
|
+
return "\\b";
|
|
151
|
+
case " ":
|
|
152
|
+
return "\\t";
|
|
153
|
+
case "\f":
|
|
154
|
+
return "\\f";
|
|
155
|
+
case "<":
|
|
156
|
+
return "\\x3C";
|
|
157
|
+
case "\u2028":
|
|
158
|
+
return "\\u2028";
|
|
159
|
+
case "\u2029":
|
|
160
|
+
return "\\u2029";
|
|
161
|
+
default:
|
|
162
|
+
return void 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function serializeString(str) {
|
|
138
166
|
let result = "";
|
|
139
167
|
let lastPos = 0;
|
|
168
|
+
let replacement;
|
|
140
169
|
for (let i = 0, len = str.length; i < len; i++) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
break;
|
|
146
|
-
case "\\":
|
|
147
|
-
replacement = "\\\\";
|
|
148
|
-
break;
|
|
149
|
-
case "<":
|
|
150
|
-
replacement = "\\x3C";
|
|
151
|
-
break;
|
|
152
|
-
case "\n":
|
|
153
|
-
replacement = "\\n";
|
|
154
|
-
break;
|
|
155
|
-
case "\r":
|
|
156
|
-
replacement = "\\r";
|
|
157
|
-
break;
|
|
158
|
-
case "\u2028":
|
|
159
|
-
replacement = "\\u2028";
|
|
160
|
-
break;
|
|
161
|
-
case "\u2029":
|
|
162
|
-
replacement = "\\u2029";
|
|
163
|
-
break;
|
|
164
|
-
default:
|
|
165
|
-
continue;
|
|
170
|
+
replacement = serializeChar(str[i]);
|
|
171
|
+
if (replacement) {
|
|
172
|
+
result += str.slice(lastPos, i) + replacement;
|
|
173
|
+
lastPos = i + 1;
|
|
166
174
|
}
|
|
167
|
-
result += str.slice(lastPos, i) + replacement;
|
|
168
|
-
lastPos = i + 1;
|
|
169
175
|
}
|
|
170
176
|
if (lastPos === 0) {
|
|
171
177
|
result = str;
|
|
@@ -174,8 +180,61 @@ function quote(str) {
|
|
|
174
180
|
}
|
|
175
181
|
return result;
|
|
176
182
|
}
|
|
177
|
-
function
|
|
178
|
-
return str.replace(/\\"/g, '"').replace(/\\\\/g, "\\").replace(/\\
|
|
183
|
+
function deserializeString(str) {
|
|
184
|
+
return str.replace(/\\"/g, '"').replace(/\\\\/g, "\\").replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\b/g, "\b").replace(/\\t/g, " ").replace(/\\f/g, "\f").replace(/\\x3C/g, "<").replace(/\\u2028/g, "\u2028").replace(/\\u2029/g, "\u2029");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/tree/reference.ts
|
|
188
|
+
var REFERENCE = /* @__PURE__ */ new Map();
|
|
189
|
+
var INV_REFERENCE = /* @__PURE__ */ new Map();
|
|
190
|
+
function createReference(id, value) {
|
|
191
|
+
REFERENCE.set(value, id);
|
|
192
|
+
INV_REFERENCE.set(id, value);
|
|
193
|
+
return value;
|
|
194
|
+
}
|
|
195
|
+
function hasReferenceID(value) {
|
|
196
|
+
return REFERENCE.has(value);
|
|
197
|
+
}
|
|
198
|
+
function hasReference(id) {
|
|
199
|
+
return INV_REFERENCE.has(id);
|
|
200
|
+
}
|
|
201
|
+
function getReferenceID(value) {
|
|
202
|
+
assert(hasReferenceID(value), "Missing reference id");
|
|
203
|
+
return REFERENCE.get(value);
|
|
204
|
+
}
|
|
205
|
+
function getReference(id) {
|
|
206
|
+
assert(hasReference(id), "Missing reference for id:" + id);
|
|
207
|
+
return INV_REFERENCE.get(id);
|
|
208
|
+
}
|
|
209
|
+
var GLOBAL_KEY = "__SEROVAL__";
|
|
210
|
+
if (typeof globalThis !== void 0) {
|
|
211
|
+
Object.defineProperty(globalThis, GLOBAL_KEY, {
|
|
212
|
+
value: INV_REFERENCE,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: false,
|
|
215
|
+
enumerable: false
|
|
216
|
+
});
|
|
217
|
+
} else if (typeof window !== void 0) {
|
|
218
|
+
Object.defineProperty(window, GLOBAL_KEY, {
|
|
219
|
+
value: INV_REFERENCE,
|
|
220
|
+
configurable: true,
|
|
221
|
+
writable: false,
|
|
222
|
+
enumerable: false
|
|
223
|
+
});
|
|
224
|
+
} else if (typeof self !== void 0) {
|
|
225
|
+
Object.defineProperty(self, GLOBAL_KEY, {
|
|
226
|
+
value: INV_REFERENCE,
|
|
227
|
+
configurable: true,
|
|
228
|
+
writable: false,
|
|
229
|
+
enumerable: false
|
|
230
|
+
});
|
|
231
|
+
} else if (typeof global !== void 0) {
|
|
232
|
+
Object.defineProperty(global, GLOBAL_KEY, {
|
|
233
|
+
value: INV_REFERENCE,
|
|
234
|
+
configurable: true,
|
|
235
|
+
writable: false,
|
|
236
|
+
enumerable: false
|
|
237
|
+
});
|
|
179
238
|
}
|
|
180
239
|
|
|
181
240
|
// src/tree/symbols.ts
|
|
@@ -235,7 +294,8 @@ var TRUE_NODE = {
|
|
|
235
294
|
m: void 0,
|
|
236
295
|
d: void 0,
|
|
237
296
|
a: void 0,
|
|
238
|
-
f: void 0
|
|
297
|
+
f: void 0,
|
|
298
|
+
b: void 0
|
|
239
299
|
};
|
|
240
300
|
var FALSE_NODE = {
|
|
241
301
|
t: 2 /* Boolean */,
|
|
@@ -246,7 +306,8 @@ var FALSE_NODE = {
|
|
|
246
306
|
m: void 0,
|
|
247
307
|
d: void 0,
|
|
248
308
|
a: void 0,
|
|
249
|
-
f: void 0
|
|
309
|
+
f: void 0,
|
|
310
|
+
b: void 0
|
|
250
311
|
};
|
|
251
312
|
var UNDEFINED_NODE = {
|
|
252
313
|
t: 4 /* Undefined */,
|
|
@@ -257,7 +318,8 @@ var UNDEFINED_NODE = {
|
|
|
257
318
|
m: void 0,
|
|
258
319
|
d: void 0,
|
|
259
320
|
a: void 0,
|
|
260
|
-
f: void 0
|
|
321
|
+
f: void 0,
|
|
322
|
+
b: void 0
|
|
261
323
|
};
|
|
262
324
|
var NULL_NODE = {
|
|
263
325
|
t: 3 /* Null */,
|
|
@@ -268,7 +330,8 @@ var NULL_NODE = {
|
|
|
268
330
|
m: void 0,
|
|
269
331
|
d: void 0,
|
|
270
332
|
a: void 0,
|
|
271
|
-
f: void 0
|
|
333
|
+
f: void 0,
|
|
334
|
+
b: void 0
|
|
272
335
|
};
|
|
273
336
|
var NEG_ZERO_NODE = {
|
|
274
337
|
t: 5 /* NegativeZero */,
|
|
@@ -279,7 +342,8 @@ var NEG_ZERO_NODE = {
|
|
|
279
342
|
m: void 0,
|
|
280
343
|
d: void 0,
|
|
281
344
|
a: void 0,
|
|
282
|
-
f: void 0
|
|
345
|
+
f: void 0,
|
|
346
|
+
b: void 0
|
|
283
347
|
};
|
|
284
348
|
var INFINITY_NODE = {
|
|
285
349
|
t: 6 /* Infinity */,
|
|
@@ -290,7 +354,8 @@ var INFINITY_NODE = {
|
|
|
290
354
|
m: void 0,
|
|
291
355
|
d: void 0,
|
|
292
356
|
a: void 0,
|
|
293
|
-
f: void 0
|
|
357
|
+
f: void 0,
|
|
358
|
+
b: void 0
|
|
294
359
|
};
|
|
295
360
|
var NEG_INFINITY_NODE = {
|
|
296
361
|
t: 7 /* NegativeInfinity */,
|
|
@@ -301,7 +366,8 @@ var NEG_INFINITY_NODE = {
|
|
|
301
366
|
m: void 0,
|
|
302
367
|
d: void 0,
|
|
303
368
|
a: void 0,
|
|
304
|
-
f: void 0
|
|
369
|
+
f: void 0,
|
|
370
|
+
b: void 0
|
|
305
371
|
};
|
|
306
372
|
var NAN_NODE = {
|
|
307
373
|
t: 8 /* NaN */,
|
|
@@ -312,7 +378,8 @@ var NAN_NODE = {
|
|
|
312
378
|
m: void 0,
|
|
313
379
|
d: void 0,
|
|
314
380
|
a: void 0,
|
|
315
|
-
f: void 0
|
|
381
|
+
f: void 0,
|
|
382
|
+
b: void 0
|
|
316
383
|
};
|
|
317
384
|
function createNumberNode(value) {
|
|
318
385
|
return {
|
|
@@ -324,20 +391,22 @@ function createNumberNode(value) {
|
|
|
324
391
|
m: void 0,
|
|
325
392
|
d: void 0,
|
|
326
393
|
a: void 0,
|
|
327
|
-
f: void 0
|
|
394
|
+
f: void 0,
|
|
395
|
+
b: void 0
|
|
328
396
|
};
|
|
329
397
|
}
|
|
330
398
|
function createStringNode(value) {
|
|
331
399
|
return {
|
|
332
400
|
t: 1 /* String */,
|
|
333
401
|
i: void 0,
|
|
334
|
-
s:
|
|
402
|
+
s: serializeString(value),
|
|
335
403
|
l: void 0,
|
|
336
404
|
c: void 0,
|
|
337
405
|
m: void 0,
|
|
338
406
|
d: void 0,
|
|
339
407
|
a: void 0,
|
|
340
|
-
f: void 0
|
|
408
|
+
f: void 0,
|
|
409
|
+
b: void 0
|
|
341
410
|
};
|
|
342
411
|
}
|
|
343
412
|
function createBigIntNode(ctx, current) {
|
|
@@ -351,12 +420,13 @@ function createBigIntNode(ctx, current) {
|
|
|
351
420
|
m: void 0,
|
|
352
421
|
d: void 0,
|
|
353
422
|
a: void 0,
|
|
354
|
-
f: void 0
|
|
423
|
+
f: void 0,
|
|
424
|
+
b: void 0
|
|
355
425
|
};
|
|
356
426
|
}
|
|
357
|
-
function
|
|
427
|
+
function createIndexedValueNode(id) {
|
|
358
428
|
return {
|
|
359
|
-
t: 10 /*
|
|
429
|
+
t: 10 /* IndexedValue */,
|
|
360
430
|
i: id,
|
|
361
431
|
s: void 0,
|
|
362
432
|
l: void 0,
|
|
@@ -364,7 +434,8 @@ function createReferenceNode(id) {
|
|
|
364
434
|
m: void 0,
|
|
365
435
|
d: void 0,
|
|
366
436
|
a: void 0,
|
|
367
|
-
f: void 0
|
|
437
|
+
f: void 0,
|
|
438
|
+
b: void 0
|
|
368
439
|
};
|
|
369
440
|
}
|
|
370
441
|
function createDateNode(id, current) {
|
|
@@ -377,7 +448,8 @@ function createDateNode(id, current) {
|
|
|
377
448
|
m: void 0,
|
|
378
449
|
d: void 0,
|
|
379
450
|
f: void 0,
|
|
380
|
-
a: void 0
|
|
451
|
+
a: void 0,
|
|
452
|
+
b: void 0
|
|
381
453
|
};
|
|
382
454
|
}
|
|
383
455
|
function createRegExpNode(id, current) {
|
|
@@ -390,27 +462,51 @@ function createRegExpNode(id, current) {
|
|
|
390
462
|
m: current.flags,
|
|
391
463
|
d: void 0,
|
|
392
464
|
a: void 0,
|
|
393
|
-
f: void 0
|
|
465
|
+
f: void 0,
|
|
466
|
+
b: void 0
|
|
394
467
|
};
|
|
395
468
|
}
|
|
396
|
-
function
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
const len = current.length;
|
|
469
|
+
function createArrayBufferNode(id, current) {
|
|
470
|
+
const bytes = new Uint8Array(current);
|
|
471
|
+
const len = bytes.length;
|
|
400
472
|
const values = new Array(len);
|
|
401
473
|
for (let i = 0; i < len; i++) {
|
|
402
|
-
values[i] =
|
|
474
|
+
values[i] = bytes[i];
|
|
403
475
|
}
|
|
404
476
|
return {
|
|
405
|
-
t:
|
|
477
|
+
t: 28 /* ArrayBuffer */,
|
|
406
478
|
i: id,
|
|
407
479
|
s: values,
|
|
408
|
-
l:
|
|
480
|
+
l: void 0,
|
|
481
|
+
c: void 0,
|
|
482
|
+
m: void 0,
|
|
483
|
+
d: void 0,
|
|
484
|
+
a: void 0,
|
|
485
|
+
f: void 0,
|
|
486
|
+
b: void 0
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
function serializeArrayBuffer(ctx, current) {
|
|
490
|
+
const id = createIndexedValue(ctx, current);
|
|
491
|
+
if (ctx.markedRefs.has(id)) {
|
|
492
|
+
return createIndexedValueNode(id);
|
|
493
|
+
}
|
|
494
|
+
return createArrayBufferNode(id, current);
|
|
495
|
+
}
|
|
496
|
+
function createTypedArrayNode(ctx, id, current) {
|
|
497
|
+
const constructor = current.constructor.name;
|
|
498
|
+
assert(ctx.features & 2048 /* TypedArray */, `Unsupported value type "${constructor}"`);
|
|
499
|
+
return {
|
|
500
|
+
t: 22 /* TypedArray */,
|
|
501
|
+
i: id,
|
|
502
|
+
s: void 0,
|
|
503
|
+
l: current.length,
|
|
409
504
|
c: constructor,
|
|
410
505
|
m: void 0,
|
|
411
506
|
d: void 0,
|
|
412
507
|
a: void 0,
|
|
413
|
-
f:
|
|
508
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
509
|
+
b: current.byteOffset
|
|
414
510
|
};
|
|
415
511
|
}
|
|
416
512
|
var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
|
|
@@ -420,24 +516,22 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
420
516
|
(ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
|
|
421
517
|
`Unsupported value type "${constructor}"`
|
|
422
518
|
);
|
|
423
|
-
const len = current.length;
|
|
424
|
-
const values = new Array(len);
|
|
425
|
-
for (let i = 0; i < len; i++) {
|
|
426
|
-
values[i] = "" + current[i];
|
|
427
|
-
}
|
|
428
519
|
return {
|
|
429
520
|
t: 23 /* BigIntTypedArray */,
|
|
430
521
|
i: id,
|
|
431
|
-
s:
|
|
432
|
-
l: current.
|
|
522
|
+
s: void 0,
|
|
523
|
+
l: current.length,
|
|
433
524
|
c: constructor,
|
|
434
525
|
m: void 0,
|
|
435
526
|
d: void 0,
|
|
436
527
|
a: void 0,
|
|
437
|
-
f:
|
|
528
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
529
|
+
b: current.byteOffset
|
|
438
530
|
};
|
|
439
531
|
}
|
|
440
|
-
function createWKSymbolNode(current) {
|
|
532
|
+
function createWKSymbolNode(ctx, current) {
|
|
533
|
+
assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "symbol"');
|
|
534
|
+
assert(current in INV_SYMBOL_REF, "seroval only supports well-known symbols");
|
|
441
535
|
return {
|
|
442
536
|
t: 24 /* WKSymbol */,
|
|
443
537
|
i: void 0,
|
|
@@ -447,7 +541,36 @@ function createWKSymbolNode(current) {
|
|
|
447
541
|
m: void 0,
|
|
448
542
|
d: void 0,
|
|
449
543
|
a: void 0,
|
|
450
|
-
f: void 0
|
|
544
|
+
f: void 0,
|
|
545
|
+
b: void 0
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function createReferenceNode(id, ref) {
|
|
549
|
+
return {
|
|
550
|
+
t: 27 /* Reference */,
|
|
551
|
+
i: id,
|
|
552
|
+
s: serializeString(getReferenceID(ref)),
|
|
553
|
+
l: void 0,
|
|
554
|
+
c: void 0,
|
|
555
|
+
m: void 0,
|
|
556
|
+
d: void 0,
|
|
557
|
+
a: void 0,
|
|
558
|
+
f: void 0,
|
|
559
|
+
b: void 0
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function createDataViewNode(ctx, id, current) {
|
|
563
|
+
return {
|
|
564
|
+
t: 29 /* DataView */,
|
|
565
|
+
i: id,
|
|
566
|
+
s: void 0,
|
|
567
|
+
l: current.byteLength,
|
|
568
|
+
c: void 0,
|
|
569
|
+
m: void 0,
|
|
570
|
+
d: void 0,
|
|
571
|
+
a: void 0,
|
|
572
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
573
|
+
b: current.byteOffset
|
|
451
574
|
};
|
|
452
575
|
}
|
|
453
576
|
|
|
@@ -589,6 +712,68 @@ function isValidIdentifier(name) {
|
|
|
589
712
|
return (char === "$" || char === "_" || char >= "A" && char <= "Z" || char >= "a" && char <= "z") && IDENTIFIER_CHECK.test(name);
|
|
590
713
|
}
|
|
591
714
|
|
|
715
|
+
// src/tree/web-api.ts
|
|
716
|
+
function createURLNode(ctx, id, current) {
|
|
717
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "URL"');
|
|
718
|
+
return {
|
|
719
|
+
t: 25 /* URL */,
|
|
720
|
+
i: id,
|
|
721
|
+
s: serializeString(current.href),
|
|
722
|
+
l: void 0,
|
|
723
|
+
c: void 0,
|
|
724
|
+
m: void 0,
|
|
725
|
+
d: void 0,
|
|
726
|
+
f: void 0,
|
|
727
|
+
a: void 0,
|
|
728
|
+
b: void 0
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
function createURLSearchParamsNode(ctx, id, current) {
|
|
732
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "URLSearchParams"');
|
|
733
|
+
return {
|
|
734
|
+
t: 26 /* URLSearchParams */,
|
|
735
|
+
i: id,
|
|
736
|
+
s: serializeString(current.toString()),
|
|
737
|
+
l: void 0,
|
|
738
|
+
c: void 0,
|
|
739
|
+
m: void 0,
|
|
740
|
+
d: void 0,
|
|
741
|
+
f: void 0,
|
|
742
|
+
a: void 0,
|
|
743
|
+
b: void 0
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
async function createBlobNode(ctx, id, current) {
|
|
747
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "Blob"');
|
|
748
|
+
return {
|
|
749
|
+
t: 30 /* Blob */,
|
|
750
|
+
i: id,
|
|
751
|
+
s: void 0,
|
|
752
|
+
l: void 0,
|
|
753
|
+
c: serializeString(current.type),
|
|
754
|
+
m: void 0,
|
|
755
|
+
d: void 0,
|
|
756
|
+
f: serializeArrayBuffer(ctx, await current.arrayBuffer()),
|
|
757
|
+
a: void 0,
|
|
758
|
+
b: void 0
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
async function createFileNode(ctx, id, current) {
|
|
762
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "File"');
|
|
763
|
+
return {
|
|
764
|
+
t: 31 /* File */,
|
|
765
|
+
i: id,
|
|
766
|
+
s: void 0,
|
|
767
|
+
l: void 0,
|
|
768
|
+
c: serializeString(current.type),
|
|
769
|
+
m: serializeString(current.name),
|
|
770
|
+
d: void 0,
|
|
771
|
+
f: serializeArrayBuffer(ctx, await current.arrayBuffer()),
|
|
772
|
+
a: void 0,
|
|
773
|
+
b: current.lastModified
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
592
777
|
// src/tree/async.ts
|
|
593
778
|
async function generateNodeList(ctx, current) {
|
|
594
779
|
const size = current.length;
|
|
@@ -622,7 +807,8 @@ async function generateArrayNode(ctx, id, current) {
|
|
|
622
807
|
m: void 0,
|
|
623
808
|
d: void 0,
|
|
624
809
|
a: await generateNodeList(ctx, current),
|
|
625
|
-
f: void 0
|
|
810
|
+
f: void 0,
|
|
811
|
+
b: void 0
|
|
626
812
|
};
|
|
627
813
|
}
|
|
628
814
|
async function generateMapNode(ctx, id, current) {
|
|
@@ -658,7 +844,8 @@ async function generateMapNode(ctx, id, current) {
|
|
|
658
844
|
m: void 0,
|
|
659
845
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
660
846
|
a: void 0,
|
|
661
|
-
f: void 0
|
|
847
|
+
f: void 0,
|
|
848
|
+
b: void 0
|
|
662
849
|
};
|
|
663
850
|
}
|
|
664
851
|
async function generateSetNode(ctx, id, current) {
|
|
@@ -687,7 +874,8 @@ async function generateSetNode(ctx, id, current) {
|
|
|
687
874
|
m: void 0,
|
|
688
875
|
d: void 0,
|
|
689
876
|
a: nodes,
|
|
690
|
-
f: void 0
|
|
877
|
+
f: void 0,
|
|
878
|
+
b: void 0
|
|
691
879
|
};
|
|
692
880
|
}
|
|
693
881
|
async function generateProperties(ctx, properties) {
|
|
@@ -700,14 +888,16 @@ async function generateProperties(ctx, properties) {
|
|
|
700
888
|
let deferredSize = 0;
|
|
701
889
|
let nodesSize = 0;
|
|
702
890
|
let item;
|
|
891
|
+
let escaped;
|
|
703
892
|
for (const key of keys) {
|
|
704
893
|
item = properties[key];
|
|
894
|
+
escaped = serializeString(key);
|
|
705
895
|
if (isIterable(item)) {
|
|
706
|
-
deferredKeys[deferredSize] =
|
|
896
|
+
deferredKeys[deferredSize] = escaped;
|
|
707
897
|
deferredValues[deferredSize] = item;
|
|
708
898
|
deferredSize++;
|
|
709
899
|
} else {
|
|
710
|
-
keyNodes[nodesSize] =
|
|
900
|
+
keyNodes[nodesSize] = escaped;
|
|
711
901
|
valueNodes[nodesSize] = await parse(ctx, item);
|
|
712
902
|
nodesSize++;
|
|
713
903
|
}
|
|
@@ -736,7 +926,8 @@ async function generateIterableNode(ctx, id, current) {
|
|
|
736
926
|
// Parse options first before the items
|
|
737
927
|
d: options ? await generateProperties(ctx, options) : void 0,
|
|
738
928
|
a: await generateNodeList(ctx, array),
|
|
739
|
-
f: void 0
|
|
929
|
+
f: void 0,
|
|
930
|
+
b: void 0
|
|
740
931
|
};
|
|
741
932
|
}
|
|
742
933
|
async function generatePromiseNode(ctx, id, current) {
|
|
@@ -751,7 +942,8 @@ async function generatePromiseNode(ctx, id, current) {
|
|
|
751
942
|
// Parse options first before the items
|
|
752
943
|
d: void 0,
|
|
753
944
|
a: void 0,
|
|
754
|
-
f: await parse(ctx, value)
|
|
945
|
+
f: await parse(ctx, value),
|
|
946
|
+
b: void 0
|
|
755
947
|
}));
|
|
756
948
|
}
|
|
757
949
|
async function generateObjectNode(ctx, id, current, empty) {
|
|
@@ -770,7 +962,8 @@ async function generateObjectNode(ctx, id, current, empty) {
|
|
|
770
962
|
m: void 0,
|
|
771
963
|
d: await generateProperties(ctx, current),
|
|
772
964
|
a: void 0,
|
|
773
|
-
f: void 0
|
|
965
|
+
f: void 0,
|
|
966
|
+
b: void 0
|
|
774
967
|
};
|
|
775
968
|
}
|
|
776
969
|
async function generateAggregateErrorNode(ctx, id, current) {
|
|
@@ -780,12 +973,13 @@ async function generateAggregateErrorNode(ctx, id, current) {
|
|
|
780
973
|
t: 20 /* AggregateError */,
|
|
781
974
|
i: id,
|
|
782
975
|
s: void 0,
|
|
783
|
-
l:
|
|
976
|
+
l: void 0,
|
|
784
977
|
c: void 0,
|
|
785
|
-
m: current.message,
|
|
978
|
+
m: serializeString(current.message),
|
|
786
979
|
d: optionsNode,
|
|
787
|
-
a:
|
|
788
|
-
f: void 0
|
|
980
|
+
a: void 0,
|
|
981
|
+
f: void 0,
|
|
982
|
+
b: void 0
|
|
789
983
|
};
|
|
790
984
|
}
|
|
791
985
|
async function generateErrorNode(ctx, id, current) {
|
|
@@ -797,10 +991,49 @@ async function generateErrorNode(ctx, id, current) {
|
|
|
797
991
|
s: void 0,
|
|
798
992
|
l: void 0,
|
|
799
993
|
c: getErrorConstructorName(current),
|
|
800
|
-
m: current.message,
|
|
994
|
+
m: serializeString(current.message),
|
|
801
995
|
d: optionsNode,
|
|
802
996
|
a: void 0,
|
|
803
|
-
f: void 0
|
|
997
|
+
f: void 0,
|
|
998
|
+
b: void 0
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
async function generateHeadersNode(ctx, id, current) {
|
|
1002
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "Headers"');
|
|
1003
|
+
const items = {};
|
|
1004
|
+
current.forEach((value, key) => {
|
|
1005
|
+
items[key] = value;
|
|
1006
|
+
});
|
|
1007
|
+
return {
|
|
1008
|
+
t: 32 /* Headers */,
|
|
1009
|
+
i: id,
|
|
1010
|
+
s: void 0,
|
|
1011
|
+
l: void 0,
|
|
1012
|
+
c: void 0,
|
|
1013
|
+
m: void 0,
|
|
1014
|
+
d: await generateProperties(ctx, items),
|
|
1015
|
+
a: void 0,
|
|
1016
|
+
f: void 0,
|
|
1017
|
+
b: void 0
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
async function generateFormDataNode(ctx, id, current) {
|
|
1021
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "FormData"');
|
|
1022
|
+
const items = {};
|
|
1023
|
+
current.forEach((value, key) => {
|
|
1024
|
+
items[key] = value;
|
|
1025
|
+
});
|
|
1026
|
+
return {
|
|
1027
|
+
t: 33 /* FormData */,
|
|
1028
|
+
i: id,
|
|
1029
|
+
s: void 0,
|
|
1030
|
+
l: void 0,
|
|
1031
|
+
c: void 0,
|
|
1032
|
+
m: void 0,
|
|
1033
|
+
d: await generateProperties(ctx, items),
|
|
1034
|
+
a: void 0,
|
|
1035
|
+
f: void 0,
|
|
1036
|
+
b: void 0
|
|
804
1037
|
};
|
|
805
1038
|
}
|
|
806
1039
|
async function parse(ctx, current) {
|
|
@@ -818,24 +1051,26 @@ async function parse(ctx, current) {
|
|
|
818
1051
|
case -Infinity:
|
|
819
1052
|
return NEG_INFINITY_NODE;
|
|
820
1053
|
default:
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
1054
|
+
if (current !== current) {
|
|
1055
|
+
return NAN_NODE;
|
|
1056
|
+
}
|
|
1057
|
+
if (Object.is(current, -0)) {
|
|
1058
|
+
return NEG_ZERO_NODE;
|
|
1059
|
+
}
|
|
1060
|
+
return createNumberNode(current);
|
|
828
1061
|
}
|
|
829
|
-
return createNumberNode(current);
|
|
830
1062
|
case "bigint":
|
|
831
1063
|
return createBigIntNode(ctx, current);
|
|
832
1064
|
case "object": {
|
|
833
1065
|
if (!current) {
|
|
834
1066
|
return NULL_NODE;
|
|
835
1067
|
}
|
|
836
|
-
const id =
|
|
1068
|
+
const id = createIndexedValue(ctx, current);
|
|
837
1069
|
if (ctx.markedRefs.has(id)) {
|
|
838
|
-
return
|
|
1070
|
+
return createIndexedValueNode(id);
|
|
1071
|
+
}
|
|
1072
|
+
if (hasReferenceID(current)) {
|
|
1073
|
+
return createReferenceNode(id, current);
|
|
839
1074
|
}
|
|
840
1075
|
if (Array.isArray(current)) {
|
|
841
1076
|
return generateArrayNode(ctx, id, current);
|
|
@@ -847,6 +1082,8 @@ async function parse(ctx, current) {
|
|
|
847
1082
|
return createRegExpNode(id, current);
|
|
848
1083
|
case Promise:
|
|
849
1084
|
return generatePromiseNode(ctx, id, current);
|
|
1085
|
+
case ArrayBuffer:
|
|
1086
|
+
return createArrayBufferNode(id, current);
|
|
850
1087
|
case Int8Array:
|
|
851
1088
|
case Int16Array:
|
|
852
1089
|
case Int32Array:
|
|
@@ -860,6 +1097,8 @@ async function parse(ctx, current) {
|
|
|
860
1097
|
case BigInt64Array:
|
|
861
1098
|
case BigUint64Array:
|
|
862
1099
|
return createBigIntTypedArrayNode(ctx, id, current);
|
|
1100
|
+
case DataView:
|
|
1101
|
+
return createDataViewNode(ctx, id, current);
|
|
863
1102
|
case Map:
|
|
864
1103
|
return generateMapNode(
|
|
865
1104
|
ctx,
|
|
@@ -899,6 +1138,18 @@ async function parse(ctx, current) {
|
|
|
899
1138
|
case TypeError:
|
|
900
1139
|
case URIError:
|
|
901
1140
|
return generateErrorNode(ctx, id, current);
|
|
1141
|
+
case URL:
|
|
1142
|
+
return createURLNode(ctx, id, current);
|
|
1143
|
+
case URLSearchParams:
|
|
1144
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
1145
|
+
case Blob:
|
|
1146
|
+
return createBlobNode(ctx, id, current);
|
|
1147
|
+
case File:
|
|
1148
|
+
return createFileNode(ctx, id, current);
|
|
1149
|
+
case Headers:
|
|
1150
|
+
return generateHeadersNode(ctx, id, current);
|
|
1151
|
+
case FormData:
|
|
1152
|
+
return generateFormDataNode(ctx, id, current);
|
|
902
1153
|
default:
|
|
903
1154
|
break;
|
|
904
1155
|
}
|
|
@@ -923,9 +1174,22 @@ async function parse(ctx, current) {
|
|
|
923
1174
|
throw new Error("Unsupported type");
|
|
924
1175
|
}
|
|
925
1176
|
case "symbol":
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1177
|
+
if (hasReferenceID(current)) {
|
|
1178
|
+
const id = createIndexedValue(ctx, current);
|
|
1179
|
+
if (ctx.markedRefs.has(id)) {
|
|
1180
|
+
return createIndexedValueNode(id);
|
|
1181
|
+
}
|
|
1182
|
+
return createReferenceNode(id, current);
|
|
1183
|
+
}
|
|
1184
|
+
return createWKSymbolNode(ctx, current);
|
|
1185
|
+
case "function": {
|
|
1186
|
+
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
1187
|
+
const id = createIndexedValue(ctx, current);
|
|
1188
|
+
if (ctx.markedRefs.has(id)) {
|
|
1189
|
+
return createIndexedValueNode(id);
|
|
1190
|
+
}
|
|
1191
|
+
return createReferenceNode(id, current);
|
|
1192
|
+
}
|
|
929
1193
|
default:
|
|
930
1194
|
throw new Error("Unsupported type");
|
|
931
1195
|
}
|
|
@@ -937,13 +1201,20 @@ async function parseAsync(ctx, current) {
|
|
|
937
1201
|
}
|
|
938
1202
|
|
|
939
1203
|
// src/tree/deserialize.ts
|
|
940
|
-
function
|
|
941
|
-
ctx.
|
|
1204
|
+
function assignIndexedValue(ctx, index, value) {
|
|
1205
|
+
if (ctx.markedRefs.has(index)) {
|
|
1206
|
+
ctx.valueMap.set(index, value);
|
|
1207
|
+
}
|
|
942
1208
|
return value;
|
|
943
1209
|
}
|
|
944
|
-
function
|
|
1210
|
+
function deserializeArray(ctx, node) {
|
|
1211
|
+
const result = assignIndexedValue(
|
|
1212
|
+
ctx,
|
|
1213
|
+
node.i,
|
|
1214
|
+
new Array(node.l)
|
|
1215
|
+
);
|
|
945
1216
|
let item;
|
|
946
|
-
for (let i = 0, len = node.
|
|
1217
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
947
1218
|
item = node.a[i];
|
|
948
1219
|
if (item) {
|
|
949
1220
|
result[i] = deserializeTree(ctx, item);
|
|
@@ -951,84 +1222,68 @@ function deserializeNodeList(ctx, node, result) {
|
|
|
951
1222
|
}
|
|
952
1223
|
return result;
|
|
953
1224
|
}
|
|
954
|
-
function deserializeArray(ctx, node) {
|
|
955
|
-
const result = assignRef(
|
|
956
|
-
ctx,
|
|
957
|
-
node.i,
|
|
958
|
-
new Array(node.l)
|
|
959
|
-
);
|
|
960
|
-
ctx.stack.push(node.i);
|
|
961
|
-
deserializeNodeList(ctx, node, result);
|
|
962
|
-
ctx.stack.pop();
|
|
963
|
-
return result;
|
|
964
|
-
}
|
|
965
1225
|
function deserializeProperties(ctx, node, result) {
|
|
966
1226
|
if (node.s === 0) {
|
|
967
1227
|
return {};
|
|
968
1228
|
}
|
|
969
1229
|
for (let i = 0; i < node.s; i++) {
|
|
970
|
-
result[node.k[i]] = deserializeTree(ctx, node.v[i]);
|
|
1230
|
+
result[deserializeString(node.k[i])] = deserializeTree(ctx, node.v[i]);
|
|
971
1231
|
}
|
|
972
1232
|
return result;
|
|
973
1233
|
}
|
|
974
1234
|
function deserializeNullConstructor(ctx, node) {
|
|
975
|
-
const result =
|
|
976
|
-
|
|
1235
|
+
const result = assignIndexedValue(
|
|
1236
|
+
ctx,
|
|
1237
|
+
node.i,
|
|
1238
|
+
/* @__PURE__ */ Object.create(null)
|
|
1239
|
+
);
|
|
977
1240
|
deserializeProperties(ctx, node.d, result);
|
|
978
|
-
ctx.stack.pop();
|
|
979
1241
|
return result;
|
|
980
1242
|
}
|
|
981
1243
|
function deserializeObject(ctx, node) {
|
|
982
|
-
const result =
|
|
983
|
-
ctx.stack.push(node.i);
|
|
1244
|
+
const result = assignIndexedValue(ctx, node.i, {});
|
|
984
1245
|
deserializeProperties(ctx, node.d, result);
|
|
985
|
-
ctx.stack.pop();
|
|
986
1246
|
return result;
|
|
987
1247
|
}
|
|
988
1248
|
function deserializeSet(ctx, node) {
|
|
989
|
-
const result =
|
|
990
|
-
|
|
991
|
-
for (let i = 0, len = node.a.length; i < len; i++) {
|
|
1249
|
+
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
1250
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
992
1251
|
result.add(deserializeTree(ctx, node.a[i]));
|
|
993
1252
|
}
|
|
994
|
-
ctx.stack.pop();
|
|
995
1253
|
return result;
|
|
996
1254
|
}
|
|
997
1255
|
function deserializeMap(ctx, node) {
|
|
998
|
-
const result =
|
|
1256
|
+
const result = assignIndexedValue(
|
|
999
1257
|
ctx,
|
|
1000
1258
|
node.i,
|
|
1001
1259
|
/* @__PURE__ */ new Map()
|
|
1002
1260
|
);
|
|
1003
|
-
|
|
1004
|
-
for (let i = 0; i < node.d.s; i++) {
|
|
1261
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1005
1262
|
result.set(
|
|
1006
1263
|
deserializeTree(ctx, node.d.k[i]),
|
|
1007
1264
|
deserializeTree(ctx, node.d.v[i])
|
|
1008
1265
|
);
|
|
1009
1266
|
}
|
|
1010
|
-
ctx.stack.pop();
|
|
1011
1267
|
return result;
|
|
1012
1268
|
}
|
|
1013
1269
|
function deserializeDictionary(ctx, node, result) {
|
|
1014
1270
|
if (node.d) {
|
|
1015
|
-
ctx.stack.push(node.i);
|
|
1016
1271
|
const fields = deserializeProperties(ctx, node.d, {});
|
|
1017
|
-
ctx.stack.pop();
|
|
1018
1272
|
Object.assign(result, fields);
|
|
1019
1273
|
}
|
|
1020
1274
|
return result;
|
|
1021
1275
|
}
|
|
1022
1276
|
function deserializeAggregateError(ctx, node) {
|
|
1023
|
-
const result =
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1277
|
+
const result = assignIndexedValue(
|
|
1278
|
+
ctx,
|
|
1279
|
+
node.i,
|
|
1280
|
+
new AggregateError([], deserializeString(node.m))
|
|
1281
|
+
);
|
|
1027
1282
|
return deserializeDictionary(ctx, node, result);
|
|
1028
1283
|
}
|
|
1029
1284
|
function deserializeError(ctx, node) {
|
|
1030
1285
|
const ErrorConstructor = getErrorConstructor(node.c);
|
|
1031
|
-
const result =
|
|
1286
|
+
const result = assignIndexedValue(ctx, node.i, new ErrorConstructor(deserializeString(node.m)));
|
|
1032
1287
|
return deserializeDictionary(ctx, node, result);
|
|
1033
1288
|
}
|
|
1034
1289
|
function createDeferred() {
|
|
@@ -1044,37 +1299,107 @@ function createDeferred() {
|
|
|
1044
1299
|
}
|
|
1045
1300
|
function deserializePromise(ctx, node) {
|
|
1046
1301
|
const deferred = createDeferred();
|
|
1047
|
-
const result =
|
|
1302
|
+
const result = assignIndexedValue(ctx, node.i, deferred.promise);
|
|
1048
1303
|
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1049
1304
|
return result;
|
|
1050
1305
|
}
|
|
1306
|
+
function deserializeArrayBuffer(ctx, node) {
|
|
1307
|
+
const bytes = new Uint8Array(node.s);
|
|
1308
|
+
const result = assignIndexedValue(ctx, node.i, bytes.buffer);
|
|
1309
|
+
return result;
|
|
1310
|
+
}
|
|
1051
1311
|
function deserializeTypedArray(ctx, node) {
|
|
1052
1312
|
const TypedArray = getTypedArrayConstructor(node.c);
|
|
1053
|
-
const
|
|
1054
|
-
const result =
|
|
1055
|
-
|
|
1313
|
+
const source = deserializeTree(ctx, node.f);
|
|
1314
|
+
const result = assignIndexedValue(ctx, node.i, new TypedArray(
|
|
1315
|
+
source,
|
|
1316
|
+
node.b,
|
|
1056
1317
|
node.l
|
|
1057
1318
|
));
|
|
1058
|
-
for (let i = 0, len = node.s.length; i < len; i++) {
|
|
1059
|
-
result[i] = node.t === 23 /* BigIntTypedArray */ ? BigInt(node.s[i]) : Number(node.s[i]);
|
|
1060
|
-
}
|
|
1061
1319
|
return result;
|
|
1062
1320
|
}
|
|
1063
1321
|
function deserializeIterable(ctx, node) {
|
|
1064
1322
|
const values = [];
|
|
1065
|
-
|
|
1066
|
-
|
|
1323
|
+
let item;
|
|
1324
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
1325
|
+
item = node.a[i];
|
|
1326
|
+
if (item) {
|
|
1327
|
+
values[i] = deserializeTree(ctx, item);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
const result = assignIndexedValue(ctx, node.i, {
|
|
1067
1331
|
[Symbol.iterator]: () => values.values()
|
|
1068
1332
|
});
|
|
1069
1333
|
return deserializeDictionary(ctx, node, result);
|
|
1070
1334
|
}
|
|
1335
|
+
function deserializeDate(ctx, node) {
|
|
1336
|
+
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1337
|
+
}
|
|
1338
|
+
function deserializeRegExp(ctx, node) {
|
|
1339
|
+
return assignIndexedValue(ctx, node.i, new RegExp(node.c, node.m));
|
|
1340
|
+
}
|
|
1341
|
+
function deserializeURL(ctx, node) {
|
|
1342
|
+
return assignIndexedValue(ctx, node.i, new URL(deserializeString(node.s)));
|
|
1343
|
+
}
|
|
1344
|
+
function deserializeURLSearchParams(ctx, node) {
|
|
1345
|
+
return assignIndexedValue(ctx, node.i, new URLSearchParams(deserializeString(node.s)));
|
|
1346
|
+
}
|
|
1347
|
+
function deserializeReference(ctx, node) {
|
|
1348
|
+
return assignIndexedValue(ctx, node.i, getReference(deserializeString(node.s)));
|
|
1349
|
+
}
|
|
1350
|
+
function deserializeDataView(ctx, node) {
|
|
1351
|
+
const source = deserializeTree(ctx, node.f);
|
|
1352
|
+
const result = assignIndexedValue(ctx, node.i, new DataView(
|
|
1353
|
+
source,
|
|
1354
|
+
node.b,
|
|
1355
|
+
node.l
|
|
1356
|
+
));
|
|
1357
|
+
return result;
|
|
1358
|
+
}
|
|
1359
|
+
function deserializeBlob(ctx, node) {
|
|
1360
|
+
const source = deserializeTree(ctx, node.f);
|
|
1361
|
+
const result = assignIndexedValue(ctx, node.i, new Blob(
|
|
1362
|
+
[source],
|
|
1363
|
+
{ type: deserializeString(node.c) }
|
|
1364
|
+
));
|
|
1365
|
+
return result;
|
|
1366
|
+
}
|
|
1367
|
+
function deserializeFile(ctx, node) {
|
|
1368
|
+
const source = deserializeTree(ctx, node.f);
|
|
1369
|
+
const result = assignIndexedValue(ctx, node.i, new File(
|
|
1370
|
+
[source],
|
|
1371
|
+
deserializeString(node.m),
|
|
1372
|
+
{ type: deserializeString(node.c), lastModified: node.b }
|
|
1373
|
+
));
|
|
1374
|
+
return result;
|
|
1375
|
+
}
|
|
1376
|
+
function deserializeHeaders(ctx, node) {
|
|
1377
|
+
const result = assignIndexedValue(ctx, node.i, new Headers());
|
|
1378
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1379
|
+
result.set(
|
|
1380
|
+
deserializeString(node.d.k[i]),
|
|
1381
|
+
deserializeTree(ctx, node.d.v[i])
|
|
1382
|
+
);
|
|
1383
|
+
}
|
|
1384
|
+
return result;
|
|
1385
|
+
}
|
|
1386
|
+
function deserializeFormData(ctx, node) {
|
|
1387
|
+
const result = assignIndexedValue(ctx, node.i, new FormData());
|
|
1388
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1389
|
+
result.set(
|
|
1390
|
+
deserializeString(node.d.k[i]),
|
|
1391
|
+
deserializeTree(ctx, node.d.v[i])
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
return result;
|
|
1395
|
+
}
|
|
1071
1396
|
function deserializeTree(ctx, node) {
|
|
1072
1397
|
switch (node.t) {
|
|
1073
1398
|
case 0 /* Number */:
|
|
1074
1399
|
case 2 /* Boolean */:
|
|
1075
1400
|
return node.s;
|
|
1076
1401
|
case 1 /* String */:
|
|
1077
|
-
return
|
|
1402
|
+
return deserializeString(node.s);
|
|
1078
1403
|
case 4 /* Undefined */:
|
|
1079
1404
|
return void 0;
|
|
1080
1405
|
case 3 /* Null */:
|
|
@@ -1089,7 +1414,7 @@ function deserializeTree(ctx, node) {
|
|
|
1089
1414
|
return NaN;
|
|
1090
1415
|
case 9 /* BigInt */:
|
|
1091
1416
|
return BigInt(node.s);
|
|
1092
|
-
case 10 /*
|
|
1417
|
+
case 10 /* IndexedValue */:
|
|
1093
1418
|
return ctx.valueMap.get(node.i);
|
|
1094
1419
|
case 15 /* Array */:
|
|
1095
1420
|
return deserializeArray(ctx, node);
|
|
@@ -1098,16 +1423,20 @@ function deserializeTree(ctx, node) {
|
|
|
1098
1423
|
case 17 /* NullConstructor */:
|
|
1099
1424
|
return deserializeNullConstructor(ctx, node);
|
|
1100
1425
|
case 11 /* Date */:
|
|
1101
|
-
return
|
|
1426
|
+
return deserializeDate(ctx, node);
|
|
1102
1427
|
case 12 /* RegExp */:
|
|
1103
|
-
return
|
|
1428
|
+
return deserializeRegExp(ctx, node);
|
|
1104
1429
|
case 13 /* Set */:
|
|
1105
1430
|
return deserializeSet(ctx, node);
|
|
1106
1431
|
case 14 /* Map */:
|
|
1107
1432
|
return deserializeMap(ctx, node);
|
|
1433
|
+
case 28 /* ArrayBuffer */:
|
|
1434
|
+
return deserializeArrayBuffer(ctx, node);
|
|
1108
1435
|
case 23 /* BigIntTypedArray */:
|
|
1109
1436
|
case 22 /* TypedArray */:
|
|
1110
1437
|
return deserializeTypedArray(ctx, node);
|
|
1438
|
+
case 29 /* DataView */:
|
|
1439
|
+
return deserializeDataView(ctx, node);
|
|
1111
1440
|
case 20 /* AggregateError */:
|
|
1112
1441
|
return deserializeAggregateError(ctx, node);
|
|
1113
1442
|
case 19 /* Error */:
|
|
@@ -1118,6 +1447,20 @@ function deserializeTree(ctx, node) {
|
|
|
1118
1447
|
return deserializePromise(ctx, node);
|
|
1119
1448
|
case 24 /* WKSymbol */:
|
|
1120
1449
|
return SYMBOL_REF[node.s];
|
|
1450
|
+
case 25 /* URL */:
|
|
1451
|
+
return deserializeURL(ctx, node);
|
|
1452
|
+
case 26 /* URLSearchParams */:
|
|
1453
|
+
return deserializeURLSearchParams(ctx, node);
|
|
1454
|
+
case 27 /* Reference */:
|
|
1455
|
+
return deserializeReference(ctx, node);
|
|
1456
|
+
case 30 /* Blob */:
|
|
1457
|
+
return deserializeBlob(ctx, node);
|
|
1458
|
+
case 31 /* File */:
|
|
1459
|
+
return deserializeFile(ctx, node);
|
|
1460
|
+
case 32 /* Headers */:
|
|
1461
|
+
return deserializeHeaders(ctx, node);
|
|
1462
|
+
case 33 /* FormData */:
|
|
1463
|
+
return deserializeFormData(ctx, node);
|
|
1121
1464
|
default:
|
|
1122
1465
|
throw new Error("Unsupported type");
|
|
1123
1466
|
}
|
|
@@ -1128,10 +1471,12 @@ function getAssignmentExpression(assignment) {
|
|
|
1128
1471
|
switch (assignment.t) {
|
|
1129
1472
|
case "index":
|
|
1130
1473
|
return assignment.s + "=" + assignment.v;
|
|
1131
|
-
case "map":
|
|
1132
|
-
return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
|
|
1133
1474
|
case "set":
|
|
1475
|
+
return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
|
|
1476
|
+
case "add":
|
|
1134
1477
|
return assignment.s + ".add(" + assignment.v + ")";
|
|
1478
|
+
case "append":
|
|
1479
|
+
return assignment.s + ".append(" + assignment.k + "," + assignment.v + ")";
|
|
1135
1480
|
default:
|
|
1136
1481
|
return "";
|
|
1137
1482
|
}
|
|
@@ -1158,10 +1503,10 @@ function mergeAssignments(assignments) {
|
|
|
1158
1503
|
current = item;
|
|
1159
1504
|
}
|
|
1160
1505
|
break;
|
|
1161
|
-
case "
|
|
1506
|
+
case "set":
|
|
1162
1507
|
if (item.s === prev.s) {
|
|
1163
1508
|
current = {
|
|
1164
|
-
t: "
|
|
1509
|
+
t: "set",
|
|
1165
1510
|
s: getAssignmentExpression(current),
|
|
1166
1511
|
k: item.k,
|
|
1167
1512
|
v: item.v
|
|
@@ -1171,10 +1516,10 @@ function mergeAssignments(assignments) {
|
|
|
1171
1516
|
current = item;
|
|
1172
1517
|
}
|
|
1173
1518
|
break;
|
|
1174
|
-
case "
|
|
1519
|
+
case "add":
|
|
1175
1520
|
if (item.s === prev.s) {
|
|
1176
1521
|
current = {
|
|
1177
|
-
t: "
|
|
1522
|
+
t: "add",
|
|
1178
1523
|
s: getAssignmentExpression(current),
|
|
1179
1524
|
k: void 0,
|
|
1180
1525
|
v: item.v
|
|
@@ -1184,6 +1529,10 @@ function mergeAssignments(assignments) {
|
|
|
1184
1529
|
current = item;
|
|
1185
1530
|
}
|
|
1186
1531
|
break;
|
|
1532
|
+
case "append":
|
|
1533
|
+
newAssignments.push(current);
|
|
1534
|
+
current = item;
|
|
1535
|
+
break;
|
|
1187
1536
|
default:
|
|
1188
1537
|
break;
|
|
1189
1538
|
}
|
|
@@ -1218,40 +1567,45 @@ function createAssignment(ctx, source, value) {
|
|
|
1218
1567
|
v: value
|
|
1219
1568
|
});
|
|
1220
1569
|
}
|
|
1221
|
-
function
|
|
1222
|
-
markRef(ctx, ref);
|
|
1570
|
+
function createAddAssignment(ctx, ref, value) {
|
|
1223
1571
|
ctx.assignments.push({
|
|
1224
|
-
t: "
|
|
1572
|
+
t: "add",
|
|
1225
1573
|
s: getRefParam(ctx, ref),
|
|
1226
1574
|
k: void 0,
|
|
1227
1575
|
v: value
|
|
1228
1576
|
});
|
|
1229
1577
|
}
|
|
1230
|
-
function
|
|
1231
|
-
|
|
1578
|
+
function createSetAssignment(ctx, ref, key, value) {
|
|
1579
|
+
ctx.assignments.push({
|
|
1580
|
+
t: "set",
|
|
1581
|
+
s: getRefParam(ctx, ref),
|
|
1582
|
+
k: key,
|
|
1583
|
+
v: value
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
function createAppendAssignment(ctx, ref, key, value) {
|
|
1232
1587
|
ctx.assignments.push({
|
|
1233
|
-
t: "
|
|
1588
|
+
t: "append",
|
|
1234
1589
|
s: getRefParam(ctx, ref),
|
|
1235
1590
|
k: key,
|
|
1236
1591
|
v: value
|
|
1237
1592
|
});
|
|
1238
1593
|
}
|
|
1239
1594
|
function createArrayAssign(ctx, ref, index, value) {
|
|
1240
|
-
markRef(ctx, ref);
|
|
1241
1595
|
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
|
|
1242
1596
|
}
|
|
1243
1597
|
function createObjectAssign(ctx, ref, key, value) {
|
|
1244
1598
|
markRef(ctx, ref);
|
|
1245
1599
|
createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
|
|
1246
1600
|
}
|
|
1247
|
-
function
|
|
1601
|
+
function assignIndexedValue2(ctx, index, value) {
|
|
1248
1602
|
if (ctx.markedRefs.has(index)) {
|
|
1249
1603
|
return getRefParam(ctx, index) + "=" + value;
|
|
1250
1604
|
}
|
|
1251
1605
|
return value;
|
|
1252
1606
|
}
|
|
1253
|
-
function
|
|
1254
|
-
return node.t === 10 /*
|
|
1607
|
+
function isIndexedValueInStack(ctx, node) {
|
|
1608
|
+
return node.t === 10 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
1255
1609
|
}
|
|
1256
1610
|
function serializeNodeList(ctx, node) {
|
|
1257
1611
|
const size = node.l;
|
|
@@ -1264,7 +1618,8 @@ function serializeNodeList(ctx, node) {
|
|
|
1264
1618
|
}
|
|
1265
1619
|
item = node.a[i];
|
|
1266
1620
|
if (item) {
|
|
1267
|
-
if (
|
|
1621
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1622
|
+
markRef(ctx, node.i);
|
|
1268
1623
|
createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
|
|
1269
1624
|
isHoley = true;
|
|
1270
1625
|
} else {
|
|
@@ -1281,7 +1636,7 @@ function serializeArray(ctx, node) {
|
|
|
1281
1636
|
ctx.stack.push(node.i);
|
|
1282
1637
|
const result = serializeNodeList(ctx, node);
|
|
1283
1638
|
ctx.stack.pop();
|
|
1284
|
-
return
|
|
1639
|
+
return assignIndexedValue2(ctx, node.i, result);
|
|
1285
1640
|
}
|
|
1286
1641
|
function serializeProperties(ctx, sourceID, node) {
|
|
1287
1642
|
if (node.s === 0) {
|
|
@@ -1295,20 +1650,24 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1295
1650
|
let isIdentifier;
|
|
1296
1651
|
let refParam;
|
|
1297
1652
|
let hasPrev = false;
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1653
|
+
const keys = node.k;
|
|
1654
|
+
const values = node.v;
|
|
1655
|
+
for (let i = 0, len = node.s; i < len; i++) {
|
|
1656
|
+
key = keys[i];
|
|
1657
|
+
val = values[i];
|
|
1301
1658
|
check = Number(key);
|
|
1302
1659
|
isIdentifier = check >= 0 || isValidIdentifier(key);
|
|
1303
|
-
if (
|
|
1660
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1304
1661
|
refParam = getRefParam(ctx, val.i);
|
|
1305
1662
|
if (isIdentifier && Number.isNaN(check)) {
|
|
1663
|
+
markRef(ctx, sourceID);
|
|
1306
1664
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
1307
1665
|
} else {
|
|
1308
|
-
|
|
1666
|
+
markRef(ctx, sourceID);
|
|
1667
|
+
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + key + '"', refParam);
|
|
1309
1668
|
}
|
|
1310
1669
|
} else {
|
|
1311
|
-
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' +
|
|
1670
|
+
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + key + '"') + ":" + serializeTree(ctx, val);
|
|
1312
1671
|
hasPrev = true;
|
|
1313
1672
|
}
|
|
1314
1673
|
}
|
|
@@ -1331,12 +1690,14 @@ function serializeAssignments(ctx, sourceID, node) {
|
|
|
1331
1690
|
let check;
|
|
1332
1691
|
let parentAssignment;
|
|
1333
1692
|
let isIdentifier;
|
|
1334
|
-
|
|
1693
|
+
const keys = node.k;
|
|
1694
|
+
const values = node.v;
|
|
1695
|
+
for (let i = 0, len = node.s; i < len; i++) {
|
|
1335
1696
|
parentStack = ctx.stack;
|
|
1336
1697
|
ctx.stack = [];
|
|
1337
|
-
refParam = serializeTree(ctx,
|
|
1698
|
+
refParam = serializeTree(ctx, values[i]);
|
|
1338
1699
|
ctx.stack = parentStack;
|
|
1339
|
-
key =
|
|
1700
|
+
key = keys[i];
|
|
1340
1701
|
check = Number(key);
|
|
1341
1702
|
parentAssignment = ctx.assignments;
|
|
1342
1703
|
ctx.assignments = mainAssignments;
|
|
@@ -1344,7 +1705,7 @@ function serializeAssignments(ctx, sourceID, node) {
|
|
|
1344
1705
|
if (isIdentifier && Number.isNaN(check)) {
|
|
1345
1706
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
1346
1707
|
} else {
|
|
1347
|
-
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' +
|
|
1708
|
+
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + key + '"', refParam);
|
|
1348
1709
|
}
|
|
1349
1710
|
ctx.assignments = parentAssignment;
|
|
1350
1711
|
}
|
|
@@ -1359,17 +1720,17 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1359
1720
|
markRef(ctx, i);
|
|
1360
1721
|
const assignments = serializeAssignments(ctx, i, d);
|
|
1361
1722
|
if (assignments) {
|
|
1362
|
-
return "(" +
|
|
1723
|
+
return "(" + assignIndexedValue2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
|
|
1363
1724
|
}
|
|
1364
1725
|
}
|
|
1365
1726
|
}
|
|
1366
|
-
return
|
|
1727
|
+
return assignIndexedValue2(ctx, i, init);
|
|
1367
1728
|
}
|
|
1368
1729
|
function serializeNullConstructor(ctx, node) {
|
|
1369
1730
|
return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
|
|
1370
1731
|
}
|
|
1371
1732
|
function serializeObject(ctx, node) {
|
|
1372
|
-
return
|
|
1733
|
+
return assignIndexedValue2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
|
|
1373
1734
|
}
|
|
1374
1735
|
function serializeSet(ctx, node) {
|
|
1375
1736
|
let serialized = "new Set";
|
|
@@ -1381,8 +1742,9 @@ function serializeSet(ctx, node) {
|
|
|
1381
1742
|
let hasPrev = false;
|
|
1382
1743
|
for (let i = 0; i < size; i++) {
|
|
1383
1744
|
item = node.a[i];
|
|
1384
|
-
if (
|
|
1385
|
-
|
|
1745
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1746
|
+
markRef(ctx, node.i);
|
|
1747
|
+
createAddAssignment(ctx, node.i, getRefParam(ctx, item.i));
|
|
1386
1748
|
} else {
|
|
1387
1749
|
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
1388
1750
|
hasPrev = true;
|
|
@@ -1393,7 +1755,7 @@ function serializeSet(ctx, node) {
|
|
|
1393
1755
|
serialized += "([" + result + "])";
|
|
1394
1756
|
}
|
|
1395
1757
|
}
|
|
1396
|
-
return
|
|
1758
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1397
1759
|
}
|
|
1398
1760
|
function serializeMap(ctx, node) {
|
|
1399
1761
|
let serialized = "new Map";
|
|
@@ -1409,22 +1771,24 @@ function serializeMap(ctx, node) {
|
|
|
1409
1771
|
for (let i = 0; i < node.d.s; i++) {
|
|
1410
1772
|
key = node.d.k[i];
|
|
1411
1773
|
val = node.d.v[i];
|
|
1412
|
-
if (
|
|
1774
|
+
if (isIndexedValueInStack(ctx, key)) {
|
|
1413
1775
|
keyRef = getRefParam(ctx, key.i);
|
|
1414
|
-
|
|
1776
|
+
markRef(ctx, node.i);
|
|
1777
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1415
1778
|
valueRef = getRefParam(ctx, val.i);
|
|
1416
|
-
|
|
1779
|
+
createSetAssignment(ctx, node.i, keyRef, valueRef);
|
|
1417
1780
|
} else {
|
|
1418
1781
|
parent = ctx.stack;
|
|
1419
1782
|
ctx.stack = [];
|
|
1420
|
-
|
|
1783
|
+
createSetAssignment(ctx, node.i, keyRef, serializeTree(ctx, val));
|
|
1421
1784
|
ctx.stack = parent;
|
|
1422
1785
|
}
|
|
1423
|
-
} else if (
|
|
1786
|
+
} else if (isIndexedValueInStack(ctx, val)) {
|
|
1424
1787
|
valueRef = getRefParam(ctx, val.i);
|
|
1788
|
+
markRef(ctx, node.i);
|
|
1425
1789
|
parent = ctx.stack;
|
|
1426
1790
|
ctx.stack = [];
|
|
1427
|
-
|
|
1791
|
+
createSetAssignment(ctx, node.i, serializeTree(ctx, key), valueRef);
|
|
1428
1792
|
ctx.stack = parent;
|
|
1429
1793
|
} else {
|
|
1430
1794
|
result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
@@ -1436,21 +1800,21 @@ function serializeMap(ctx, node) {
|
|
|
1436
1800
|
serialized += "([" + result + "])";
|
|
1437
1801
|
}
|
|
1438
1802
|
}
|
|
1439
|
-
return
|
|
1803
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1440
1804
|
}
|
|
1441
1805
|
function serializeAggregateError(ctx, node) {
|
|
1442
1806
|
ctx.stack.push(node.i);
|
|
1443
|
-
const serialized =
|
|
1807
|
+
const serialized = 'new AggregateError([],"' + node.m + '")';
|
|
1444
1808
|
ctx.stack.pop();
|
|
1445
1809
|
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
1446
1810
|
}
|
|
1447
1811
|
function serializeError(ctx, node) {
|
|
1448
|
-
const serialized = "new " + node.c + '("' +
|
|
1812
|
+
const serialized = "new " + node.c + '("' + node.m + '")';
|
|
1449
1813
|
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
1450
1814
|
}
|
|
1451
1815
|
function serializePromise(ctx, node) {
|
|
1452
1816
|
let serialized;
|
|
1453
|
-
if (
|
|
1817
|
+
if (isIndexedValueInStack(ctx, node.f)) {
|
|
1454
1818
|
const ref = getRefParam(ctx, node.f.i);
|
|
1455
1819
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1456
1820
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
@@ -1463,16 +1827,22 @@ function serializePromise(ctx, node) {
|
|
|
1463
1827
|
ctx.stack.pop();
|
|
1464
1828
|
serialized = "Promise.resolve(" + result + ")";
|
|
1465
1829
|
}
|
|
1466
|
-
return
|
|
1830
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1467
1831
|
}
|
|
1468
|
-
function
|
|
1469
|
-
let result = "";
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1832
|
+
function serializeArrayBuffer2(ctx, node) {
|
|
1833
|
+
let result = "new Uint8Array(";
|
|
1834
|
+
if (node.s.length) {
|
|
1835
|
+
result += "[";
|
|
1836
|
+
for (let i = 0, len = node.s.length; i < len; i++) {
|
|
1837
|
+
result += (i > 0 ? "," : "") + node.s[i];
|
|
1838
|
+
}
|
|
1839
|
+
result += "]";
|
|
1473
1840
|
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1841
|
+
return assignIndexedValue2(ctx, node.i, result + ").buffer");
|
|
1842
|
+
}
|
|
1843
|
+
function serializeTypedArray(ctx, node) {
|
|
1844
|
+
const args = serializeTree(ctx, node.f) + "," + node.b + "," + node.l;
|
|
1845
|
+
return assignIndexedValue2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1476
1846
|
}
|
|
1477
1847
|
function serializeIterable(ctx, node) {
|
|
1478
1848
|
const parent = ctx.stack;
|
|
@@ -1494,6 +1864,68 @@ function serializeIterable(ctx, node) {
|
|
|
1494
1864
|
}
|
|
1495
1865
|
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
1496
1866
|
}
|
|
1867
|
+
function serializeDate(ctx, node) {
|
|
1868
|
+
return assignIndexedValue2(ctx, node.i, 'new Date("' + node.s + '")');
|
|
1869
|
+
}
|
|
1870
|
+
function serializeRegExp(ctx, node) {
|
|
1871
|
+
return assignIndexedValue2(ctx, node.i, "/" + node.c + "/" + node.m);
|
|
1872
|
+
}
|
|
1873
|
+
function serializeURL(ctx, node) {
|
|
1874
|
+
return assignIndexedValue2(ctx, node.i, 'new URL("' + node.s + '")');
|
|
1875
|
+
}
|
|
1876
|
+
function serializeURLSearchParams(ctx, node) {
|
|
1877
|
+
return assignIndexedValue2(ctx, node.i, node.s ? 'new URLSearchParams("' + node.s + '")' : "new URLSearchParams");
|
|
1878
|
+
}
|
|
1879
|
+
function serializeReference(ctx, node) {
|
|
1880
|
+
return assignIndexedValue2(ctx, node.i, GLOBAL_KEY + '.get("' + node.s + '")');
|
|
1881
|
+
}
|
|
1882
|
+
function serializeDataView(ctx, node) {
|
|
1883
|
+
const args = serializeTree(ctx, node.f) + "," + node.b + "," + node.l;
|
|
1884
|
+
return assignIndexedValue2(ctx, node.i, "new DataView(" + args + ")");
|
|
1885
|
+
}
|
|
1886
|
+
function serializeBlob(ctx, node) {
|
|
1887
|
+
const args = "[" + serializeTree(ctx, node.f) + '],{type:"' + node.c + '"}';
|
|
1888
|
+
return assignIndexedValue2(ctx, node.i, "new Blob(" + args + ")");
|
|
1889
|
+
}
|
|
1890
|
+
function serializeFile(ctx, node) {
|
|
1891
|
+
const options = '{type:"' + node.c + '",lastModified:' + node.b + "}";
|
|
1892
|
+
const args = "[" + serializeTree(ctx, node.f) + '],"' + node.m + '",' + options;
|
|
1893
|
+
return assignIndexedValue2(ctx, node.i, "new File(" + args + ")");
|
|
1894
|
+
}
|
|
1895
|
+
function serializeHeaders(ctx, node) {
|
|
1896
|
+
return assignIndexedValue2(ctx, node.i, "new Headers(" + serializeProperties(ctx, node.i, node.d) + ")");
|
|
1897
|
+
}
|
|
1898
|
+
function serializeFormDataEntries(ctx, node) {
|
|
1899
|
+
ctx.stack.push(node.i);
|
|
1900
|
+
const mainAssignments = [];
|
|
1901
|
+
let parentStack;
|
|
1902
|
+
let value;
|
|
1903
|
+
let key;
|
|
1904
|
+
let parentAssignment;
|
|
1905
|
+
for (let i = 0; i < node.d.s; i++) {
|
|
1906
|
+
parentStack = ctx.stack;
|
|
1907
|
+
ctx.stack = [];
|
|
1908
|
+
value = serializeTree(ctx, node.d.v[i]);
|
|
1909
|
+
key = node.d.k[i];
|
|
1910
|
+
ctx.stack = parentStack;
|
|
1911
|
+
parentAssignment = ctx.assignments;
|
|
1912
|
+
ctx.assignments = mainAssignments;
|
|
1913
|
+
createAppendAssignment(ctx, node.i, '"' + key + '"', value);
|
|
1914
|
+
ctx.assignments = parentAssignment;
|
|
1915
|
+
}
|
|
1916
|
+
ctx.stack.pop();
|
|
1917
|
+
return resolveAssignments(mainAssignments);
|
|
1918
|
+
}
|
|
1919
|
+
function serializeFormData(ctx, node) {
|
|
1920
|
+
if (node.d.s) {
|
|
1921
|
+
markRef(ctx, node.i);
|
|
1922
|
+
}
|
|
1923
|
+
const result = assignIndexedValue2(ctx, node.i, "new FormData()");
|
|
1924
|
+
if (node.d.s) {
|
|
1925
|
+
return "(" + result + "," + serializeFormDataEntries(ctx, node) + getRefParam(ctx, node.i) + ")";
|
|
1926
|
+
}
|
|
1927
|
+
return result;
|
|
1928
|
+
}
|
|
1497
1929
|
function serializeTree(ctx, node) {
|
|
1498
1930
|
switch (node.t) {
|
|
1499
1931
|
case 0 /* Number */:
|
|
@@ -1516,7 +1948,7 @@ function serializeTree(ctx, node) {
|
|
|
1516
1948
|
return "NaN";
|
|
1517
1949
|
case 9 /* BigInt */:
|
|
1518
1950
|
return node.s + "n";
|
|
1519
|
-
case 10 /*
|
|
1951
|
+
case 10 /* IndexedValue */:
|
|
1520
1952
|
return getRefParam(ctx, node.i);
|
|
1521
1953
|
case 15 /* Array */:
|
|
1522
1954
|
return serializeArray(ctx, node);
|
|
@@ -1525,16 +1957,20 @@ function serializeTree(ctx, node) {
|
|
|
1525
1957
|
case 17 /* NullConstructor */:
|
|
1526
1958
|
return serializeNullConstructor(ctx, node);
|
|
1527
1959
|
case 11 /* Date */:
|
|
1528
|
-
return
|
|
1960
|
+
return serializeDate(ctx, node);
|
|
1529
1961
|
case 12 /* RegExp */:
|
|
1530
|
-
return
|
|
1962
|
+
return serializeRegExp(ctx, node);
|
|
1531
1963
|
case 13 /* Set */:
|
|
1532
1964
|
return serializeSet(ctx, node);
|
|
1533
1965
|
case 14 /* Map */:
|
|
1534
1966
|
return serializeMap(ctx, node);
|
|
1967
|
+
case 28 /* ArrayBuffer */:
|
|
1968
|
+
return serializeArrayBuffer2(ctx, node);
|
|
1535
1969
|
case 23 /* BigIntTypedArray */:
|
|
1536
1970
|
case 22 /* TypedArray */:
|
|
1537
1971
|
return serializeTypedArray(ctx, node);
|
|
1972
|
+
case 29 /* DataView */:
|
|
1973
|
+
return serializeDataView(ctx, node);
|
|
1538
1974
|
case 20 /* AggregateError */:
|
|
1539
1975
|
return serializeAggregateError(ctx, node);
|
|
1540
1976
|
case 19 /* Error */:
|
|
@@ -1545,6 +1981,20 @@ function serializeTree(ctx, node) {
|
|
|
1545
1981
|
return serializePromise(ctx, node);
|
|
1546
1982
|
case 24 /* WKSymbol */:
|
|
1547
1983
|
return SYMBOL_STRING[node.s];
|
|
1984
|
+
case 25 /* URL */:
|
|
1985
|
+
return serializeURL(ctx, node);
|
|
1986
|
+
case 26 /* URLSearchParams */:
|
|
1987
|
+
return serializeURLSearchParams(ctx, node);
|
|
1988
|
+
case 27 /* Reference */:
|
|
1989
|
+
return serializeReference(ctx, node);
|
|
1990
|
+
case 30 /* Blob */:
|
|
1991
|
+
return serializeBlob(ctx, node);
|
|
1992
|
+
case 31 /* File */:
|
|
1993
|
+
return serializeFile(ctx, node);
|
|
1994
|
+
case 32 /* Headers */:
|
|
1995
|
+
return serializeHeaders(ctx, node);
|
|
1996
|
+
case 33 /* FormData */:
|
|
1997
|
+
return serializeFormData(ctx, node);
|
|
1548
1998
|
default:
|
|
1549
1999
|
throw new Error("Unsupported type");
|
|
1550
2000
|
}
|
|
@@ -1583,7 +2033,8 @@ function generateArrayNode2(ctx, id, current) {
|
|
|
1583
2033
|
m: void 0,
|
|
1584
2034
|
d: void 0,
|
|
1585
2035
|
a: generateNodeList2(ctx, current),
|
|
1586
|
-
f: void 0
|
|
2036
|
+
f: void 0,
|
|
2037
|
+
b: void 0
|
|
1587
2038
|
};
|
|
1588
2039
|
}
|
|
1589
2040
|
function generateMapNode2(ctx, id, current) {
|
|
@@ -1619,7 +2070,8 @@ function generateMapNode2(ctx, id, current) {
|
|
|
1619
2070
|
m: void 0,
|
|
1620
2071
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1621
2072
|
a: void 0,
|
|
1622
|
-
f: void 0
|
|
2073
|
+
f: void 0,
|
|
2074
|
+
b: void 0
|
|
1623
2075
|
};
|
|
1624
2076
|
}
|
|
1625
2077
|
function generateSetNode2(ctx, id, current) {
|
|
@@ -1648,7 +2100,8 @@ function generateSetNode2(ctx, id, current) {
|
|
|
1648
2100
|
m: void 0,
|
|
1649
2101
|
d: void 0,
|
|
1650
2102
|
a: nodes,
|
|
1651
|
-
f: void 0
|
|
2103
|
+
f: void 0,
|
|
2104
|
+
b: void 0
|
|
1652
2105
|
};
|
|
1653
2106
|
}
|
|
1654
2107
|
function generateProperties2(ctx, properties) {
|
|
@@ -1661,14 +2114,16 @@ function generateProperties2(ctx, properties) {
|
|
|
1661
2114
|
let deferredSize = 0;
|
|
1662
2115
|
let nodesSize = 0;
|
|
1663
2116
|
let item;
|
|
2117
|
+
let escaped;
|
|
1664
2118
|
for (const key of keys) {
|
|
1665
2119
|
item = properties[key];
|
|
2120
|
+
escaped = serializeString(key);
|
|
1666
2121
|
if (isIterable(item)) {
|
|
1667
|
-
deferredKeys[deferredSize] =
|
|
2122
|
+
deferredKeys[deferredSize] = escaped;
|
|
1668
2123
|
deferredValues[deferredSize] = item;
|
|
1669
2124
|
deferredSize++;
|
|
1670
2125
|
} else {
|
|
1671
|
-
keyNodes[nodesSize] =
|
|
2126
|
+
keyNodes[nodesSize] = escaped;
|
|
1672
2127
|
valueNodes[nodesSize] = parse2(ctx, item);
|
|
1673
2128
|
nodesSize++;
|
|
1674
2129
|
}
|
|
@@ -1697,7 +2152,8 @@ function generateIterableNode2(ctx, id, current) {
|
|
|
1697
2152
|
// Parse options first before the items
|
|
1698
2153
|
d: options ? generateProperties2(ctx, options) : void 0,
|
|
1699
2154
|
a: generateNodeList2(ctx, array),
|
|
1700
|
-
f: void 0
|
|
2155
|
+
f: void 0,
|
|
2156
|
+
b: void 0
|
|
1701
2157
|
};
|
|
1702
2158
|
}
|
|
1703
2159
|
function generateObjectNode2(ctx, id, current, empty) {
|
|
@@ -1713,7 +2169,8 @@ function generateObjectNode2(ctx, id, current, empty) {
|
|
|
1713
2169
|
m: void 0,
|
|
1714
2170
|
d: generateProperties2(ctx, current),
|
|
1715
2171
|
a: void 0,
|
|
1716
|
-
f: void 0
|
|
2172
|
+
f: void 0,
|
|
2173
|
+
b: void 0
|
|
1717
2174
|
};
|
|
1718
2175
|
}
|
|
1719
2176
|
function generateAggregateErrorNode2(ctx, id, current) {
|
|
@@ -1723,12 +2180,13 @@ function generateAggregateErrorNode2(ctx, id, current) {
|
|
|
1723
2180
|
t: 20 /* AggregateError */,
|
|
1724
2181
|
i: id,
|
|
1725
2182
|
s: void 0,
|
|
1726
|
-
l:
|
|
2183
|
+
l: void 0,
|
|
1727
2184
|
c: void 0,
|
|
1728
|
-
m: current.message,
|
|
2185
|
+
m: serializeString(current.message),
|
|
1729
2186
|
d: optionsNode,
|
|
1730
|
-
a:
|
|
1731
|
-
f: void 0
|
|
2187
|
+
a: void 0,
|
|
2188
|
+
f: void 0,
|
|
2189
|
+
b: void 0
|
|
1732
2190
|
};
|
|
1733
2191
|
}
|
|
1734
2192
|
function generateErrorNode2(ctx, id, current) {
|
|
@@ -1740,10 +2198,49 @@ function generateErrorNode2(ctx, id, current) {
|
|
|
1740
2198
|
s: void 0,
|
|
1741
2199
|
l: void 0,
|
|
1742
2200
|
c: getErrorConstructorName(current),
|
|
1743
|
-
m: current.message,
|
|
2201
|
+
m: serializeString(current.message),
|
|
1744
2202
|
d: optionsNode,
|
|
1745
2203
|
a: void 0,
|
|
1746
|
-
f: void 0
|
|
2204
|
+
f: void 0,
|
|
2205
|
+
b: void 0
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
function generateHeadersNode2(ctx, id, current) {
|
|
2209
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "Headers"');
|
|
2210
|
+
const items = {};
|
|
2211
|
+
current.forEach((value, key) => {
|
|
2212
|
+
items[key] = value;
|
|
2213
|
+
});
|
|
2214
|
+
return {
|
|
2215
|
+
t: 32 /* Headers */,
|
|
2216
|
+
i: id,
|
|
2217
|
+
s: void 0,
|
|
2218
|
+
l: void 0,
|
|
2219
|
+
c: void 0,
|
|
2220
|
+
m: void 0,
|
|
2221
|
+
d: generateProperties2(ctx, items),
|
|
2222
|
+
a: void 0,
|
|
2223
|
+
f: void 0,
|
|
2224
|
+
b: void 0
|
|
2225
|
+
};
|
|
2226
|
+
}
|
|
2227
|
+
function generateFormDataNode2(ctx, id, current) {
|
|
2228
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "FormData"');
|
|
2229
|
+
const items = {};
|
|
2230
|
+
current.forEach((value, key) => {
|
|
2231
|
+
items[key] = value;
|
|
2232
|
+
});
|
|
2233
|
+
return {
|
|
2234
|
+
t: 33 /* FormData */,
|
|
2235
|
+
i: id,
|
|
2236
|
+
s: void 0,
|
|
2237
|
+
l: void 0,
|
|
2238
|
+
c: void 0,
|
|
2239
|
+
m: void 0,
|
|
2240
|
+
d: generateProperties2(ctx, items),
|
|
2241
|
+
a: void 0,
|
|
2242
|
+
f: void 0,
|
|
2243
|
+
b: void 0
|
|
1747
2244
|
};
|
|
1748
2245
|
}
|
|
1749
2246
|
function parse2(ctx, current) {
|
|
@@ -1761,24 +2258,26 @@ function parse2(ctx, current) {
|
|
|
1761
2258
|
case -Infinity:
|
|
1762
2259
|
return NEG_INFINITY_NODE;
|
|
1763
2260
|
default:
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
2261
|
+
if (current !== current) {
|
|
2262
|
+
return NAN_NODE;
|
|
2263
|
+
}
|
|
2264
|
+
if (Object.is(current, -0)) {
|
|
2265
|
+
return NEG_ZERO_NODE;
|
|
2266
|
+
}
|
|
2267
|
+
return createNumberNode(current);
|
|
1771
2268
|
}
|
|
1772
|
-
return createNumberNode(current);
|
|
1773
2269
|
case "bigint":
|
|
1774
2270
|
return createBigIntNode(ctx, current);
|
|
1775
2271
|
case "object": {
|
|
1776
2272
|
if (!current) {
|
|
1777
2273
|
return NULL_NODE;
|
|
1778
2274
|
}
|
|
1779
|
-
const id =
|
|
2275
|
+
const id = createIndexedValue(ctx, current);
|
|
1780
2276
|
if (ctx.markedRefs.has(id)) {
|
|
1781
|
-
return
|
|
2277
|
+
return createIndexedValueNode(id);
|
|
2278
|
+
}
|
|
2279
|
+
if (hasReferenceID(current)) {
|
|
2280
|
+
return createReferenceNode(id, current);
|
|
1782
2281
|
}
|
|
1783
2282
|
if (Array.isArray(current)) {
|
|
1784
2283
|
return generateArrayNode2(ctx, id, current);
|
|
@@ -1788,6 +2287,8 @@ function parse2(ctx, current) {
|
|
|
1788
2287
|
return createDateNode(id, current);
|
|
1789
2288
|
case RegExp:
|
|
1790
2289
|
return createRegExpNode(id, current);
|
|
2290
|
+
case ArrayBuffer:
|
|
2291
|
+
return createArrayBufferNode(id, current);
|
|
1791
2292
|
case Int8Array:
|
|
1792
2293
|
case Int16Array:
|
|
1793
2294
|
case Int32Array:
|
|
@@ -1801,14 +2302,26 @@ function parse2(ctx, current) {
|
|
|
1801
2302
|
case BigInt64Array:
|
|
1802
2303
|
case BigUint64Array:
|
|
1803
2304
|
return createBigIntTypedArrayNode(ctx, id, current);
|
|
2305
|
+
case DataView:
|
|
2306
|
+
return createDataViewNode(ctx, id, current);
|
|
1804
2307
|
case Map:
|
|
1805
2308
|
return generateMapNode2(ctx, id, current);
|
|
1806
2309
|
case Set:
|
|
1807
2310
|
return generateSetNode2(ctx, id, current);
|
|
1808
2311
|
case Object:
|
|
1809
|
-
return generateObjectNode2(
|
|
2312
|
+
return generateObjectNode2(
|
|
2313
|
+
ctx,
|
|
2314
|
+
id,
|
|
2315
|
+
current,
|
|
2316
|
+
false
|
|
2317
|
+
);
|
|
1810
2318
|
case void 0:
|
|
1811
|
-
return generateObjectNode2(
|
|
2319
|
+
return generateObjectNode2(
|
|
2320
|
+
ctx,
|
|
2321
|
+
id,
|
|
2322
|
+
current,
|
|
2323
|
+
true
|
|
2324
|
+
);
|
|
1812
2325
|
case AggregateError:
|
|
1813
2326
|
if (ctx.features & 1 /* AggregateError */) {
|
|
1814
2327
|
return generateAggregateErrorNode2(ctx, id, current);
|
|
@@ -1822,6 +2335,14 @@ function parse2(ctx, current) {
|
|
|
1822
2335
|
case TypeError:
|
|
1823
2336
|
case URIError:
|
|
1824
2337
|
return generateErrorNode2(ctx, id, current);
|
|
2338
|
+
case URL:
|
|
2339
|
+
return createURLNode(ctx, id, current);
|
|
2340
|
+
case URLSearchParams:
|
|
2341
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
2342
|
+
case Headers:
|
|
2343
|
+
return generateHeadersNode2(ctx, id, current);
|
|
2344
|
+
case FormData:
|
|
2345
|
+
return generateFormDataNode2(ctx, id, current);
|
|
1825
2346
|
default:
|
|
1826
2347
|
break;
|
|
1827
2348
|
}
|
|
@@ -1840,9 +2361,22 @@ function parse2(ctx, current) {
|
|
|
1840
2361
|
throw new Error("Unsupported type");
|
|
1841
2362
|
}
|
|
1842
2363
|
case "symbol":
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
2364
|
+
if (hasReferenceID(current)) {
|
|
2365
|
+
const id = createIndexedValue(ctx, current);
|
|
2366
|
+
if (ctx.markedRefs.has(id)) {
|
|
2367
|
+
return createIndexedValueNode(id);
|
|
2368
|
+
}
|
|
2369
|
+
return createReferenceNode(id, current);
|
|
2370
|
+
}
|
|
2371
|
+
return createWKSymbolNode(ctx, current);
|
|
2372
|
+
case "function": {
|
|
2373
|
+
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
2374
|
+
const id = createIndexedValue(ctx, current);
|
|
2375
|
+
if (ctx.markedRefs.has(id)) {
|
|
2376
|
+
return createIndexedValueNode(id);
|
|
2377
|
+
}
|
|
2378
|
+
return createReferenceNode(id, current);
|
|
2379
|
+
}
|
|
1846
2380
|
default:
|
|
1847
2381
|
throw new Error("Unsupported type");
|
|
1848
2382
|
}
|