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
|
@@ -5,10 +5,9 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
|
|
|
5
5
|
Feature2[Feature2["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
|
|
6
6
|
Feature2[Feature2["ObjectAssign"] = 8] = "ObjectAssign";
|
|
7
7
|
Feature2[Feature2["BigIntTypedArray"] = 16] = "BigIntTypedArray";
|
|
8
|
-
Feature2[Feature2["AbortSignal"] = 32] = "AbortSignal";
|
|
9
8
|
return Feature2;
|
|
10
9
|
})(Feature || {});
|
|
11
|
-
var ALL_ENABLED =
|
|
10
|
+
var ALL_ENABLED = 1 /* AggregateError */ | 2 /* ArrowFunction */ | 4 /* ErrorPrototypeStack */ | 8 /* ObjectAssign */ | 16 /* BigIntTypedArray */;
|
|
12
11
|
|
|
13
12
|
// src/core/string.ts
|
|
14
13
|
function serializeChar(str) {
|
|
@@ -184,19 +183,6 @@ function resolvePlugins(plugins) {
|
|
|
184
183
|
return void 0;
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
// src/core/abort-signal.ts
|
|
188
|
-
function resolveAbortSignalResult(resolve) {
|
|
189
|
-
resolve(this.reason);
|
|
190
|
-
}
|
|
191
|
-
function resolveAbortSignal(resolve) {
|
|
192
|
-
this.addEventListener("abort", resolveAbortSignalResult.bind(this, resolve), {
|
|
193
|
-
once: true
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
function abortSignalToPromise(signal) {
|
|
197
|
-
return new Promise(resolveAbortSignal.bind(signal));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
186
|
// src/core/constants.ts
|
|
201
187
|
var SYMBOL_STRING = {
|
|
202
188
|
[0 /* AsyncIterator */]: "Symbol.asyncIterator",
|
|
@@ -485,10 +471,11 @@ function createIndexedValueNode(id) {
|
|
|
485
471
|
);
|
|
486
472
|
}
|
|
487
473
|
function createDateNode(id, current) {
|
|
474
|
+
const timestamp = current.valueOf();
|
|
488
475
|
return createSerovalNode(
|
|
489
476
|
5 /* Date */,
|
|
490
477
|
id,
|
|
491
|
-
current.toISOString(),
|
|
478
|
+
timestamp !== timestamp ? "" : current.toISOString(),
|
|
492
479
|
NIL,
|
|
493
480
|
NIL,
|
|
494
481
|
NIL,
|
|
@@ -904,18 +891,96 @@ var OpaqueReference = class {
|
|
|
904
891
|
}
|
|
905
892
|
};
|
|
906
893
|
|
|
894
|
+
// src/core/function-string.ts
|
|
895
|
+
function createFunction(features, parameters, body) {
|
|
896
|
+
if (features & 2 /* ArrowFunction */) {
|
|
897
|
+
const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
|
|
898
|
+
return joined + "=>" + (body.startsWith("{") ? "(" + body + ")" : body);
|
|
899
|
+
}
|
|
900
|
+
return "function(" + parameters.join(",") + "){return " + body + "}";
|
|
901
|
+
}
|
|
902
|
+
function createEffectfulFunction(features, parameters, body) {
|
|
903
|
+
if (features & 2 /* ArrowFunction */) {
|
|
904
|
+
const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
|
|
905
|
+
return joined + "=>{" + body + "}";
|
|
906
|
+
}
|
|
907
|
+
return "function(" + parameters.join(",") + "){" + body + "}";
|
|
908
|
+
}
|
|
909
|
+
|
|
907
910
|
// src/core/special-reference.ts
|
|
908
911
|
var ITERATOR = {};
|
|
909
912
|
var ASYNC_ITERATOR = {};
|
|
910
913
|
var SPECIAL_REFS = {
|
|
911
914
|
[0 /* MapSentinel */]: {},
|
|
912
915
|
[1 /* PromiseConstructor */]: {},
|
|
913
|
-
[2 /*
|
|
914
|
-
[3 /*
|
|
915
|
-
[4 /* StreamConstructor */]: {}
|
|
916
|
-
[5 /* AbortSignalConstructor */]: {},
|
|
917
|
-
[6 /* AbortSignalAbort */]: {}
|
|
916
|
+
[2 /* PromiseSuccess */]: {},
|
|
917
|
+
[3 /* PromiseFailure */]: {},
|
|
918
|
+
[4 /* StreamConstructor */]: {}
|
|
918
919
|
};
|
|
920
|
+
function serializePromiseConstructor(features) {
|
|
921
|
+
return createFunction(
|
|
922
|
+
features,
|
|
923
|
+
["r"],
|
|
924
|
+
"(r.p=new Promise(" + createEffectfulFunction(features, ["s", "f"], "r.s=s,r.f=f") + "))"
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
function serializePromiseSuccess(features) {
|
|
928
|
+
return createEffectfulFunction(
|
|
929
|
+
features,
|
|
930
|
+
["r", "d"],
|
|
931
|
+
"r.s(d),r.p.s=1,r.p.v=d"
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
function serializePromiseFailure(features) {
|
|
935
|
+
return createEffectfulFunction(
|
|
936
|
+
features,
|
|
937
|
+
["r", "d"],
|
|
938
|
+
"r.f(d),r.p.s=2,r.p.v=d"
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
function serializeStreamConstructor(features) {
|
|
942
|
+
return createFunction(
|
|
943
|
+
features,
|
|
944
|
+
["b", "a", "s", "l", "p", "f", "e", "n"],
|
|
945
|
+
"(b=[],a=!0,s=!1,l=[],p=0,f=" + createEffectfulFunction(
|
|
946
|
+
features,
|
|
947
|
+
["v", "m", "x"],
|
|
948
|
+
"for(x=0;x<p;x++)l[x]&&l[x][m](v)"
|
|
949
|
+
) + ",n=" + createEffectfulFunction(
|
|
950
|
+
features,
|
|
951
|
+
["o", "x", "z", "c"],
|
|
952
|
+
'for(x=0,z=b.length;x<z;x++)(c=b[x],(!a&&x===z-1)?o[s?"return":"throw"](c):o.next(c))'
|
|
953
|
+
) + ",e=" + createFunction(
|
|
954
|
+
features,
|
|
955
|
+
["o", "t"],
|
|
956
|
+
"(a&&(l[t=p++]=o),n(o)," + createEffectfulFunction(features, [], "a&&(l[t]=void 0)") + ")"
|
|
957
|
+
) + ",{__SEROVAL_STREAM__:!0,on:" + createFunction(features, ["o"], "e(o)") + ",next:" + createEffectfulFunction(features, ["v"], 'a&&(b.push(v),f(v,"next"))') + ",throw:" + createEffectfulFunction(
|
|
958
|
+
features,
|
|
959
|
+
["v"],
|
|
960
|
+
'a&&(b.push(v),f(v,"throw"),a=s=!1,l.length=0)'
|
|
961
|
+
) + ",return:" + createEffectfulFunction(
|
|
962
|
+
features,
|
|
963
|
+
["v"],
|
|
964
|
+
'a&&(b.push(v),f(v,"return"),a=!1,s=!0,l.length=0)'
|
|
965
|
+
) + "})"
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
function serializeSpecialReferenceValue(features, ref) {
|
|
969
|
+
switch (ref) {
|
|
970
|
+
case 0 /* MapSentinel */:
|
|
971
|
+
return "[]";
|
|
972
|
+
case 1 /* PromiseConstructor */:
|
|
973
|
+
return serializePromiseConstructor(features);
|
|
974
|
+
case 2 /* PromiseSuccess */:
|
|
975
|
+
return serializePromiseSuccess(features);
|
|
976
|
+
case 3 /* PromiseFailure */:
|
|
977
|
+
return serializePromiseFailure(features);
|
|
978
|
+
case 4 /* StreamConstructor */:
|
|
979
|
+
return serializeStreamConstructor(features);
|
|
980
|
+
default:
|
|
981
|
+
return "";
|
|
982
|
+
}
|
|
983
|
+
}
|
|
919
984
|
|
|
920
985
|
// src/core/utils/deferred.ts
|
|
921
986
|
function createDeferred() {
|
|
@@ -1179,6 +1244,11 @@ var BaseParserContext = class {
|
|
|
1179
1244
|
isMarked(id) {
|
|
1180
1245
|
return this.marked.has(id);
|
|
1181
1246
|
}
|
|
1247
|
+
createIndex(current) {
|
|
1248
|
+
const id = this.refs.size;
|
|
1249
|
+
this.refs.set(current, id);
|
|
1250
|
+
return id;
|
|
1251
|
+
}
|
|
1182
1252
|
getIndexedValue(current) {
|
|
1183
1253
|
const registeredId = this.refs.get(current);
|
|
1184
1254
|
if (registeredId != null) {
|
|
@@ -1188,11 +1258,9 @@ var BaseParserContext = class {
|
|
|
1188
1258
|
value: createIndexedValueNode(registeredId)
|
|
1189
1259
|
};
|
|
1190
1260
|
}
|
|
1191
|
-
const id = this.refs.size;
|
|
1192
|
-
this.refs.set(current, id);
|
|
1193
1261
|
return {
|
|
1194
1262
|
type: 0 /* Fresh */,
|
|
1195
|
-
value:
|
|
1263
|
+
value: this.createIndex(current)
|
|
1196
1264
|
};
|
|
1197
1265
|
}
|
|
1198
1266
|
getReference(current) {
|
|
@@ -1311,11 +1379,11 @@ var BaseParserContext = class {
|
|
|
1311
1379
|
NIL
|
|
1312
1380
|
);
|
|
1313
1381
|
}
|
|
1314
|
-
createPromiseConstructorNode(id) {
|
|
1382
|
+
createPromiseConstructorNode(id, resolver) {
|
|
1315
1383
|
return createSerovalNode(
|
|
1316
1384
|
22 /* PromiseConstructor */,
|
|
1317
1385
|
id,
|
|
1318
|
-
|
|
1386
|
+
resolver,
|
|
1319
1387
|
NIL,
|
|
1320
1388
|
NIL,
|
|
1321
1389
|
NIL,
|
|
@@ -1327,22 +1395,6 @@ var BaseParserContext = class {
|
|
|
1327
1395
|
NIL
|
|
1328
1396
|
);
|
|
1329
1397
|
}
|
|
1330
|
-
createAbortSignalConstructorNode(id) {
|
|
1331
|
-
return createSerovalNode(
|
|
1332
|
-
35 /* AbortSignalConstructor */,
|
|
1333
|
-
id,
|
|
1334
|
-
NIL,
|
|
1335
|
-
NIL,
|
|
1336
|
-
NIL,
|
|
1337
|
-
NIL,
|
|
1338
|
-
NIL,
|
|
1339
|
-
NIL,
|
|
1340
|
-
NIL,
|
|
1341
|
-
this.parseSpecialReference(5 /* AbortSignalConstructor */),
|
|
1342
|
-
NIL,
|
|
1343
|
-
NIL
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
1398
|
};
|
|
1347
1399
|
|
|
1348
1400
|
// src/core/context/parser/async.ts
|
|
@@ -1351,7 +1403,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1351
1403
|
const nodes = [];
|
|
1352
1404
|
for (let i = 0, len = current.length; i < len; i++) {
|
|
1353
1405
|
if (i in current) {
|
|
1354
|
-
nodes[i] = await this.
|
|
1406
|
+
nodes[i] = await this.parseTop(current[i]);
|
|
1355
1407
|
}
|
|
1356
1408
|
}
|
|
1357
1409
|
return nodes;
|
|
@@ -1365,7 +1417,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1365
1417
|
const valueNodes = [];
|
|
1366
1418
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
1367
1419
|
keyNodes.push(serializeString(entries[i][0]));
|
|
1368
|
-
valueNodes.push(await this.
|
|
1420
|
+
valueNodes.push(await this.parseTop(entries[i][1]));
|
|
1369
1421
|
}
|
|
1370
1422
|
let symbol = Symbol.iterator;
|
|
1371
1423
|
if (symbol in properties) {
|
|
@@ -1373,7 +1425,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1373
1425
|
valueNodes.push(
|
|
1374
1426
|
createIteratorFactoryInstanceNode(
|
|
1375
1427
|
this.parseIteratorFactory(),
|
|
1376
|
-
await this.
|
|
1428
|
+
await this.parseTop(
|
|
1377
1429
|
iteratorToSequence(properties)
|
|
1378
1430
|
)
|
|
1379
1431
|
)
|
|
@@ -1385,7 +1437,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1385
1437
|
valueNodes.push(
|
|
1386
1438
|
createAsyncIteratorFactoryInstanceNode(
|
|
1387
1439
|
this.parseAsyncIteratorFactory(),
|
|
1388
|
-
await this.
|
|
1440
|
+
await this.parseTop(
|
|
1389
1441
|
createStreamFromAsyncIterable(
|
|
1390
1442
|
properties
|
|
1391
1443
|
)
|
|
@@ -1418,20 +1470,24 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1418
1470
|
);
|
|
1419
1471
|
}
|
|
1420
1472
|
async parseBoxed(id, current) {
|
|
1421
|
-
return createBoxedNode(id, await this.
|
|
1473
|
+
return createBoxedNode(id, await this.parseTop(current.valueOf()));
|
|
1422
1474
|
}
|
|
1423
1475
|
async parseTypedArray(id, current) {
|
|
1424
|
-
return createTypedArrayNode(
|
|
1476
|
+
return createTypedArrayNode(
|
|
1477
|
+
id,
|
|
1478
|
+
current,
|
|
1479
|
+
await this.parseTop(current.buffer)
|
|
1480
|
+
);
|
|
1425
1481
|
}
|
|
1426
1482
|
async parseBigIntTypedArray(id, current) {
|
|
1427
1483
|
return createBigIntTypedArrayNode(
|
|
1428
1484
|
id,
|
|
1429
1485
|
current,
|
|
1430
|
-
await this.
|
|
1486
|
+
await this.parseTop(current.buffer)
|
|
1431
1487
|
);
|
|
1432
1488
|
}
|
|
1433
1489
|
async parseDataView(id, current) {
|
|
1434
|
-
return createDataViewNode(id, current, await this.
|
|
1490
|
+
return createDataViewNode(id, current, await this.parseTop(current.buffer));
|
|
1435
1491
|
}
|
|
1436
1492
|
async parseError(id, current) {
|
|
1437
1493
|
const options = getErrorOptions(current, this.features);
|
|
@@ -1453,15 +1509,15 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1453
1509
|
const keyNodes = [];
|
|
1454
1510
|
const valueNodes = [];
|
|
1455
1511
|
for (const [key, value] of current.entries()) {
|
|
1456
|
-
keyNodes.push(await this.
|
|
1457
|
-
valueNodes.push(await this.
|
|
1512
|
+
keyNodes.push(await this.parseTop(key));
|
|
1513
|
+
valueNodes.push(await this.parseTop(value));
|
|
1458
1514
|
}
|
|
1459
1515
|
return this.createMapNode(id, keyNodes, valueNodes, current.size);
|
|
1460
1516
|
}
|
|
1461
1517
|
async parseSet(id, current) {
|
|
1462
1518
|
const items = [];
|
|
1463
1519
|
for (const item of current.keys()) {
|
|
1464
|
-
items.push(await this.
|
|
1520
|
+
items.push(await this.parseTop(item));
|
|
1465
1521
|
}
|
|
1466
1522
|
return createSetNode(id, current.size, items);
|
|
1467
1523
|
}
|
|
@@ -1477,7 +1533,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1477
1533
|
NIL,
|
|
1478
1534
|
NIL,
|
|
1479
1535
|
NIL,
|
|
1480
|
-
await this.
|
|
1536
|
+
await this.parseTop(result),
|
|
1481
1537
|
NIL,
|
|
1482
1538
|
NIL
|
|
1483
1539
|
);
|
|
@@ -1509,7 +1565,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1509
1565
|
const cleanup = current.on({
|
|
1510
1566
|
next: (value) => {
|
|
1511
1567
|
this.markRef(id);
|
|
1512
|
-
this.
|
|
1568
|
+
this.parseTop(value).then(
|
|
1513
1569
|
(data) => {
|
|
1514
1570
|
sequence.push(createStreamNextNode(id, data));
|
|
1515
1571
|
},
|
|
@@ -1521,7 +1577,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1521
1577
|
},
|
|
1522
1578
|
throw: (value) => {
|
|
1523
1579
|
this.markRef(id);
|
|
1524
|
-
this.
|
|
1580
|
+
this.parseTop(value).then(
|
|
1525
1581
|
(data) => {
|
|
1526
1582
|
sequence.push(createStreamThrowNode(id, data));
|
|
1527
1583
|
resolve(sequence);
|
|
@@ -1535,7 +1591,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1535
1591
|
},
|
|
1536
1592
|
return: (value) => {
|
|
1537
1593
|
this.markRef(id);
|
|
1538
|
-
this.
|
|
1594
|
+
this.parseTop(value).then(
|
|
1539
1595
|
(data) => {
|
|
1540
1596
|
sequence.push(createStreamReturnNode(id, data));
|
|
1541
1597
|
resolve(sequence);
|
|
@@ -1551,28 +1607,6 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1551
1607
|
})
|
|
1552
1608
|
);
|
|
1553
1609
|
}
|
|
1554
|
-
async parseAbortSignalSync(id, current) {
|
|
1555
|
-
return createSerovalNode(
|
|
1556
|
-
37 /* AbortSignalSync */,
|
|
1557
|
-
id,
|
|
1558
|
-
NIL,
|
|
1559
|
-
NIL,
|
|
1560
|
-
NIL,
|
|
1561
|
-
NIL,
|
|
1562
|
-
NIL,
|
|
1563
|
-
NIL,
|
|
1564
|
-
NIL,
|
|
1565
|
-
await this.parse(current.reason),
|
|
1566
|
-
NIL,
|
|
1567
|
-
NIL
|
|
1568
|
-
);
|
|
1569
|
-
}
|
|
1570
|
-
async parseAbortSignal(id, current) {
|
|
1571
|
-
if (!current.aborted) {
|
|
1572
|
-
await abortSignalToPromise(current);
|
|
1573
|
-
}
|
|
1574
|
-
return this.parseAbortSignalSync(id, current);
|
|
1575
|
-
}
|
|
1576
1610
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: ehh
|
|
1577
1611
|
async parseObject(id, current) {
|
|
1578
1612
|
if (Array.isArray(current)) {
|
|
@@ -1583,7 +1617,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1583
1617
|
}
|
|
1584
1618
|
const currentClass = current.constructor;
|
|
1585
1619
|
if (currentClass === OpaqueReference) {
|
|
1586
|
-
return this.
|
|
1620
|
+
return this.parseTop(
|
|
1587
1621
|
current.replacement
|
|
1588
1622
|
);
|
|
1589
1623
|
}
|
|
@@ -1646,9 +1680,6 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1646
1680
|
return this.parsePromise(id, current);
|
|
1647
1681
|
}
|
|
1648
1682
|
const currentFeatures = this.features;
|
|
1649
|
-
if (currentFeatures & 32 /* AbortSignal */ && typeof AbortSignal !== "undefined" && currentClass === AbortSignal) {
|
|
1650
|
-
return this.parseAbortSignal(id, current);
|
|
1651
|
-
}
|
|
1652
1683
|
if (currentFeatures & 16 /* BigIntTypedArray */) {
|
|
1653
1684
|
switch (currentClass) {
|
|
1654
1685
|
case BigInt64Array:
|
|
@@ -1683,35 +1714,38 @@ var BaseAsyncParserContext = class extends BaseParserContext {
|
|
|
1683
1714
|
}
|
|
1684
1715
|
throw new SerovalUnsupportedTypeError(current);
|
|
1685
1716
|
}
|
|
1686
|
-
async
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
return ref.type === 0 ? await this.parseObject(ref.value, current) : ref.value;
|
|
1703
|
-
}
|
|
1704
|
-
return NULL_NODE;
|
|
1717
|
+
async parseTop(current) {
|
|
1718
|
+
switch (typeof current) {
|
|
1719
|
+
case "boolean":
|
|
1720
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
1721
|
+
case "undefined":
|
|
1722
|
+
return UNDEFINED_NODE;
|
|
1723
|
+
case "string":
|
|
1724
|
+
return createStringNode(current);
|
|
1725
|
+
case "number":
|
|
1726
|
+
return createNumberNode(current);
|
|
1727
|
+
case "bigint":
|
|
1728
|
+
return createBigIntNode(current);
|
|
1729
|
+
case "object": {
|
|
1730
|
+
if (current) {
|
|
1731
|
+
const ref = this.getReference(current);
|
|
1732
|
+
return ref.type === 0 ? await this.parseObject(ref.value, current) : ref.value;
|
|
1705
1733
|
}
|
|
1706
|
-
|
|
1707
|
-
return this.parseWellKnownSymbol(current);
|
|
1708
|
-
case "function":
|
|
1709
|
-
return this.parseFunction(current);
|
|
1710
|
-
default:
|
|
1711
|
-
throw new SerovalUnsupportedTypeError(current);
|
|
1734
|
+
return NULL_NODE;
|
|
1712
1735
|
}
|
|
1736
|
+
case "symbol":
|
|
1737
|
+
return this.parseWellKnownSymbol(current);
|
|
1738
|
+
case "function":
|
|
1739
|
+
return this.parseFunction(current);
|
|
1740
|
+
default:
|
|
1741
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
async parse(current) {
|
|
1745
|
+
try {
|
|
1746
|
+
return await this.parseTop(current);
|
|
1713
1747
|
} catch (error) {
|
|
1714
|
-
throw new SerovalParserError(error);
|
|
1748
|
+
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
1715
1749
|
}
|
|
1716
1750
|
}
|
|
1717
1751
|
};
|
|
@@ -1982,21 +2016,6 @@ var BaseDeserializerContext = class {
|
|
|
1982
2016
|
this.deserialize(node.a[1]);
|
|
1983
2017
|
return void 0;
|
|
1984
2018
|
}
|
|
1985
|
-
deserializeAbortSignalConstructor(node) {
|
|
1986
|
-
return this.assignIndexedValue(node.i, new AbortController()).signal;
|
|
1987
|
-
}
|
|
1988
|
-
deserializeAbortSignalAbort(node) {
|
|
1989
|
-
const controller = this.refs.get(node.i);
|
|
1990
|
-
assert(controller, new SerovalMissingInstanceError("AbortSignal"));
|
|
1991
|
-
controller.abort(this.deserialize(node.a[1]));
|
|
1992
|
-
return void 0;
|
|
1993
|
-
}
|
|
1994
|
-
deserializeAbortSignalSync(node) {
|
|
1995
|
-
return this.assignIndexedValue(
|
|
1996
|
-
node.i,
|
|
1997
|
-
AbortSignal.abort(this.deserialize(node.f))
|
|
1998
|
-
);
|
|
1999
|
-
}
|
|
2000
2019
|
deserialize(node) {
|
|
2001
2020
|
try {
|
|
2002
2021
|
switch (node.t) {
|
|
@@ -2046,9 +2065,9 @@ var BaseDeserializerContext = class {
|
|
|
2046
2065
|
return this.deserializePlugin(node);
|
|
2047
2066
|
case 22 /* PromiseConstructor */:
|
|
2048
2067
|
return this.deserializePromiseConstructor(node);
|
|
2049
|
-
case 23 /*
|
|
2068
|
+
case 23 /* PromiseSuccess */:
|
|
2050
2069
|
return this.deserializePromiseResolve(node);
|
|
2051
|
-
case 24 /*
|
|
2070
|
+
case 24 /* PromiseFailure */:
|
|
2052
2071
|
return this.deserializePromiseReject(node);
|
|
2053
2072
|
case 28 /* IteratorFactoryInstance */:
|
|
2054
2073
|
return this.deserializeIteratorFactoryInstance(node);
|
|
@@ -2066,12 +2085,6 @@ var BaseDeserializerContext = class {
|
|
|
2066
2085
|
return this.deserializeIteratorFactory(node);
|
|
2067
2086
|
case 29 /* AsyncIteratorFactory */:
|
|
2068
2087
|
return this.deserializeAsyncIteratorFactory(node);
|
|
2069
|
-
case 36 /* AbortSignalAbort */:
|
|
2070
|
-
return this.deserializeAbortSignalAbort(node);
|
|
2071
|
-
case 35 /* AbortSignalConstructor */:
|
|
2072
|
-
return this.deserializeAbortSignalConstructor(node);
|
|
2073
|
-
case 37 /* AbortSignalSync */:
|
|
2074
|
-
return this.deserializeAbortSignalSync(node);
|
|
2075
2088
|
// case SerovalNodeType.SpecialReference:
|
|
2076
2089
|
default:
|
|
2077
2090
|
throw new SerovalUnsupportedNodeError(node);
|
|
@@ -2202,18 +2215,10 @@ var BaseSerializerContext = class {
|
|
|
2202
2215
|
this.marked = new Set(options.markedRefs);
|
|
2203
2216
|
}
|
|
2204
2217
|
createFunction(parameters, body) {
|
|
2205
|
-
|
|
2206
|
-
const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
|
|
2207
|
-
return joined + "=>" + (body.startsWith("{") ? "(" + body + ")" : body);
|
|
2208
|
-
}
|
|
2209
|
-
return "function(" + parameters.join(",") + "){return " + body + "}";
|
|
2218
|
+
return createFunction(this.features, parameters, body);
|
|
2210
2219
|
}
|
|
2211
2220
|
createEffectfulFunction(parameters, body) {
|
|
2212
|
-
|
|
2213
|
-
const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
|
|
2214
|
-
return joined + "=>{" + body + "}";
|
|
2215
|
-
}
|
|
2216
|
-
return "function(" + parameters.join(",") + "){" + body + "}";
|
|
2221
|
+
return createEffectfulFunction(this.features, parameters, body);
|
|
2217
2222
|
}
|
|
2218
2223
|
/**
|
|
2219
2224
|
* A tiny function that tells if a reference
|
|
@@ -2682,7 +2687,11 @@ var BaseSerializerContext = class {
|
|
|
2682
2687
|
return current === this.getRefParam(node.i) ? current : "(" + current + ")";
|
|
2683
2688
|
}
|
|
2684
2689
|
serializePromiseConstructor(node) {
|
|
2685
|
-
|
|
2690
|
+
const resolver = this.assignIndexedValue(node.s, "{p:0,s:0,f:0}");
|
|
2691
|
+
return this.assignIndexedValue(
|
|
2692
|
+
node.i,
|
|
2693
|
+
this.getConstructor(node.f) + "(" + resolver + ")"
|
|
2694
|
+
);
|
|
2686
2695
|
}
|
|
2687
2696
|
serializePromiseResolve(node) {
|
|
2688
2697
|
return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
|
|
@@ -2690,63 +2699,10 @@ var BaseSerializerContext = class {
|
|
|
2690
2699
|
serializePromiseReject(node) {
|
|
2691
2700
|
return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
|
|
2692
2701
|
}
|
|
2693
|
-
serializeSpecialReferenceValue(ref) {
|
|
2694
|
-
switch (ref) {
|
|
2695
|
-
case 0 /* MapSentinel */:
|
|
2696
|
-
return "[]";
|
|
2697
|
-
case 1 /* PromiseConstructor */:
|
|
2698
|
-
return this.createFunction(
|
|
2699
|
-
["s", "f", "p"],
|
|
2700
|
-
"((p=new Promise(" + this.createEffectfulFunction(["a", "b"], "s=a,f=b") + ")).s=s,p.f=f,p)"
|
|
2701
|
-
);
|
|
2702
|
-
case 2 /* PromiseResolve */:
|
|
2703
|
-
return this.createEffectfulFunction(
|
|
2704
|
-
["p", "d"],
|
|
2705
|
-
'p.s(d),p.status="success",p.value=d;delete p.s;delete p.f'
|
|
2706
|
-
);
|
|
2707
|
-
case 3 /* PromiseReject */:
|
|
2708
|
-
return this.createEffectfulFunction(
|
|
2709
|
-
["p", "d"],
|
|
2710
|
-
'p.f(d),p.status="failure",p.value=d;delete p.s;delete p.f'
|
|
2711
|
-
);
|
|
2712
|
-
case 4 /* StreamConstructor */:
|
|
2713
|
-
return this.createFunction(
|
|
2714
|
-
["b", "a", "s", "l", "p", "f", "e", "n"],
|
|
2715
|
-
"(b=[],a=!0,s=!1,l=[],p=0,f=" + this.createEffectfulFunction(
|
|
2716
|
-
["v", "m", "x"],
|
|
2717
|
-
"for(x=0;x<p;x++)l[x]&&l[x][m](v)"
|
|
2718
|
-
) + ",n=" + this.createEffectfulFunction(
|
|
2719
|
-
["o", "x", "z", "c"],
|
|
2720
|
-
'for(x=0,z=b.length;x<z;x++)(c=b[x],(!a&&x===z-1)?o[s?"return":"throw"](c):o.next(c))'
|
|
2721
|
-
) + ",e=" + this.createFunction(
|
|
2722
|
-
["o", "t"],
|
|
2723
|
-
"(a&&(l[t=p++]=o),n(o)," + this.createEffectfulFunction([], "a&&(l[t]=void 0)") + ")"
|
|
2724
|
-
) + ",{__SEROVAL_STREAM__:!0,on:" + this.createFunction(["o"], "e(o)") + ",next:" + this.createEffectfulFunction(["v"], 'a&&(b.push(v),f(v,"next"))') + ",throw:" + this.createEffectfulFunction(
|
|
2725
|
-
["v"],
|
|
2726
|
-
'a&&(b.push(v),f(v,"throw"),a=s=!1,l.length=0)'
|
|
2727
|
-
) + ",return:" + this.createEffectfulFunction(
|
|
2728
|
-
["v"],
|
|
2729
|
-
'a&&(b.push(v),f(v,"return"),a=!1,s=!0,l.length=0)'
|
|
2730
|
-
) + "})"
|
|
2731
|
-
);
|
|
2732
|
-
case 5 /* AbortSignalConstructor */:
|
|
2733
|
-
return this.createFunction(
|
|
2734
|
-
["a", "s"],
|
|
2735
|
-
"((s=(a=new AbortController).signal).a=a,s)"
|
|
2736
|
-
);
|
|
2737
|
-
case 6 /* AbortSignalAbort */:
|
|
2738
|
-
return this.createEffectfulFunction(
|
|
2739
|
-
["s", "r"],
|
|
2740
|
-
"s.a.abort(r);delete s.a"
|
|
2741
|
-
);
|
|
2742
|
-
default:
|
|
2743
|
-
return "";
|
|
2744
|
-
}
|
|
2745
|
-
}
|
|
2746
2702
|
serializeSpecialReference(node) {
|
|
2747
2703
|
return this.assignIndexedValue(
|
|
2748
2704
|
node.i,
|
|
2749
|
-
this.
|
|
2705
|
+
serializeSpecialReferenceValue(this.features, node.s)
|
|
2750
2706
|
);
|
|
2751
2707
|
}
|
|
2752
2708
|
serializeIteratorFactory(node) {
|
|
@@ -2799,6 +2755,15 @@ var BaseSerializerContext = class {
|
|
|
2799
2755
|
["s"],
|
|
2800
2756
|
this.createFunction(
|
|
2801
2757
|
["b", "c", "p", "d", "e", "t", "f"],
|
|
2758
|
+
/**
|
|
2759
|
+
* b = resolved values
|
|
2760
|
+
* c = b size
|
|
2761
|
+
* p = pending promises
|
|
2762
|
+
* d = index where the resolved value stops
|
|
2763
|
+
* e = if the last value is a throw
|
|
2764
|
+
* t = placeholder variable
|
|
2765
|
+
* f = finalize
|
|
2766
|
+
*/
|
|
2802
2767
|
"(b=[],c=0,p=[],d=-1,e=!1,f=" + this.createEffectfulFunction(
|
|
2803
2768
|
["i", "l"],
|
|
2804
2769
|
"for(i=0,l=p.length;i<l;i++)p[i].s({done:!0,value:void 0})"
|
|
@@ -2811,9 +2776,9 @@ var BaseSerializerContext = class {
|
|
|
2811
2776
|
) + ",return:" + this.createEffectfulFunction(
|
|
2812
2777
|
["v", "t"],
|
|
2813
2778
|
"if(t=p.shift())t.s({done:!0,value:v});f(),d=b.length,b.push(v)"
|
|
2814
|
-
) + "}),t={[" + this.getRefParam(symbol.i) + "]:" + this.createFunction([], "t") + ",next:" + this.createEffectfulFunction(
|
|
2779
|
+
) + "}),t={[" + this.getRefParam(symbol.i) + "]:" + this.createFunction([], "t.p") + ",next:" + this.createEffectfulFunction(
|
|
2815
2780
|
["i", "t", "v"],
|
|
2816
|
-
"if(d===-1){return((i=c++)>=b.length)?(
|
|
2781
|
+
"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}"
|
|
2817
2782
|
) + "})"
|
|
2818
2783
|
)
|
|
2819
2784
|
)
|
|
@@ -2850,18 +2815,6 @@ var BaseSerializerContext = class {
|
|
|
2850
2815
|
serializeStreamReturn(node) {
|
|
2851
2816
|
return this.getRefParam(node.i) + ".return(" + this.serialize(node.f) + ")";
|
|
2852
2817
|
}
|
|
2853
|
-
serializeAbortSignalSync(node) {
|
|
2854
|
-
return this.assignIndexedValue(
|
|
2855
|
-
node.i,
|
|
2856
|
-
"AbortSignal.abort(" + this.serialize(node.f) + ")"
|
|
2857
|
-
);
|
|
2858
|
-
}
|
|
2859
|
-
serializeAbortSignalConstructor(node) {
|
|
2860
|
-
return this.assignIndexedValue(node.i, this.getConstructor(node.f) + "()");
|
|
2861
|
-
}
|
|
2862
|
-
serializeAbortSignalAbort(node) {
|
|
2863
|
-
return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
|
|
2864
|
-
}
|
|
2865
2818
|
serialize(node) {
|
|
2866
2819
|
try {
|
|
2867
2820
|
switch (node.t) {
|
|
@@ -2910,9 +2863,9 @@ var BaseSerializerContext = class {
|
|
|
2910
2863
|
return this.serializeBoxed(node);
|
|
2911
2864
|
case 22 /* PromiseConstructor */:
|
|
2912
2865
|
return this.serializePromiseConstructor(node);
|
|
2913
|
-
case 23 /*
|
|
2866
|
+
case 23 /* PromiseSuccess */:
|
|
2914
2867
|
return this.serializePromiseResolve(node);
|
|
2915
|
-
case 24 /*
|
|
2868
|
+
case 24 /* PromiseFailure */:
|
|
2916
2869
|
return this.serializePromiseReject(node);
|
|
2917
2870
|
case 25 /* Plugin */:
|
|
2918
2871
|
return this.serializePlugin(node);
|
|
@@ -2934,12 +2887,6 @@ var BaseSerializerContext = class {
|
|
|
2934
2887
|
return this.serializeStreamThrow(node);
|
|
2935
2888
|
case 34 /* StreamReturn */:
|
|
2936
2889
|
return this.serializeStreamReturn(node);
|
|
2937
|
-
case 36 /* AbortSignalAbort */:
|
|
2938
|
-
return this.serializeAbortSignalAbort(node);
|
|
2939
|
-
case 35 /* AbortSignalConstructor */:
|
|
2940
|
-
return this.serializeAbortSignalConstructor(node);
|
|
2941
|
-
case 37 /* AbortSignalSync */:
|
|
2942
|
-
return this.serializeAbortSignalSync(node);
|
|
2943
2890
|
default:
|
|
2944
2891
|
throw new SerovalUnsupportedNodeError(node);
|
|
2945
2892
|
}
|
|
@@ -2989,7 +2936,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
2989
2936
|
const nodes = [];
|
|
2990
2937
|
for (let i = 0, len = current.length; i < len; i++) {
|
|
2991
2938
|
if (i in current) {
|
|
2992
|
-
nodes[i] = this.
|
|
2939
|
+
nodes[i] = this.parseTop(current[i]);
|
|
2993
2940
|
}
|
|
2994
2941
|
}
|
|
2995
2942
|
return nodes;
|
|
@@ -3003,7 +2950,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3003
2950
|
const valueNodes = [];
|
|
3004
2951
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
3005
2952
|
keyNodes.push(serializeString(entries[i][0]));
|
|
3006
|
-
valueNodes.push(this.
|
|
2953
|
+
valueNodes.push(this.parseTop(entries[i][1]));
|
|
3007
2954
|
}
|
|
3008
2955
|
let symbol = Symbol.iterator;
|
|
3009
2956
|
if (symbol in properties) {
|
|
@@ -3011,7 +2958,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3011
2958
|
valueNodes.push(
|
|
3012
2959
|
createIteratorFactoryInstanceNode(
|
|
3013
2960
|
this.parseIteratorFactory(),
|
|
3014
|
-
this.
|
|
2961
|
+
this.parseTop(
|
|
3015
2962
|
iteratorToSequence(properties)
|
|
3016
2963
|
)
|
|
3017
2964
|
)
|
|
@@ -3023,7 +2970,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3023
2970
|
valueNodes.push(
|
|
3024
2971
|
createAsyncIteratorFactoryInstanceNode(
|
|
3025
2972
|
this.parseAsyncIteratorFactory(),
|
|
3026
|
-
this.
|
|
2973
|
+
this.parseTop(createStream())
|
|
3027
2974
|
)
|
|
3028
2975
|
);
|
|
3029
2976
|
}
|
|
@@ -3052,16 +2999,20 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3052
2999
|
);
|
|
3053
3000
|
}
|
|
3054
3001
|
parseBoxed(id, current) {
|
|
3055
|
-
return createBoxedNode(id, this.
|
|
3002
|
+
return createBoxedNode(id, this.parseTop(current.valueOf()));
|
|
3056
3003
|
}
|
|
3057
3004
|
parseTypedArray(id, current) {
|
|
3058
|
-
return createTypedArrayNode(id, current, this.
|
|
3005
|
+
return createTypedArrayNode(id, current, this.parseTop(current.buffer));
|
|
3059
3006
|
}
|
|
3060
3007
|
parseBigIntTypedArray(id, current) {
|
|
3061
|
-
return createBigIntTypedArrayNode(
|
|
3008
|
+
return createBigIntTypedArrayNode(
|
|
3009
|
+
id,
|
|
3010
|
+
current,
|
|
3011
|
+
this.parseTop(current.buffer)
|
|
3012
|
+
);
|
|
3062
3013
|
}
|
|
3063
3014
|
parseDataView(id, current) {
|
|
3064
|
-
return createDataViewNode(id, current, this.
|
|
3015
|
+
return createDataViewNode(id, current, this.parseTop(current.buffer));
|
|
3065
3016
|
}
|
|
3066
3017
|
parseError(id, current) {
|
|
3067
3018
|
const options = getErrorOptions(current, this.features);
|
|
@@ -3083,15 +3034,15 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3083
3034
|
const keyNodes = [];
|
|
3084
3035
|
const valueNodes = [];
|
|
3085
3036
|
for (const [key, value] of current.entries()) {
|
|
3086
|
-
keyNodes.push(this.
|
|
3087
|
-
valueNodes.push(this.
|
|
3037
|
+
keyNodes.push(this.parseTop(key));
|
|
3038
|
+
valueNodes.push(this.parseTop(value));
|
|
3088
3039
|
}
|
|
3089
3040
|
return this.createMapNode(id, keyNodes, valueNodes, current.size);
|
|
3090
3041
|
}
|
|
3091
3042
|
parseSet(id, current) {
|
|
3092
3043
|
const items = [];
|
|
3093
3044
|
for (const item of current.keys()) {
|
|
3094
|
-
items.push(this.
|
|
3045
|
+
items.push(this.parseTop(item));
|
|
3095
3046
|
}
|
|
3096
3047
|
return createSetNode(id, current.size, items);
|
|
3097
3048
|
}
|
|
@@ -3121,29 +3072,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3121
3072
|
);
|
|
3122
3073
|
}
|
|
3123
3074
|
parsePromise(id, _current) {
|
|
3124
|
-
return this.createPromiseConstructorNode(id);
|
|
3125
|
-
}
|
|
3126
|
-
parseAbortSignalSync(id, current) {
|
|
3127
|
-
return createSerovalNode(
|
|
3128
|
-
37 /* AbortSignalSync */,
|
|
3129
|
-
id,
|
|
3130
|
-
NIL,
|
|
3131
|
-
NIL,
|
|
3132
|
-
NIL,
|
|
3133
|
-
NIL,
|
|
3134
|
-
NIL,
|
|
3135
|
-
NIL,
|
|
3136
|
-
NIL,
|
|
3137
|
-
this.parse(current.reason),
|
|
3138
|
-
NIL,
|
|
3139
|
-
NIL
|
|
3140
|
-
);
|
|
3141
|
-
}
|
|
3142
|
-
parseAbortSignal(id, current) {
|
|
3143
|
-
if (current.aborted) {
|
|
3144
|
-
return this.parseAbortSignalSync(id, current);
|
|
3145
|
-
}
|
|
3146
|
-
return this.createAbortSignalConstructorNode(id);
|
|
3075
|
+
return this.createPromiseConstructorNode(id, this.createIndex({}));
|
|
3147
3076
|
}
|
|
3148
3077
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: ehh
|
|
3149
3078
|
parseObject(id, current) {
|
|
@@ -3155,7 +3084,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3155
3084
|
}
|
|
3156
3085
|
const currentClass = current.constructor;
|
|
3157
3086
|
if (currentClass === OpaqueReference) {
|
|
3158
|
-
return this.
|
|
3087
|
+
return this.parseTop(
|
|
3159
3088
|
current.replacement
|
|
3160
3089
|
);
|
|
3161
3090
|
}
|
|
@@ -3218,9 +3147,6 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3218
3147
|
return this.parsePromise(id, current);
|
|
3219
3148
|
}
|
|
3220
3149
|
const currentFeatures = this.features;
|
|
3221
|
-
if (currentFeatures & 32 /* AbortSignal */ && typeof AbortSignal !== "undefined" && currentClass === AbortSignal) {
|
|
3222
|
-
return this.parseAbortSignal(id, current);
|
|
3223
|
-
}
|
|
3224
3150
|
if (currentFeatures & 16 /* BigIntTypedArray */) {
|
|
3225
3151
|
switch (currentClass) {
|
|
3226
3152
|
case BigInt64Array:
|
|
@@ -3255,36 +3181,39 @@ var BaseSyncParserContext = class extends BaseParserContext {
|
|
|
3255
3181
|
}
|
|
3256
3182
|
throw new SerovalUnsupportedTypeError(current);
|
|
3257
3183
|
}
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
return ref.type === 0 /* Fresh */ ? this.parseObject(ref.value, current) : ref.value;
|
|
3275
|
-
}
|
|
3276
|
-
return NULL_NODE;
|
|
3277
|
-
}
|
|
3278
|
-
case "symbol":
|
|
3279
|
-
return this.parseWellKnownSymbol(current);
|
|
3280
|
-
case "function": {
|
|
3281
|
-
return this.parseFunction(current);
|
|
3184
|
+
parseTop(current) {
|
|
3185
|
+
switch (typeof current) {
|
|
3186
|
+
case "boolean":
|
|
3187
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
3188
|
+
case "undefined":
|
|
3189
|
+
return UNDEFINED_NODE;
|
|
3190
|
+
case "string":
|
|
3191
|
+
return createStringNode(current);
|
|
3192
|
+
case "number":
|
|
3193
|
+
return createNumberNode(current);
|
|
3194
|
+
case "bigint":
|
|
3195
|
+
return createBigIntNode(current);
|
|
3196
|
+
case "object": {
|
|
3197
|
+
if (current) {
|
|
3198
|
+
const ref = this.getReference(current);
|
|
3199
|
+
return ref.type === 0 /* Fresh */ ? this.parseObject(ref.value, current) : ref.value;
|
|
3282
3200
|
}
|
|
3283
|
-
|
|
3284
|
-
|
|
3201
|
+
return NULL_NODE;
|
|
3202
|
+
}
|
|
3203
|
+
case "symbol":
|
|
3204
|
+
return this.parseWellKnownSymbol(current);
|
|
3205
|
+
case "function": {
|
|
3206
|
+
return this.parseFunction(current);
|
|
3285
3207
|
}
|
|
3208
|
+
default:
|
|
3209
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
parse(current) {
|
|
3213
|
+
try {
|
|
3214
|
+
return this.parseTop(current);
|
|
3286
3215
|
} catch (error) {
|
|
3287
|
-
throw new SerovalParserError(error);
|
|
3216
|
+
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3288
3217
|
}
|
|
3289
3218
|
}
|
|
3290
3219
|
};
|
|
@@ -3348,7 +3277,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3348
3277
|
const valueNodes = [];
|
|
3349
3278
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
3350
3279
|
keyNodes.push(serializeString(entries[i][0]));
|
|
3351
|
-
valueNodes.push(this.
|
|
3280
|
+
valueNodes.push(this.parseTop(entries[i][1]));
|
|
3352
3281
|
}
|
|
3353
3282
|
let symbol = Symbol.iterator;
|
|
3354
3283
|
if (symbol in properties) {
|
|
@@ -3356,7 +3285,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3356
3285
|
valueNodes.push(
|
|
3357
3286
|
createIteratorFactoryInstanceNode(
|
|
3358
3287
|
this.parseIteratorFactory(),
|
|
3359
|
-
this.
|
|
3288
|
+
this.parseTop(
|
|
3360
3289
|
iteratorToSequence(properties)
|
|
3361
3290
|
)
|
|
3362
3291
|
)
|
|
@@ -3368,7 +3297,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3368
3297
|
valueNodes.push(
|
|
3369
3298
|
createAsyncIteratorFactoryInstanceNode(
|
|
3370
3299
|
this.parseAsyncIteratorFactory(),
|
|
3371
|
-
this.
|
|
3300
|
+
this.parseTop(
|
|
3372
3301
|
createStreamFromAsyncIterable(
|
|
3373
3302
|
properties
|
|
3374
3303
|
)
|
|
@@ -3392,63 +3321,63 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3392
3321
|
s: keyNodes.length
|
|
3393
3322
|
};
|
|
3394
3323
|
}
|
|
3324
|
+
handlePromiseSuccess(id, data) {
|
|
3325
|
+
const parsed = this.parseWithError(data);
|
|
3326
|
+
if (parsed) {
|
|
3327
|
+
this.onParse(
|
|
3328
|
+
createSerovalNode(
|
|
3329
|
+
23 /* PromiseSuccess */,
|
|
3330
|
+
id,
|
|
3331
|
+
NIL,
|
|
3332
|
+
NIL,
|
|
3333
|
+
NIL,
|
|
3334
|
+
NIL,
|
|
3335
|
+
NIL,
|
|
3336
|
+
NIL,
|
|
3337
|
+
[this.parseSpecialReference(2 /* PromiseSuccess */), parsed],
|
|
3338
|
+
NIL,
|
|
3339
|
+
NIL,
|
|
3340
|
+
NIL
|
|
3341
|
+
)
|
|
3342
|
+
);
|
|
3343
|
+
}
|
|
3344
|
+
this.popPendingState();
|
|
3345
|
+
}
|
|
3346
|
+
handlePromiseFailure(id, data) {
|
|
3347
|
+
if (this.alive) {
|
|
3348
|
+
const parsed = this.parseWithError(data);
|
|
3349
|
+
if (parsed) {
|
|
3350
|
+
this.onParse(
|
|
3351
|
+
createSerovalNode(
|
|
3352
|
+
24 /* PromiseFailure */,
|
|
3353
|
+
id,
|
|
3354
|
+
NIL,
|
|
3355
|
+
NIL,
|
|
3356
|
+
NIL,
|
|
3357
|
+
NIL,
|
|
3358
|
+
NIL,
|
|
3359
|
+
NIL,
|
|
3360
|
+
[
|
|
3361
|
+
this.parseSpecialReference(3 /* PromiseFailure */),
|
|
3362
|
+
parsed
|
|
3363
|
+
],
|
|
3364
|
+
NIL,
|
|
3365
|
+
NIL,
|
|
3366
|
+
NIL
|
|
3367
|
+
)
|
|
3368
|
+
);
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
this.popPendingState();
|
|
3372
|
+
}
|
|
3395
3373
|
parsePromise(id, current) {
|
|
3374
|
+
const resolver = this.createIndex({});
|
|
3396
3375
|
current.then(
|
|
3397
|
-
(
|
|
3398
|
-
|
|
3399
|
-
if (parsed) {
|
|
3400
|
-
this.onParse(
|
|
3401
|
-
createSerovalNode(
|
|
3402
|
-
23 /* PromiseResolve */,
|
|
3403
|
-
id,
|
|
3404
|
-
NIL,
|
|
3405
|
-
NIL,
|
|
3406
|
-
NIL,
|
|
3407
|
-
NIL,
|
|
3408
|
-
NIL,
|
|
3409
|
-
NIL,
|
|
3410
|
-
[
|
|
3411
|
-
this.parseSpecialReference(2 /* PromiseResolve */),
|
|
3412
|
-
parsed
|
|
3413
|
-
],
|
|
3414
|
-
NIL,
|
|
3415
|
-
NIL,
|
|
3416
|
-
NIL
|
|
3417
|
-
)
|
|
3418
|
-
);
|
|
3419
|
-
}
|
|
3420
|
-
this.popPendingState();
|
|
3421
|
-
},
|
|
3422
|
-
(data) => {
|
|
3423
|
-
if (this.alive) {
|
|
3424
|
-
const parsed = this.parseWithError(data);
|
|
3425
|
-
if (parsed) {
|
|
3426
|
-
this.onParse(
|
|
3427
|
-
createSerovalNode(
|
|
3428
|
-
24 /* PromiseReject */,
|
|
3429
|
-
id,
|
|
3430
|
-
NIL,
|
|
3431
|
-
NIL,
|
|
3432
|
-
NIL,
|
|
3433
|
-
NIL,
|
|
3434
|
-
NIL,
|
|
3435
|
-
NIL,
|
|
3436
|
-
[
|
|
3437
|
-
this.parseSpecialReference(3 /* PromiseReject */),
|
|
3438
|
-
parsed
|
|
3439
|
-
],
|
|
3440
|
-
NIL,
|
|
3441
|
-
NIL,
|
|
3442
|
-
NIL
|
|
3443
|
-
)
|
|
3444
|
-
);
|
|
3445
|
-
}
|
|
3446
|
-
}
|
|
3447
|
-
this.popPendingState();
|
|
3448
|
-
}
|
|
3376
|
+
this.handlePromiseSuccess.bind(this, resolver),
|
|
3377
|
+
this.handlePromiseFailure.bind(this, resolver)
|
|
3449
3378
|
);
|
|
3450
3379
|
this.pushPendingState();
|
|
3451
|
-
return this.createPromiseConstructorNode(id);
|
|
3380
|
+
return this.createPromiseConstructorNode(id, resolver);
|
|
3452
3381
|
}
|
|
3453
3382
|
parsePlugin(id, current) {
|
|
3454
3383
|
const currentPlugins = this.plugins;
|
|
@@ -3505,48 +3434,9 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
|
|
|
3505
3434
|
});
|
|
3506
3435
|
return result;
|
|
3507
3436
|
}
|
|
3508
|
-
handleAbortSignal(id, current) {
|
|
3509
|
-
if (this.alive) {
|
|
3510
|
-
const parsed = this.parseWithError(current.reason);
|
|
3511
|
-
if (parsed) {
|
|
3512
|
-
this.onParse(
|
|
3513
|
-
createSerovalNode(
|
|
3514
|
-
36 /* AbortSignalAbort */,
|
|
3515
|
-
id,
|
|
3516
|
-
NIL,
|
|
3517
|
-
NIL,
|
|
3518
|
-
NIL,
|
|
3519
|
-
NIL,
|
|
3520
|
-
NIL,
|
|
3521
|
-
NIL,
|
|
3522
|
-
[
|
|
3523
|
-
this.parseSpecialReference(6 /* AbortSignalAbort */),
|
|
3524
|
-
parsed
|
|
3525
|
-
],
|
|
3526
|
-
NIL,
|
|
3527
|
-
NIL,
|
|
3528
|
-
NIL
|
|
3529
|
-
)
|
|
3530
|
-
);
|
|
3531
|
-
}
|
|
3532
|
-
}
|
|
3533
|
-
this.popPendingState();
|
|
3534
|
-
}
|
|
3535
|
-
parseAbortSignal(id, current) {
|
|
3536
|
-
if (current.aborted) {
|
|
3537
|
-
return this.parseAbortSignalSync(id, current);
|
|
3538
|
-
}
|
|
3539
|
-
this.pushPendingState();
|
|
3540
|
-
current.addEventListener(
|
|
3541
|
-
"abort",
|
|
3542
|
-
this.handleAbortSignal.bind(this, id, current),
|
|
3543
|
-
{ once: true }
|
|
3544
|
-
);
|
|
3545
|
-
return this.createAbortSignalConstructorNode(id);
|
|
3546
|
-
}
|
|
3547
3437
|
parseWithError(current) {
|
|
3548
3438
|
try {
|
|
3549
|
-
return this.
|
|
3439
|
+
return this.parseTop(current);
|
|
3550
3440
|
} catch (err) {
|
|
3551
3441
|
this.onError(err);
|
|
3552
3442
|
return NIL;
|
|
@@ -3787,9 +3677,6 @@ var VanillaSerializerContext = class extends BaseSerializerContext {
|
|
|
3787
3677
|
serializePromiseReject(node) {
|
|
3788
3678
|
throw new SerovalUnsupportedNodeError(node);
|
|
3789
3679
|
}
|
|
3790
|
-
serializeAbortSignalAbort(node) {
|
|
3791
|
-
throw new SerovalUnsupportedNodeError(node);
|
|
3792
|
-
}
|
|
3793
3680
|
serializeTop(tree) {
|
|
3794
3681
|
const result = this.serialize(tree);
|
|
3795
3682
|
if (tree.i != null && this.vars.length) {
|