seroval 1.2.1 → 1.3.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 +1 -1
- package/dist/cjs/development/index.cjs +270 -383
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +6 -6
- package/dist/esm/development/index.mjs +270 -383
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +6 -6
- package/dist/types/core/base-primitives.d.ts +1 -2
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/compat.d.ts +2 -3
- package/dist/types/core/compat.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +3 -6
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts +0 -3
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser/async.d.ts +1 -2
- package/dist/types/core/context/parser/async.d.ts.map +1 -1
- package/dist/types/core/context/parser/stream.d.ts +8 -8
- package/dist/types/core/context/parser/stream.d.ts.map +1 -1
- package/dist/types/core/context/parser/sync.d.ts +2 -3
- package/dist/types/core/context/parser/sync.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +3 -3
- package/dist/types/core/context/parser.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts +1 -5
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/function-string.d.ts +3 -0
- package/dist/types/core/function-string.d.ts.map +1 -0
- package/dist/types/core/special-reference.d.ts +4 -5
- package/dist/types/core/special-reference.d.ts.map +1 -1
- package/dist/types/core/tree/serializer.d.ts +1 -2
- package/dist/types/core/tree/serializer.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +5 -19
- package/dist/types/core/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/core/base-primitives.ts +2 -22
- package/src/core/compat.ts +6 -2
- package/src/core/constants.ts +2 -5
- package/src/core/context/deserializer.ts +2 -35
- package/src/core/context/parser/async.ts +54 -83
- package/src/core/context/parser/stream.ts +64 -111
- package/src/core/context/parser/sync.ts +53 -83
- package/src/core/context/parser.ts +9 -24
- package/src/core/context/serializer.ts +24 -131
- package/src/core/function-string.ts +31 -0
- package/src/core/special-reference.ts +96 -8
- package/src/core/tree/serializer.ts +0 -7
- package/src/core/types.ts +5 -27
- package/dist/types/core/abort-signal.d.ts +0 -2
- package/dist/types/core/abort-signal.d.ts.map +0 -1
- package/src/core/abort-signal.ts +0 -19
|
@@ -63,10 +63,9 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
|
|
|
63
63
|
Feature2[Feature2["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
|
|
64
64
|
Feature2[Feature2["ObjectAssign"] = 8] = "ObjectAssign";
|
|
65
65
|
Feature2[Feature2["BigIntTypedArray"] = 16] = "BigIntTypedArray";
|
|
66
|
-
Feature2[Feature2["AbortSignal"] = 32] = "AbortSignal";
|
|
67
66
|
return Feature2;
|
|
68
67
|
})(Feature || {});
|
|
69
|
-
var ALL_ENABLED =
|
|
68
|
+
var ALL_ENABLED = 1 /* AggregateError */ | 2 /* ArrowFunction */ | 4 /* ErrorPrototypeStack */ | 8 /* ObjectAssign */ | 16 /* BigIntTypedArray */;
|
|
70
69
|
|
|
71
70
|
// src/core/string.ts
|
|
72
71
|
function serializeChar(str) {
|
|
@@ -242,19 +241,6 @@ function resolvePlugins(plugins) {
|
|
|
242
241
|
return void 0;
|
|
243
242
|
}
|
|
244
243
|
|
|
245
|
-
// src/core/abort-signal.ts
|
|
246
|
-
function resolveAbortSignalResult(resolve) {
|
|
247
|
-
resolve(this.reason);
|
|
248
|
-
}
|
|
249
|
-
function resolveAbortSignal(resolve) {
|
|
250
|
-
this.addEventListener("abort", resolveAbortSignalResult.bind(this, resolve), {
|
|
251
|
-
once: true
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
function abortSignalToPromise(signal) {
|
|
255
|
-
return new Promise(resolveAbortSignal.bind(signal));
|
|
256
|
-
}
|
|
257
|
-
|
|
258
244
|
// src/core/constants.ts
|
|
259
245
|
var SYMBOL_STRING = {
|
|
260
246
|
[0 /* AsyncIterator */]: "Symbol.asyncIterator",
|
|
@@ -543,10 +529,11 @@ function createIndexedValueNode(id) {
|
|
|
543
529
|
);
|
|
544
530
|
}
|
|
545
531
|
function createDateNode(id, current) {
|
|
532
|
+
const timestamp = current.valueOf();
|
|
546
533
|
return createSerovalNode(
|
|
547
534
|
5 /* Date */,
|
|
548
535
|
id,
|
|
549
|
-
current.toISOString(),
|
|
536
|
+
timestamp !== timestamp ? "" : current.toISOString(),
|
|
550
537
|
NIL,
|
|
551
538
|
NIL,
|
|
552
539
|
NIL,
|
|
@@ -962,18 +949,96 @@ var OpaqueReference = class {
|
|
|
962
949
|
}
|
|
963
950
|
};
|
|
964
951
|
|
|
952
|
+
// src/core/function-string.ts
|
|
953
|
+
function createFunction(features, parameters, body) {
|
|
954
|
+
if (features & 2 /* ArrowFunction */) {
|
|
955
|
+
const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
|
|
956
|
+
return joined + "=>" + (body.startsWith("{") ? "(" + body + ")" : body);
|
|
957
|
+
}
|
|
958
|
+
return "function(" + parameters.join(",") + "){return " + body + "}";
|
|
959
|
+
}
|
|
960
|
+
function createEffectfulFunction(features, parameters, body) {
|
|
961
|
+
if (features & 2 /* ArrowFunction */) {
|
|
962
|
+
const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
|
|
963
|
+
return joined + "=>{" + body + "}";
|
|
964
|
+
}
|
|
965
|
+
return "function(" + parameters.join(",") + "){" + body + "}";
|
|
966
|
+
}
|
|
967
|
+
|
|
965
968
|
// src/core/special-reference.ts
|
|
966
969
|
var ITERATOR = {};
|
|
967
970
|
var ASYNC_ITERATOR = {};
|
|
968
971
|
var SPECIAL_REFS = {
|
|
969
972
|
[0 /* MapSentinel */]: {},
|
|
970
973
|
[1 /* PromiseConstructor */]: {},
|
|
971
|
-
[2 /*
|
|
972
|
-
[3 /*
|
|
973
|
-
[4 /* StreamConstructor */]: {}
|
|
974
|
-
[5 /* AbortSignalConstructor */]: {},
|
|
975
|
-
[6 /* AbortSignalAbort */]: {}
|
|
974
|
+
[2 /* PromiseSuccess */]: {},
|
|
975
|
+
[3 /* PromiseFailure */]: {},
|
|
976
|
+
[4 /* StreamConstructor */]: {}
|
|
976
977
|
};
|
|
978
|
+
function serializePromiseConstructor(features) {
|
|
979
|
+
return createFunction(
|
|
980
|
+
features,
|
|
981
|
+
["r"],
|
|
982
|
+
"(r.p=new Promise(" + createEffectfulFunction(features, ["s", "f"], "r.s=s,r.f=f") + "))"
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
function serializePromiseSuccess(features) {
|
|
986
|
+
return createEffectfulFunction(
|
|
987
|
+
features,
|
|
988
|
+
["r", "d"],
|
|
989
|
+
"r.s(d),r.p.s=1,r.p.v=d"
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
function serializePromiseFailure(features) {
|
|
993
|
+
return createEffectfulFunction(
|
|
994
|
+
features,
|
|
995
|
+
["r", "d"],
|
|
996
|
+
"r.f(d),r.p.s=2,r.p.v=d"
|
|
997
|
+
);
|
|
998
|
+
}
|
|
999
|
+
function serializeStreamConstructor(features) {
|
|
1000
|
+
return createFunction(
|
|
1001
|
+
features,
|
|
1002
|
+
["b", "a", "s", "l", "p", "f", "e", "n"],
|
|
1003
|
+
"(b=[],a=!0,s=!1,l=[],p=0,f=" + createEffectfulFunction(
|
|
1004
|
+
features,
|
|
1005
|
+
["v", "m", "x"],
|
|
1006
|
+
"for(x=0;x<p;x++)l[x]&&l[x][m](v)"
|
|
1007
|
+
) + ",n=" + createEffectfulFunction(
|
|
1008
|
+
features,
|
|
1009
|
+
["o", "x", "z", "c"],
|
|
1010
|
+
'for(x=0,z=b.length;x<z;x++)(c=b[x],(!a&&x===z-1)?o[s?"return":"throw"](c):o.next(c))'
|
|
1011
|
+
) + ",e=" + createFunction(
|
|
1012
|
+
features,
|
|
1013
|
+
["o", "t"],
|
|
1014
|
+
"(a&&(l[t=p++]=o),n(o)," + createEffectfulFunction(features, [], "a&&(l[t]=void 0)") + ")"
|
|
1015
|
+
) + ",{__SEROVAL_STREAM__:!0,on:" + createFunction(features, ["o"], "e(o)") + ",next:" + createEffectfulFunction(features, ["v"], 'a&&(b.push(v),f(v,"next"))') + ",throw:" + createEffectfulFunction(
|
|
1016
|
+
features,
|
|
1017
|
+
["v"],
|
|
1018
|
+
'a&&(b.push(v),f(v,"throw"),a=s=!1,l.length=0)'
|
|
1019
|
+
) + ",return:" + createEffectfulFunction(
|
|
1020
|
+
features,
|
|
1021
|
+
["v"],
|
|
1022
|
+
'a&&(b.push(v),f(v,"return"),a=!1,s=!0,l.length=0)'
|
|
1023
|
+
) + "})"
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
function serializeSpecialReferenceValue(features, ref) {
|
|
1027
|
+
switch (ref) {
|
|
1028
|
+
case 0 /* MapSentinel */:
|
|
1029
|
+
return "[]";
|
|
1030
|
+
case 1 /* PromiseConstructor */:
|
|
1031
|
+
return serializePromiseConstructor(features);
|
|
1032
|
+
case 2 /* PromiseSuccess */:
|
|
1033
|
+
return serializePromiseSuccess(features);
|
|
1034
|
+
case 3 /* PromiseFailure */:
|
|
1035
|
+
return serializePromiseFailure(features);
|
|
1036
|
+
case 4 /* StreamConstructor */:
|
|
1037
|
+
return serializeStreamConstructor(features);
|
|
1038
|
+
default:
|
|
1039
|
+
return "";
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
977
1042
|
|
|
978
1043
|
// src/core/utils/deferred.ts
|
|
979
1044
|
function createDeferred() {
|
|
@@ -1237,6 +1302,11 @@ var BaseParserContext = class {
|
|
|
1237
1302
|
isMarked(id) {
|
|
1238
1303
|
return this.marked.has(id);
|
|
1239
1304
|
}
|
|
1305
|
+
createIndex(current) {
|
|
1306
|
+
const id = this.refs.size;
|
|
1307
|
+
this.refs.set(current, id);
|
|
1308
|
+
return id;
|
|
1309
|
+
}
|
|
1240
1310
|
getIndexedValue(current) {
|
|
1241
1311
|
const registeredId = this.refs.get(current);
|
|
1242
1312
|
if (registeredId != null) {
|
|
@@ -1246,11 +1316,9 @@ var BaseParserContext = class {
|
|
|
1246
1316
|
value: createIndexedValueNode(registeredId)
|
|
1247
1317
|
};
|
|
1248
1318
|
}
|
|
1249
|
-
const id = this.refs.size;
|
|
1250
|
-
this.refs.set(current, id);
|
|
1251
1319
|
return {
|
|
1252
1320
|
type: 0 /* Fresh */,
|
|
1253
|
-
value:
|
|
1321
|
+
value: this.createIndex(current)
|
|
1254
1322
|
};
|
|
1255
1323
|
}
|
|
1256
1324
|
getReference(current) {
|
|
@@ -1369,11 +1437,11 @@ var BaseParserContext = class {
|
|
|
1369
1437
|
NIL
|
|
1370
1438
|
);
|
|
1371
1439
|
}
|
|
1372
|
-
createPromiseConstructorNode(id) {
|
|
1440
|
+
createPromiseConstructorNode(id, resolver) {
|
|
1373
1441
|
return createSerovalNode(
|
|
1374
1442
|
22 /* PromiseConstructor */,
|
|
1375
1443
|
id,
|
|
1376
|
-
|
|
1444
|
+
resolver,
|
|
1377
1445
|
NIL,
|
|
1378
1446
|
NIL,
|
|
1379
1447
|
NIL,
|
|
@@ -1385,22 +1453,6 @@ var BaseParserContext = class {
|
|
|
1385
1453
|
NIL
|
|
1386
1454
|
);
|
|
1387
1455
|
}
|
|
1388
|
-
createAbortSignalConstructorNode(id) {
|
|
1389
|
-
return createSerovalNode(
|
|
1390
|
-
35 /* AbortSignalConstructor */,
|
|
1391
|
-
id,
|
|
1392
|
-
NIL,
|
|
1393
|
-
NIL,
|
|
1394
|
-
NIL,
|
|
1395
|
-
NIL,
|
|
1396
|
-
NIL,
|
|
1397
|
-
NIL,
|
|
1398
|
-
NIL,
|
|
1399
|
-
this.parseSpecialReference(5 /* AbortSignalConstructor */),
|
|
1400
|
-
NIL,
|
|
1401
|
-
NIL
|
|
1402
|
-
);
|
|
1403
|
-
}
|
|
1404
1456
|
};
|
|
1405
1457
|
|
|
1406
1458
|
// src/core/context/parser/async.ts
|
|
@@ -1409,7 +1461,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1409
1461
|
const nodes = [];
|
|
1410
1462
|
for (let i = 0, len = current.length; i < len; i++) {
|
|
1411
1463
|
if (i in current) {
|
|
1412
|
-
nodes[i] = await this.
|
|
1464
|
+
nodes[i] = await this.parseTop(current[i]);
|
|
1413
1465
|
}
|
|
1414
1466
|
}
|
|
1415
1467
|
return nodes;
|
|
@@ -1423,7 +1475,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1423
1475
|
const valueNodes = [];
|
|
1424
1476
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
1425
1477
|
keyNodes.push(serializeString(entries[i][0]));
|
|
1426
|
-
valueNodes.push(await this.
|
|
1478
|
+
valueNodes.push(await this.parseTop(entries[i][1]));
|
|
1427
1479
|
}
|
|
1428
1480
|
let symbol = Symbol.iterator;
|
|
1429
1481
|
if (symbol in properties) {
|
|
@@ -1431,7 +1483,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1431
1483
|
valueNodes.push(
|
|
1432
1484
|
createIteratorFactoryInstanceNode(
|
|
1433
1485
|
this.parseIteratorFactory(),
|
|
1434
|
-
await this.
|
|
1486
|
+
await this.parseTop(
|
|
1435
1487
|
iteratorToSequence(properties)
|
|
1436
1488
|
)
|
|
1437
1489
|
)
|
|
@@ -1443,7 +1495,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1443
1495
|
valueNodes.push(
|
|
1444
1496
|
createAsyncIteratorFactoryInstanceNode(
|
|
1445
1497
|
this.parseAsyncIteratorFactory(),
|
|
1446
|
-
await this.
|
|
1498
|
+
await this.parseTop(
|
|
1447
1499
|
createStreamFromAsyncIterable(
|
|
1448
1500
|
properties
|
|
1449
1501
|
)
|
|
@@ -1476,20 +1528,24 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1476
1528
|
);
|
|
1477
1529
|
}
|
|
1478
1530
|
async parseBoxed(id, current) {
|
|
1479
|
-
return createBoxedNode(id, await this.
|
|
1531
|
+
return createBoxedNode(id, await this.parseTop(current.valueOf()));
|
|
1480
1532
|
}
|
|
1481
1533
|
async parseTypedArray(id, current) {
|
|
1482
|
-
return createTypedArrayNode(
|
|
1534
|
+
return createTypedArrayNode(
|
|
1535
|
+
id,
|
|
1536
|
+
current,
|
|
1537
|
+
await this.parseTop(current.buffer)
|
|
1538
|
+
);
|
|
1483
1539
|
}
|
|
1484
1540
|
async parseBigIntTypedArray(id, current) {
|
|
1485
1541
|
return createBigIntTypedArrayNode(
|
|
1486
1542
|
id,
|
|
1487
1543
|
current,
|
|
1488
|
-
await this.
|
|
1544
|
+
await this.parseTop(current.buffer)
|
|
1489
1545
|
);
|
|
1490
1546
|
}
|
|
1491
1547
|
async parseDataView(id, current) {
|
|
1492
|
-
return createDataViewNode(id, current, await this.
|
|
1548
|
+
return createDataViewNode(id, current, await this.parseTop(current.buffer));
|
|
1493
1549
|
}
|
|
1494
1550
|
async parseError(id, current) {
|
|
1495
1551
|
const options = getErrorOptions(current, this.features);
|
|
@@ -1511,15 +1567,15 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1511
1567
|
const keyNodes = [];
|
|
1512
1568
|
const valueNodes = [];
|
|
1513
1569
|
for (const [key, value] of current.entries()) {
|
|
1514
|
-
keyNodes.push(await this.
|
|
1515
|
-
valueNodes.push(await this.
|
|
1570
|
+
keyNodes.push(await this.parseTop(key));
|
|
1571
|
+
valueNodes.push(await this.parseTop(value));
|
|
1516
1572
|
}
|
|
1517
1573
|
return this.createMapNode(id, keyNodes, valueNodes, current.size);
|
|
1518
1574
|
}
|
|
1519
1575
|
async parseSet(id, current) {
|
|
1520
1576
|
const items = [];
|
|
1521
1577
|
for (const item of current.keys()) {
|
|
1522
|
-
items.push(await this.
|
|
1578
|
+
items.push(await this.parseTop(item));
|
|
1523
1579
|
}
|
|
1524
1580
|
return createSetNode(id, current.size, items);
|
|
1525
1581
|
}
|
|
@@ -1535,7 +1591,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1535
1591
|
NIL,
|
|
1536
1592
|
NIL,
|
|
1537
1593
|
NIL,
|
|
1538
|
-
await this.
|
|
1594
|
+
await this.parseTop(result),
|
|
1539
1595
|
NIL,
|
|
1540
1596
|
NIL
|
|
1541
1597
|
);
|
|
@@ -1567,7 +1623,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1567
1623
|
const cleanup = current.on({
|
|
1568
1624
|
next: (value) => {
|
|
1569
1625
|
this.markRef(id);
|
|
1570
|
-
this.
|
|
1626
|
+
this.parseTop(value).then(
|
|
1571
1627
|
(data) => {
|
|
1572
1628
|
sequence.push(createStreamNextNode(id, data));
|
|
1573
1629
|
},
|
|
@@ -1579,7 +1635,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1579
1635
|
},
|
|
1580
1636
|
throw: (value) => {
|
|
1581
1637
|
this.markRef(id);
|
|
1582
|
-
this.
|
|
1638
|
+
this.parseTop(value).then(
|
|
1583
1639
|
(data) => {
|
|
1584
1640
|
sequence.push(createStreamThrowNode(id, data));
|
|
1585
1641
|
resolve(sequence);
|
|
@@ -1593,7 +1649,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1593
1649
|
},
|
|
1594
1650
|
return: (value) => {
|
|
1595
1651
|
this.markRef(id);
|
|
1596
|
-
this.
|
|
1652
|
+
this.parseTop(value).then(
|
|
1597
1653
|
(data) => {
|
|
1598
1654
|
sequence.push(createStreamReturnNode(id, data));
|
|
1599
1655
|
resolve(sequence);
|
|
@@ -1609,28 +1665,6 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1609
1665
|
})
|
|
1610
1666
|
);
|
|
1611
1667
|
}
|
|
1612
|
-
async parseAbortSignalSync(id, current) {
|
|
1613
|
-
return createSerovalNode(
|
|
1614
|
-
37 /* AbortSignalSync */,
|
|
1615
|
-
id,
|
|
1616
|
-
NIL,
|
|
1617
|
-
NIL,
|
|
1618
|
-
NIL,
|
|
1619
|
-
NIL,
|
|
1620
|
-
NIL,
|
|
1621
|
-
NIL,
|
|
1622
|
-
NIL,
|
|
1623
|
-
await this.parse(current.reason),
|
|
1624
|
-
NIL,
|
|
1625
|
-
NIL
|
|
1626
|
-
);
|
|
1627
|
-
}
|
|
1628
|
-
async parseAbortSignal(id, current) {
|
|
1629
|
-
if (!current.aborted) {
|
|
1630
|
-
await abortSignalToPromise(current);
|
|
1631
|
-
}
|
|
1632
|
-
return this.parseAbortSignalSync(id, current);
|
|
1633
|
-
}
|
|
1634
1668
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: ehh
|
|
1635
1669
|
async parseObject(id, current) {
|
|
1636
1670
|
if (Array.isArray(current)) {
|
|
@@ -1641,7 +1675,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1641
1675
|
}
|
|
1642
1676
|
const currentClass = current.constructor;
|
|
1643
1677
|
if (currentClass === OpaqueReference) {
|
|
1644
|
-
return this.
|
|
1678
|
+
return this.parseTop(
|
|
1645
1679
|
current.replacement
|
|
1646
1680
|
);
|
|
1647
1681
|
}
|
|
@@ -1704,9 +1738,6 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1704
1738
|
return this.parsePromise(id, current);
|
|
1705
1739
|
}
|
|
1706
1740
|
const currentFeatures = this.features;
|
|
1707
|
-
if (currentFeatures & 32 /* AbortSignal */ && typeof AbortSignal !== "undefined" && currentClass === AbortSignal) {
|
|
1708
|
-
return this.parseAbortSignal(id, current);
|
|
1709
|
-
}
|
|
1710
1741
|
if (currentFeatures & 16 /* BigIntTypedArray */) {
|
|
1711
1742
|
switch (currentClass) {
|
|
1712
1743
|
case BigInt64Array:
|
|
@@ -1741,35 +1772,38 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1741
1772
|
}
|
|
1742
1773
|
throw new SerovalUnsupportedTypeError(current);
|
|
1743
1774
|
}
|
|
1744
|
-
async
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
return ref.type === 0 ? await this.parseObject(ref.value, current) : ref.value;
|
|
1761
|
-
}
|
|
1762
|
-
return NULL_NODE;
|
|
1775
|
+
async parseTop(current) {
|
|
1776
|
+
switch (typeof current) {
|
|
1777
|
+
case "boolean":
|
|
1778
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
1779
|
+
case "undefined":
|
|
1780
|
+
return UNDEFINED_NODE;
|
|
1781
|
+
case "string":
|
|
1782
|
+
return createStringNode(current);
|
|
1783
|
+
case "number":
|
|
1784
|
+
return createNumberNode(current);
|
|
1785
|
+
case "bigint":
|
|
1786
|
+
return createBigIntNode(current);
|
|
1787
|
+
case "object": {
|
|
1788
|
+
if (current) {
|
|
1789
|
+
const ref = this.getReference(current);
|
|
1790
|
+
return ref.type === 0 ? await this.parseObject(ref.value, current) : ref.value;
|
|
1763
1791
|
}
|
|
1764
|
-
|
|
1765
|
-
return this.parseWellKnownSymbol(current);
|
|
1766
|
-
case "function":
|
|
1767
|
-
return this.parseFunction(current);
|
|
1768
|
-
default:
|
|
1769
|
-
throw new SerovalUnsupportedTypeError(current);
|
|
1792
|
+
return NULL_NODE;
|
|
1770
1793
|
}
|
|
1794
|
+
case "symbol":
|
|
1795
|
+
return this.parseWellKnownSymbol(current);
|
|
1796
|
+
case "function":
|
|
1797
|
+
return this.parseFunction(current);
|
|
1798
|
+
default:
|
|
1799
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
async parse(current) {
|
|
1803
|
+
try {
|
|
1804
|
+
return await this.parseTop(current);
|
|
1771
1805
|
} catch (error) {
|
|
1772
|
-
throw new SerovalParserError(error);
|
|
1806
|
+
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
1773
1807
|
}
|
|
1774
1808
|
}
|
|
1775
1809
|
};
|
|
@@ -2040,21 +2074,6 @@ var BaseDeserializerContext = class {
|
|
|
2040
2074
|
this.deserialize(node.a[1]);
|
|
2041
2075
|
return void 0;
|
|
2042
2076
|
}
|
|
2043
|
-
deserializeAbortSignalConstructor(node) {
|
|
2044
|
-
return this.assignIndexedValue(node.i, new AbortController()).signal;
|
|
2045
|
-
}
|
|
2046
|
-
deserializeAbortSignalAbort(node) {
|
|
2047
|
-
const controller = this.refs.get(node.i);
|
|
2048
|
-
assert(controller, new SerovalMissingInstanceError("AbortSignal"));
|
|
2049
|
-
controller.abort(this.deserialize(node.a[1]));
|
|
2050
|
-
return void 0;
|
|
2051
|
-
}
|
|
2052
|
-
deserializeAbortSignalSync(node) {
|
|
2053
|
-
return this.assignIndexedValue(
|
|
2054
|
-
node.i,
|
|
2055
|
-
AbortSignal.abort(this.deserialize(node.f))
|
|
2056
|
-
);
|
|
2057
|
-
}
|
|
2058
2077
|
deserialize(node) {
|
|
2059
2078
|
try {
|
|
2060
2079
|
switch (node.t) {
|
|
@@ -2104,9 +2123,9 @@ var BaseDeserializerContext = class {
|
|
|
2104
2123
|
return this.deserializePlugin(node);
|
|
2105
2124
|
case 22 /* PromiseConstructor */:
|
|
2106
2125
|
return this.deserializePromiseConstructor(node);
|
|
2107
|
-
case 23 /*
|
|
2126
|
+
case 23 /* PromiseSuccess */:
|
|
2108
2127
|
return this.deserializePromiseResolve(node);
|
|
2109
|
-
case 24 /*
|
|
2128
|
+
case 24 /* PromiseFailure */:
|
|
2110
2129
|
return this.deserializePromiseReject(node);
|
|
2111
2130
|
case 28 /* IteratorFactoryInstance */:
|
|
2112
2131
|
return this.deserializeIteratorFactoryInstance(node);
|
|
@@ -2124,12 +2143,6 @@ var BaseDeserializerContext = class {
|
|
|
2124
2143
|
return this.deserializeIteratorFactory(node);
|
|
2125
2144
|
case 29 /* AsyncIteratorFactory */:
|
|
2126
2145
|
return this.deserializeAsyncIteratorFactory(node);
|
|
2127
|
-
case 36 /* AbortSignalAbort */:
|
|
2128
|
-
return this.deserializeAbortSignalAbort(node);
|
|
2129
|
-
case 35 /* AbortSignalConstructor */:
|
|
2130
|
-
return this.deserializeAbortSignalConstructor(node);
|
|
2131
|
-
case 37 /* AbortSignalSync */:
|
|
2132
|
-
return this.deserializeAbortSignalSync(node);
|
|
2133
2146
|
// case SerovalNodeType.SpecialReference:
|
|
2134
2147
|
default:
|
|
2135
2148
|
throw new SerovalUnsupportedNodeError(node);
|
|
@@ -2260,18 +2273,10 @@ var BaseSerializerContext = class {
|
|
|
2260
2273
|
this.marked = new Set(options.markedRefs);
|
|
2261
2274
|
}
|
|
2262
2275
|
createFunction(parameters, body) {
|
|
2263
|
-
|
|
2264
|
-
const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
|
|
2265
|
-
return joined + "=>" + (body.startsWith("{") ? "(" + body + ")" : body);
|
|
2266
|
-
}
|
|
2267
|
-
return "function(" + parameters.join(",") + "){return " + body + "}";
|
|
2276
|
+
return createFunction(this.features, parameters, body);
|
|
2268
2277
|
}
|
|
2269
2278
|
createEffectfulFunction(parameters, body) {
|
|
2270
|
-
|
|
2271
|
-
const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
|
|
2272
|
-
return joined + "=>{" + body + "}";
|
|
2273
|
-
}
|
|
2274
|
-
return "function(" + parameters.join(",") + "){" + body + "}";
|
|
2279
|
+
return createEffectfulFunction(this.features, parameters, body);
|
|
2275
2280
|
}
|
|
2276
2281
|
/**
|
|
2277
2282
|
* A tiny function that tells if a reference
|
|
@@ -2740,7 +2745,11 @@ var BaseSerializerContext = class {
|
|
|
2740
2745
|
return current === this.getRefParam(node.i) ? current : "(" + current + ")";
|
|
2741
2746
|
}
|
|
2742
2747
|
serializePromiseConstructor(node) {
|
|
2743
|
-
|
|
2748
|
+
const resolver = this.assignIndexedValue(node.s, "{p:0,s:0,f:0}");
|
|
2749
|
+
return this.assignIndexedValue(
|
|
2750
|
+
node.i,
|
|
2751
|
+
this.getConstructor(node.f) + "(" + resolver + ")"
|
|
2752
|
+
);
|
|
2744
2753
|
}
|
|
2745
2754
|
serializePromiseResolve(node) {
|
|
2746
2755
|
return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
|
|
@@ -2748,63 +2757,10 @@ var BaseSerializerContext = class {
|
|
|
2748
2757
|
serializePromiseReject(node) {
|
|
2749
2758
|
return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
|
|
2750
2759
|
}
|
|
2751
|
-
serializeSpecialReferenceValue(ref) {
|
|
2752
|
-
switch (ref) {
|
|
2753
|
-
case 0 /* MapSentinel */:
|
|
2754
|
-
return "[]";
|
|
2755
|
-
case 1 /* PromiseConstructor */:
|
|
2756
|
-
return this.createFunction(
|
|
2757
|
-
["s", "f", "p"],
|
|
2758
|
-
"((p=new Promise(" + this.createEffectfulFunction(["a", "b"], "s=a,f=b") + ")).s=s,p.f=f,p)"
|
|
2759
|
-
);
|
|
2760
|
-
case 2 /* PromiseResolve */:
|
|
2761
|
-
return this.createEffectfulFunction(
|
|
2762
|
-
["p", "d"],
|
|
2763
|
-
'p.s(d),p.status="success",p.value=d;delete p.s;delete p.f'
|
|
2764
|
-
);
|
|
2765
|
-
case 3 /* PromiseReject */:
|
|
2766
|
-
return this.createEffectfulFunction(
|
|
2767
|
-
["p", "d"],
|
|
2768
|
-
'p.f(d),p.status="failure",p.value=d;delete p.s;delete p.f'
|
|
2769
|
-
);
|
|
2770
|
-
case 4 /* StreamConstructor */:
|
|
2771
|
-
return this.createFunction(
|
|
2772
|
-
["b", "a", "s", "l", "p", "f", "e", "n"],
|
|
2773
|
-
"(b=[],a=!0,s=!1,l=[],p=0,f=" + this.createEffectfulFunction(
|
|
2774
|
-
["v", "m", "x"],
|
|
2775
|
-
"for(x=0;x<p;x++)l[x]&&l[x][m](v)"
|
|
2776
|
-
) + ",n=" + this.createEffectfulFunction(
|
|
2777
|
-
["o", "x", "z", "c"],
|
|
2778
|
-
'for(x=0,z=b.length;x<z;x++)(c=b[x],(!a&&x===z-1)?o[s?"return":"throw"](c):o.next(c))'
|
|
2779
|
-
) + ",e=" + this.createFunction(
|
|
2780
|
-
["o", "t"],
|
|
2781
|
-
"(a&&(l[t=p++]=o),n(o)," + this.createEffectfulFunction([], "a&&(l[t]=void 0)") + ")"
|
|
2782
|
-
) + ",{__SEROVAL_STREAM__:!0,on:" + this.createFunction(["o"], "e(o)") + ",next:" + this.createEffectfulFunction(["v"], 'a&&(b.push(v),f(v,"next"))') + ",throw:" + this.createEffectfulFunction(
|
|
2783
|
-
["v"],
|
|
2784
|
-
'a&&(b.push(v),f(v,"throw"),a=s=!1,l.length=0)'
|
|
2785
|
-
) + ",return:" + this.createEffectfulFunction(
|
|
2786
|
-
["v"],
|
|
2787
|
-
'a&&(b.push(v),f(v,"return"),a=!1,s=!0,l.length=0)'
|
|
2788
|
-
) + "})"
|
|
2789
|
-
);
|
|
2790
|
-
case 5 /* AbortSignalConstructor */:
|
|
2791
|
-
return this.createFunction(
|
|
2792
|
-
["a", "s"],
|
|
2793
|
-
"((s=(a=new AbortController).signal).a=a,s)"
|
|
2794
|
-
);
|
|
2795
|
-
case 6 /* AbortSignalAbort */:
|
|
2796
|
-
return this.createEffectfulFunction(
|
|
2797
|
-
["s", "r"],
|
|
2798
|
-
"s.a.abort(r);delete s.a"
|
|
2799
|
-
);
|
|
2800
|
-
default:
|
|
2801
|
-
return "";
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2804
2760
|
serializeSpecialReference(node) {
|
|
2805
2761
|
return this.assignIndexedValue(
|
|
2806
2762
|
node.i,
|
|
2807
|
-
this.
|
|
2763
|
+
serializeSpecialReferenceValue(this.features, node.s)
|
|
2808
2764
|
);
|
|
2809
2765
|
}
|
|
2810
2766
|
serializeIteratorFactory(node) {
|
|
@@ -2857,6 +2813,15 @@ var BaseSerializerContext = class {
|
|
|
2857
2813
|
["s"],
|
|
2858
2814
|
this.createFunction(
|
|
2859
2815
|
["b", "c", "p", "d", "e", "t", "f"],
|
|
2816
|
+
/**
|
|
2817
|
+
* b = resolved values
|
|
2818
|
+
* c = b size
|
|
2819
|
+
* p = pending promises
|
|
2820
|
+
* d = index where the resolved value stops
|
|
2821
|
+
* e = if the last value is a throw
|
|
2822
|
+
* t = placeholder variable
|
|
2823
|
+
* f = finalize
|
|
2824
|
+
*/
|
|
2860
2825
|
"(b=[],c=0,p=[],d=-1,e=!1,f=" + this.createEffectfulFunction(
|
|
2861
2826
|
["i", "l"],
|
|
2862
2827
|
"for(i=0,l=p.length;i<l;i++)p[i].s({done:!0,value:void 0})"
|
|
@@ -2869,9 +2834,9 @@ var BaseSerializerContext = class {
|
|
|
2869
2834
|
) + ",return:" + this.createEffectfulFunction(
|
|
2870
2835
|
["v", "t"],
|
|
2871
2836
|
"if(t=p.shift())t.s({done:!0,value:v});f(),d=b.length,b.push(v)"
|
|
2872
|
-
) + "}),t={[" + this.getRefParam(symbol.i) + "]:" + this.createFunction([], "t") + ",next:" + this.createEffectfulFunction(
|
|
2837
|
+
) + "}),t={[" + this.getRefParam(symbol.i) + "]:" + this.createFunction([], "t.p") + ",next:" + this.createEffectfulFunction(
|
|
2873
2838
|
["i", "t", "v"],
|
|
2874
|
-
"if(d===-1){return((i=c++)>=b.length)?(
|
|
2839
|
+
"if(d===-1){return((i=c++)>=b.length)?(" + this.getRefParam(promise.i) + "(t={p:0,s:0,f:0}),p.push(t),t.p):{done:!1,value:b[i]}}if(c>d)return{done:!0,value:void 0};if(v=b[i=c++],i!==d)return{done:!1,value:v};if(e)throw v;return{done:!0,value:v}"
|
|
2875
2840
|
) + "})"
|
|
2876
2841
|
)
|
|
2877
2842
|
)
|
|
@@ -2908,18 +2873,6 @@ var BaseSerializerContext = class {
|
|
|
2908
2873
|
serializeStreamReturn(node) {
|
|
2909
2874
|
return this.getRefParam(node.i) + ".return(" + this.serialize(node.f) + ")";
|
|
2910
2875
|
}
|
|
2911
|
-
serializeAbortSignalSync(node) {
|
|
2912
|
-
return this.assignIndexedValue(
|
|
2913
|
-
node.i,
|
|
2914
|
-
"AbortSignal.abort(" + this.serialize(node.f) + ")"
|
|
2915
|
-
);
|
|
2916
|
-
}
|
|
2917
|
-
serializeAbortSignalConstructor(node) {
|
|
2918
|
-
return this.assignIndexedValue(node.i, this.getConstructor(node.f) + "()");
|
|
2919
|
-
}
|
|
2920
|
-
serializeAbortSignalAbort(node) {
|
|
2921
|
-
return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
|
|
2922
|
-
}
|
|
2923
2876
|
serialize(node) {
|
|
2924
2877
|
try {
|
|
2925
2878
|
switch (node.t) {
|
|
@@ -2968,9 +2921,9 @@ var BaseSerializerContext = class {
|
|
|
2968
2921
|
return this.serializeBoxed(node);
|
|
2969
2922
|
case 22 /* PromiseConstructor */:
|
|
2970
2923
|
return this.serializePromiseConstructor(node);
|
|
2971
|
-
case 23 /*
|
|
2924
|
+
case 23 /* PromiseSuccess */:
|
|
2972
2925
|
return this.serializePromiseResolve(node);
|
|
2973
|
-
case 24 /*
|
|
2926
|
+
case 24 /* PromiseFailure */:
|
|
2974
2927
|
return this.serializePromiseReject(node);
|
|
2975
2928
|
case 25 /* Plugin */:
|
|
2976
2929
|
return this.serializePlugin(node);
|
|
@@ -2992,12 +2945,6 @@ var BaseSerializerContext = class {
|
|
|
2992
2945
|
return this.serializeStreamThrow(node);
|
|
2993
2946
|
case 34 /* StreamReturn */:
|
|
2994
2947
|
return this.serializeStreamReturn(node);
|
|
2995
|
-
case 36 /* AbortSignalAbort */:
|
|
2996
|
-
return this.serializeAbortSignalAbort(node);
|
|
2997
|
-
case 35 /* AbortSignalConstructor */:
|
|
2998
|
-
return this.serializeAbortSignalConstructor(node);
|
|
2999
|
-
case 37 /* AbortSignalSync */:
|
|
3000
|
-
return this.serializeAbortSignalSync(node);
|
|
3001
2948
|
default:
|
|
3002
2949
|
throw new SerovalUnsupportedNodeError(node);
|
|
3003
2950
|
}
|
|
@@ -3047,7 +2994,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3047
2994
|
const nodes = [];
|
|
3048
2995
|
for (let i = 0, len = current.length; i < len; i++) {
|
|
3049
2996
|
if (i in current) {
|
|
3050
|
-
nodes[i] = this.
|
|
2997
|
+
nodes[i] = this.parseTop(current[i]);
|
|
3051
2998
|
}
|
|
3052
2999
|
}
|
|
3053
3000
|
return nodes;
|
|
@@ -3061,7 +3008,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3061
3008
|
const valueNodes = [];
|
|
3062
3009
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
3063
3010
|
keyNodes.push(serializeString(entries[i][0]));
|
|
3064
|
-
valueNodes.push(this.
|
|
3011
|
+
valueNodes.push(this.parseTop(entries[i][1]));
|
|
3065
3012
|
}
|
|
3066
3013
|
let symbol = Symbol.iterator;
|
|
3067
3014
|
if (symbol in properties) {
|
|
@@ -3069,7 +3016,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3069
3016
|
valueNodes.push(
|
|
3070
3017
|
createIteratorFactoryInstanceNode(
|
|
3071
3018
|
this.parseIteratorFactory(),
|
|
3072
|
-
this.
|
|
3019
|
+
this.parseTop(
|
|
3073
3020
|
iteratorToSequence(properties)
|
|
3074
3021
|
)
|
|
3075
3022
|
)
|
|
@@ -3081,7 +3028,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3081
3028
|
valueNodes.push(
|
|
3082
3029
|
createAsyncIteratorFactoryInstanceNode(
|
|
3083
3030
|
this.parseAsyncIteratorFactory(),
|
|
3084
|
-
this.
|
|
3031
|
+
this.parseTop(createStream())
|
|
3085
3032
|
)
|
|
3086
3033
|
);
|
|
3087
3034
|
}
|
|
@@ -3110,16 +3057,20 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3110
3057
|
);
|
|
3111
3058
|
}
|
|
3112
3059
|
parseBoxed(id, current) {
|
|
3113
|
-
return createBoxedNode(id, this.
|
|
3060
|
+
return createBoxedNode(id, this.parseTop(current.valueOf()));
|
|
3114
3061
|
}
|
|
3115
3062
|
parseTypedArray(id, current) {
|
|
3116
|
-
return createTypedArrayNode(id, current, this.
|
|
3063
|
+
return createTypedArrayNode(id, current, this.parseTop(current.buffer));
|
|
3117
3064
|
}
|
|
3118
3065
|
parseBigIntTypedArray(id, current) {
|
|
3119
|
-
return createBigIntTypedArrayNode(
|
|
3066
|
+
return createBigIntTypedArrayNode(
|
|
3067
|
+
id,
|
|
3068
|
+
current,
|
|
3069
|
+
this.parseTop(current.buffer)
|
|
3070
|
+
);
|
|
3120
3071
|
}
|
|
3121
3072
|
parseDataView(id, current) {
|
|
3122
|
-
return createDataViewNode(id, current, this.
|
|
3073
|
+
return createDataViewNode(id, current, this.parseTop(current.buffer));
|
|
3123
3074
|
}
|
|
3124
3075
|
parseError(id, current) {
|
|
3125
3076
|
const options = getErrorOptions(current, this.features);
|
|
@@ -3141,15 +3092,15 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3141
3092
|
const keyNodes = [];
|
|
3142
3093
|
const valueNodes = [];
|
|
3143
3094
|
for (const [key, value] of current.entries()) {
|
|
3144
|
-
keyNodes.push(this.
|
|
3145
|
-
valueNodes.push(this.
|
|
3095
|
+
keyNodes.push(this.parseTop(key));
|
|
3096
|
+
valueNodes.push(this.parseTop(value));
|
|
3146
3097
|
}
|
|
3147
3098
|
return this.createMapNode(id, keyNodes, valueNodes, current.size);
|
|
3148
3099
|
}
|
|
3149
3100
|
parseSet(id, current) {
|
|
3150
3101
|
const items = [];
|
|
3151
3102
|
for (const item of current.keys()) {
|
|
3152
|
-
items.push(this.
|
|
3103
|
+
items.push(this.parseTop(item));
|
|
3153
3104
|
}
|
|
3154
3105
|
return createSetNode(id, current.size, items);
|
|
3155
3106
|
}
|
|
@@ -3179,29 +3130,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3179
3130
|
);
|
|
3180
3131
|
}
|
|
3181
3132
|
parsePromise(id, _current) {
|
|
3182
|
-
return this.createPromiseConstructorNode(id);
|
|
3183
|
-
}
|
|
3184
|
-
parseAbortSignalSync(id, current) {
|
|
3185
|
-
return createSerovalNode(
|
|
3186
|
-
37 /* AbortSignalSync */,
|
|
3187
|
-
id,
|
|
3188
|
-
NIL,
|
|
3189
|
-
NIL,
|
|
3190
|
-
NIL,
|
|
3191
|
-
NIL,
|
|
3192
|
-
NIL,
|
|
3193
|
-
NIL,
|
|
3194
|
-
NIL,
|
|
3195
|
-
this.parse(current.reason),
|
|
3196
|
-
NIL,
|
|
3197
|
-
NIL
|
|
3198
|
-
);
|
|
3199
|
-
}
|
|
3200
|
-
parseAbortSignal(id, current) {
|
|
3201
|
-
if (current.aborted) {
|
|
3202
|
-
return this.parseAbortSignalSync(id, current);
|
|
3203
|
-
}
|
|
3204
|
-
return this.createAbortSignalConstructorNode(id);
|
|
3133
|
+
return this.createPromiseConstructorNode(id, this.createIndex({}));
|
|
3205
3134
|
}
|
|
3206
3135
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: ehh
|
|
3207
3136
|
parseObject(id, current) {
|
|
@@ -3213,7 +3142,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3213
3142
|
}
|
|
3214
3143
|
const currentClass = current.constructor;
|
|
3215
3144
|
if (currentClass === OpaqueReference) {
|
|
3216
|
-
return this.
|
|
3145
|
+
return this.parseTop(
|
|
3217
3146
|
current.replacement
|
|
3218
3147
|
);
|
|
3219
3148
|
}
|
|
@@ -3276,9 +3205,6 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3276
3205
|
return this.parsePromise(id, current);
|
|
3277
3206
|
}
|
|
3278
3207
|
const currentFeatures = this.features;
|
|
3279
|
-
if (currentFeatures & 32 /* AbortSignal */ && typeof AbortSignal !== "undefined" && currentClass === AbortSignal) {
|
|
3280
|
-
return this.parseAbortSignal(id, current);
|
|
3281
|
-
}
|
|
3282
3208
|
if (currentFeatures & 16 /* BigIntTypedArray */) {
|
|
3283
3209
|
switch (currentClass) {
|
|
3284
3210
|
case BigInt64Array:
|
|
@@ -3313,36 +3239,39 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3313
3239
|
}
|
|
3314
3240
|
throw new SerovalUnsupportedTypeError(current);
|
|
3315
3241
|
}
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
return ref.type === 0 /* Fresh */ ? this.parseObject(ref.value, current) : ref.value;
|
|
3333
|
-
}
|
|
3334
|
-
return NULL_NODE;
|
|
3335
|
-
}
|
|
3336
|
-
case "symbol":
|
|
3337
|
-
return this.parseWellKnownSymbol(current);
|
|
3338
|
-
case "function": {
|
|
3339
|
-
return this.parseFunction(current);
|
|
3242
|
+
parseTop(current) {
|
|
3243
|
+
switch (typeof current) {
|
|
3244
|
+
case "boolean":
|
|
3245
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
3246
|
+
case "undefined":
|
|
3247
|
+
return UNDEFINED_NODE;
|
|
3248
|
+
case "string":
|
|
3249
|
+
return createStringNode(current);
|
|
3250
|
+
case "number":
|
|
3251
|
+
return createNumberNode(current);
|
|
3252
|
+
case "bigint":
|
|
3253
|
+
return createBigIntNode(current);
|
|
3254
|
+
case "object": {
|
|
3255
|
+
if (current) {
|
|
3256
|
+
const ref = this.getReference(current);
|
|
3257
|
+
return ref.type === 0 /* Fresh */ ? this.parseObject(ref.value, current) : ref.value;
|
|
3340
3258
|
}
|
|
3341
|
-
|
|
3342
|
-
|
|
3259
|
+
return NULL_NODE;
|
|
3260
|
+
}
|
|
3261
|
+
case "symbol":
|
|
3262
|
+
return this.parseWellKnownSymbol(current);
|
|
3263
|
+
case "function": {
|
|
3264
|
+
return this.parseFunction(current);
|
|
3343
3265
|
}
|
|
3266
|
+
default:
|
|
3267
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
parse(current) {
|
|
3271
|
+
try {
|
|
3272
|
+
return this.parseTop(current);
|
|
3344
3273
|
} catch (error) {
|
|
3345
|
-
throw new SerovalParserError(error);
|
|
3274
|
+
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3346
3275
|
}
|
|
3347
3276
|
}
|
|
3348
3277
|
};
|
|
@@ -3406,7 +3335,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3406
3335
|
const valueNodes = [];
|
|
3407
3336
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
3408
3337
|
keyNodes.push(serializeString(entries[i][0]));
|
|
3409
|
-
valueNodes.push(this.
|
|
3338
|
+
valueNodes.push(this.parseTop(entries[i][1]));
|
|
3410
3339
|
}
|
|
3411
3340
|
let symbol = Symbol.iterator;
|
|
3412
3341
|
if (symbol in properties) {
|
|
@@ -3414,7 +3343,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3414
3343
|
valueNodes.push(
|
|
3415
3344
|
createIteratorFactoryInstanceNode(
|
|
3416
3345
|
this.parseIteratorFactory(),
|
|
3417
|
-
this.
|
|
3346
|
+
this.parseTop(
|
|
3418
3347
|
iteratorToSequence(properties)
|
|
3419
3348
|
)
|
|
3420
3349
|
)
|
|
@@ -3426,7 +3355,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3426
3355
|
valueNodes.push(
|
|
3427
3356
|
createAsyncIteratorFactoryInstanceNode(
|
|
3428
3357
|
this.parseAsyncIteratorFactory(),
|
|
3429
|
-
this.
|
|
3358
|
+
this.parseTop(
|
|
3430
3359
|
createStreamFromAsyncIterable(
|
|
3431
3360
|
properties
|
|
3432
3361
|
)
|
|
@@ -3450,63 +3379,63 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3450
3379
|
s: keyNodes.length
|
|
3451
3380
|
};
|
|
3452
3381
|
}
|
|
3382
|
+
handlePromiseSuccess(id, data) {
|
|
3383
|
+
const parsed = this.parseWithError(data);
|
|
3384
|
+
if (parsed) {
|
|
3385
|
+
this.onParse(
|
|
3386
|
+
createSerovalNode(
|
|
3387
|
+
23 /* PromiseSuccess */,
|
|
3388
|
+
id,
|
|
3389
|
+
NIL,
|
|
3390
|
+
NIL,
|
|
3391
|
+
NIL,
|
|
3392
|
+
NIL,
|
|
3393
|
+
NIL,
|
|
3394
|
+
NIL,
|
|
3395
|
+
[this.parseSpecialReference(2 /* PromiseSuccess */), parsed],
|
|
3396
|
+
NIL,
|
|
3397
|
+
NIL,
|
|
3398
|
+
NIL
|
|
3399
|
+
)
|
|
3400
|
+
);
|
|
3401
|
+
}
|
|
3402
|
+
this.popPendingState();
|
|
3403
|
+
}
|
|
3404
|
+
handlePromiseFailure(id, data) {
|
|
3405
|
+
if (this.alive) {
|
|
3406
|
+
const parsed = this.parseWithError(data);
|
|
3407
|
+
if (parsed) {
|
|
3408
|
+
this.onParse(
|
|
3409
|
+
createSerovalNode(
|
|
3410
|
+
24 /* PromiseFailure */,
|
|
3411
|
+
id,
|
|
3412
|
+
NIL,
|
|
3413
|
+
NIL,
|
|
3414
|
+
NIL,
|
|
3415
|
+
NIL,
|
|
3416
|
+
NIL,
|
|
3417
|
+
NIL,
|
|
3418
|
+
[
|
|
3419
|
+
this.parseSpecialReference(3 /* PromiseFailure */),
|
|
3420
|
+
parsed
|
|
3421
|
+
],
|
|
3422
|
+
NIL,
|
|
3423
|
+
NIL,
|
|
3424
|
+
NIL
|
|
3425
|
+
)
|
|
3426
|
+
);
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
this.popPendingState();
|
|
3430
|
+
}
|
|
3453
3431
|
parsePromise(id, current) {
|
|
3432
|
+
const resolver = this.createIndex({});
|
|
3454
3433
|
current.then(
|
|
3455
|
-
(
|
|
3456
|
-
|
|
3457
|
-
if (parsed) {
|
|
3458
|
-
this.onParse(
|
|
3459
|
-
createSerovalNode(
|
|
3460
|
-
23 /* PromiseResolve */,
|
|
3461
|
-
id,
|
|
3462
|
-
NIL,
|
|
3463
|
-
NIL,
|
|
3464
|
-
NIL,
|
|
3465
|
-
NIL,
|
|
3466
|
-
NIL,
|
|
3467
|
-
NIL,
|
|
3468
|
-
[
|
|
3469
|
-
this.parseSpecialReference(2 /* PromiseResolve */),
|
|
3470
|
-
parsed
|
|
3471
|
-
],
|
|
3472
|
-
NIL,
|
|
3473
|
-
NIL,
|
|
3474
|
-
NIL
|
|
3475
|
-
)
|
|
3476
|
-
);
|
|
3477
|
-
}
|
|
3478
|
-
this.popPendingState();
|
|
3479
|
-
},
|
|
3480
|
-
(data) => {
|
|
3481
|
-
if (this.alive) {
|
|
3482
|
-
const parsed = this.parseWithError(data);
|
|
3483
|
-
if (parsed) {
|
|
3484
|
-
this.onParse(
|
|
3485
|
-
createSerovalNode(
|
|
3486
|
-
24 /* PromiseReject */,
|
|
3487
|
-
id,
|
|
3488
|
-
NIL,
|
|
3489
|
-
NIL,
|
|
3490
|
-
NIL,
|
|
3491
|
-
NIL,
|
|
3492
|
-
NIL,
|
|
3493
|
-
NIL,
|
|
3494
|
-
[
|
|
3495
|
-
this.parseSpecialReference(3 /* PromiseReject */),
|
|
3496
|
-
parsed
|
|
3497
|
-
],
|
|
3498
|
-
NIL,
|
|
3499
|
-
NIL,
|
|
3500
|
-
NIL
|
|
3501
|
-
)
|
|
3502
|
-
);
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
this.popPendingState();
|
|
3506
|
-
}
|
|
3434
|
+
this.handlePromiseSuccess.bind(this, resolver),
|
|
3435
|
+
this.handlePromiseFailure.bind(this, resolver)
|
|
3507
3436
|
);
|
|
3508
3437
|
this.pushPendingState();
|
|
3509
|
-
return this.createPromiseConstructorNode(id);
|
|
3438
|
+
return this.createPromiseConstructorNode(id, resolver);
|
|
3510
3439
|
}
|
|
3511
3440
|
parsePlugin(id, current) {
|
|
3512
3441
|
const currentPlugins = this.plugins;
|
|
@@ -3563,48 +3492,9 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3563
3492
|
});
|
|
3564
3493
|
return result;
|
|
3565
3494
|
}
|
|
3566
|
-
handleAbortSignal(id, current) {
|
|
3567
|
-
if (this.alive) {
|
|
3568
|
-
const parsed = this.parseWithError(current.reason);
|
|
3569
|
-
if (parsed) {
|
|
3570
|
-
this.onParse(
|
|
3571
|
-
createSerovalNode(
|
|
3572
|
-
36 /* AbortSignalAbort */,
|
|
3573
|
-
id,
|
|
3574
|
-
NIL,
|
|
3575
|
-
NIL,
|
|
3576
|
-
NIL,
|
|
3577
|
-
NIL,
|
|
3578
|
-
NIL,
|
|
3579
|
-
NIL,
|
|
3580
|
-
[
|
|
3581
|
-
this.parseSpecialReference(6 /* AbortSignalAbort */),
|
|
3582
|
-
parsed
|
|
3583
|
-
],
|
|
3584
|
-
NIL,
|
|
3585
|
-
NIL,
|
|
3586
|
-
NIL
|
|
3587
|
-
)
|
|
3588
|
-
);
|
|
3589
|
-
}
|
|
3590
|
-
}
|
|
3591
|
-
this.popPendingState();
|
|
3592
|
-
}
|
|
3593
|
-
parseAbortSignal(id, current) {
|
|
3594
|
-
if (current.aborted) {
|
|
3595
|
-
return this.parseAbortSignalSync(id, current);
|
|
3596
|
-
}
|
|
3597
|
-
this.pushPendingState();
|
|
3598
|
-
current.addEventListener(
|
|
3599
|
-
"abort",
|
|
3600
|
-
this.handleAbortSignal.bind(this, id, current),
|
|
3601
|
-
{ once: true }
|
|
3602
|
-
);
|
|
3603
|
-
return this.createAbortSignalConstructorNode(id);
|
|
3604
|
-
}
|
|
3605
3495
|
parseWithError(current) {
|
|
3606
3496
|
try {
|
|
3607
|
-
return this.
|
|
3497
|
+
return this.parseTop(current);
|
|
3608
3498
|
} catch (err) {
|
|
3609
3499
|
this.onError(err);
|
|
3610
3500
|
return NIL;
|
|
@@ -3845,9 +3735,6 @@ var VanillaSerializerContext = class extends BaseSerializerContext {
|
|
|
3845
3735
|
serializePromiseReject(node) {
|
|
3846
3736
|
throw new SerovalUnsupportedNodeError(node);
|
|
3847
3737
|
}
|
|
3848
|
-
serializeAbortSignalAbort(node) {
|
|
3849
|
-
throw new SerovalUnsupportedNodeError(node);
|
|
3850
|
-
}
|
|
3851
3738
|
serializeTop(tree) {
|
|
3852
3739
|
const result = this.serialize(tree);
|
|
3853
3740
|
if (tree.i != null && this.vars.length) {
|