seroval 1.4.0 → 1.4.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/dist/cjs/development/index.cjs +524 -364
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +524 -364
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/base-primitives.d.ts +2 -2
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/compat.d.ts +2 -1
- package/dist/types/core/compat.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +2 -2
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/constructors.d.ts +1 -1
- package/dist/types/core/constructors.d.ts.map +1 -1
- package/dist/types/core/context/async-parser.d.ts +5 -4
- package/dist/types/core/context/async-parser.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts +7 -2
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +3 -1
- package/dist/types/core/context/parser.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/context/sync-parser.d.ts +5 -5
- package/dist/types/core/context/sync-parser.d.ts.map +1 -1
- package/dist/types/core/cross/index.d.ts.map +1 -1
- package/dist/types/core/errors.d.ts +9 -0
- package/dist/types/core/errors.d.ts.map +1 -1
- package/dist/types/core/literals.d.ts.map +1 -1
- package/dist/types/core/node.d.ts +1 -1
- package/dist/types/core/node.d.ts.map +1 -1
- package/dist/types/core/string.d.ts.map +1 -1
- package/dist/types/core/tree/index.d.ts +4 -1
- package/dist/types/core/tree/index.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +2 -11
- package/dist/types/core/types.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/core/Serializer.ts +0 -119
- package/src/core/base-primitives.ts +0 -515
- package/src/core/compat.ts +0 -21
- package/src/core/constants.ts +0 -187
- package/src/core/constructors.ts +0 -269
- package/src/core/context/async-parser.ts +0 -586
- package/src/core/context/deserializer.ts +0 -646
- package/src/core/context/parser.ts +0 -333
- package/src/core/context/serializer.ts +0 -1411
- package/src/core/context/sync-parser.ts +0 -833
- package/src/core/cross/index.ts +0 -186
- package/src/core/errors.ts +0 -163
- package/src/core/function-string.ts +0 -32
- package/src/core/keys.ts +0 -17
- package/src/core/literals.ts +0 -43
- package/src/core/node.ts +0 -40
- package/src/core/opaque-reference.ts +0 -9
- package/src/core/plugin.ts +0 -100
- package/src/core/reference.ts +0 -66
- package/src/core/special-reference.ts +0 -42
- package/src/core/stream.ts +0 -71
- package/src/core/string.ts +0 -84
- package/src/core/symbols.ts +0 -18
- package/src/core/tree/index.ts +0 -125
- package/src/core/types.ts +0 -375
- package/src/core/utils/error.ts +0 -73
- package/src/core/utils/get-identifier.ts +0 -18
- package/src/core/utils/get-object-flag.ts +0 -14
- package/src/core/utils/is-valid-identifier.ts +0 -12
- package/src/core/utils/iterator-to-sequence.ts +0 -44
- package/src/core/utils/promise-to-result.ts +0 -9
- package/src/core/utils/typed-array.ts +0 -56
- package/src/index.ts +0 -36
|
@@ -23,8 +23,11 @@ __export(src_exports, {
|
|
|
23
23
|
Feature: () => Feature,
|
|
24
24
|
OpaqueReference: () => OpaqueReference,
|
|
25
25
|
Serializer: () => Serializer,
|
|
26
|
+
SerovalConflictedNodeIdError: () => SerovalConflictedNodeIdError,
|
|
27
|
+
SerovalDepthLimitError: () => SerovalDepthLimitError,
|
|
26
28
|
SerovalDeserializationError: () => SerovalDeserializationError,
|
|
27
29
|
SerovalError: () => SerovalError,
|
|
30
|
+
SerovalMalformedNodeError: () => SerovalMalformedNodeError,
|
|
28
31
|
SerovalMissingInstanceError: () => SerovalMissingInstanceError,
|
|
29
32
|
SerovalMissingPluginError: () => SerovalMissingPluginError,
|
|
30
33
|
SerovalMissingReferenceError: () => SerovalMissingReferenceError,
|
|
@@ -64,9 +67,10 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
|
|
|
64
67
|
Feature2[Feature2["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
|
|
65
68
|
Feature2[Feature2["ObjectAssign"] = 8] = "ObjectAssign";
|
|
66
69
|
Feature2[Feature2["BigIntTypedArray"] = 16] = "BigIntTypedArray";
|
|
70
|
+
Feature2[Feature2["RegExp"] = 32] = "RegExp";
|
|
67
71
|
return Feature2;
|
|
68
72
|
})(Feature || {});
|
|
69
|
-
var ALL_ENABLED = 1 /* AggregateError */ | 2 /* ArrowFunction */ | 4 /* ErrorPrototypeStack */ | 8 /* ObjectAssign */ | 16 /* BigIntTypedArray */;
|
|
73
|
+
var ALL_ENABLED = 1 /* AggregateError */ | 2 /* ArrowFunction */ | 4 /* ErrorPrototypeStack */ | 8 /* ObjectAssign */ | 16 /* BigIntTypedArray */ | 32 /* RegExp */;
|
|
70
74
|
|
|
71
75
|
// src/core/symbols.ts
|
|
72
76
|
var SYM_ASYNC_ITERATOR = Symbol.asyncIterator;
|
|
@@ -139,10 +143,11 @@ var CONSTANT_STRING = {
|
|
|
139
143
|
[6 /* NegInf */]: "-1/0",
|
|
140
144
|
[7 /* Nan */]: "0/0"
|
|
141
145
|
};
|
|
146
|
+
var NIL = void 0;
|
|
142
147
|
var CONSTANT_VAL = {
|
|
143
148
|
[2 /* True */]: true,
|
|
144
149
|
[3 /* False */]: false,
|
|
145
|
-
[1 /* Undefined */]:
|
|
150
|
+
[1 /* Undefined */]: NIL,
|
|
146
151
|
[0 /* Null */]: null,
|
|
147
152
|
[4 /* NegZero */]: -0,
|
|
148
153
|
[5 /* Inf */]: Number.POSITIVE_INFINITY,
|
|
@@ -167,15 +172,13 @@ var ERROR_CONSTRUCTOR = {
|
|
|
167
172
|
[5 /* TypeError */]: TypeError,
|
|
168
173
|
[6 /* URIError */]: URIError
|
|
169
174
|
};
|
|
170
|
-
var NIL = void 0;
|
|
171
175
|
|
|
172
176
|
// src/core/node.ts
|
|
173
|
-
function createSerovalNode(t, i, s,
|
|
177
|
+
function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o) {
|
|
174
178
|
return {
|
|
175
179
|
t,
|
|
176
180
|
i,
|
|
177
181
|
s,
|
|
178
|
-
l,
|
|
179
182
|
c,
|
|
180
183
|
m,
|
|
181
184
|
p,
|
|
@@ -200,7 +203,6 @@ function createConstantNode(value) {
|
|
|
200
203
|
NIL,
|
|
201
204
|
NIL,
|
|
202
205
|
NIL,
|
|
203
|
-
NIL,
|
|
204
206
|
NIL
|
|
205
207
|
);
|
|
206
208
|
}
|
|
@@ -251,7 +253,7 @@ function serializeChar(str) {
|
|
|
251
253
|
case "\u2029":
|
|
252
254
|
return "\\u2029";
|
|
253
255
|
default:
|
|
254
|
-
return
|
|
256
|
+
return NIL;
|
|
255
257
|
}
|
|
256
258
|
}
|
|
257
259
|
function serializeString(str) {
|
|
@@ -465,7 +467,6 @@ function createNumberNode(value) {
|
|
|
465
467
|
NIL,
|
|
466
468
|
NIL,
|
|
467
469
|
NIL,
|
|
468
|
-
NIL,
|
|
469
470
|
NIL
|
|
470
471
|
);
|
|
471
472
|
}
|
|
@@ -481,7 +482,6 @@ function createStringNode(value) {
|
|
|
481
482
|
NIL,
|
|
482
483
|
NIL,
|
|
483
484
|
NIL,
|
|
484
|
-
NIL,
|
|
485
485
|
NIL
|
|
486
486
|
);
|
|
487
487
|
}
|
|
@@ -497,7 +497,6 @@ function createBigIntNode(current) {
|
|
|
497
497
|
NIL,
|
|
498
498
|
NIL,
|
|
499
499
|
NIL,
|
|
500
|
-
NIL,
|
|
501
500
|
NIL
|
|
502
501
|
);
|
|
503
502
|
}
|
|
@@ -513,7 +512,6 @@ function createIndexedValueNode(id) {
|
|
|
513
512
|
NIL,
|
|
514
513
|
NIL,
|
|
515
514
|
NIL,
|
|
516
|
-
NIL,
|
|
517
515
|
NIL
|
|
518
516
|
);
|
|
519
517
|
}
|
|
@@ -530,7 +528,6 @@ function createDateNode(id, current) {
|
|
|
530
528
|
NIL,
|
|
531
529
|
NIL,
|
|
532
530
|
NIL,
|
|
533
|
-
NIL,
|
|
534
531
|
NIL
|
|
535
532
|
);
|
|
536
533
|
}
|
|
@@ -539,7 +536,6 @@ function createRegExpNode(id, current) {
|
|
|
539
536
|
6 /* RegExp */,
|
|
540
537
|
id,
|
|
541
538
|
NIL,
|
|
542
|
-
NIL,
|
|
543
539
|
serializeString(current.source),
|
|
544
540
|
current.flags,
|
|
545
541
|
NIL,
|
|
@@ -562,7 +558,6 @@ function createWKSymbolNode(id, current) {
|
|
|
562
558
|
NIL,
|
|
563
559
|
NIL,
|
|
564
560
|
NIL,
|
|
565
|
-
NIL,
|
|
566
561
|
NIL
|
|
567
562
|
);
|
|
568
563
|
}
|
|
@@ -578,7 +573,6 @@ function createReferenceNode(id, ref) {
|
|
|
578
573
|
NIL,
|
|
579
574
|
NIL,
|
|
580
575
|
NIL,
|
|
581
|
-
NIL,
|
|
582
576
|
NIL
|
|
583
577
|
);
|
|
584
578
|
}
|
|
@@ -587,7 +581,6 @@ function createPluginNode(id, tag, value) {
|
|
|
587
581
|
25 /* Plugin */,
|
|
588
582
|
id,
|
|
589
583
|
value,
|
|
590
|
-
NIL,
|
|
591
584
|
serializeString(tag),
|
|
592
585
|
NIL,
|
|
593
586
|
NIL,
|
|
@@ -603,7 +596,6 @@ function createArrayNode(id, current, parsedItems) {
|
|
|
603
596
|
9 /* Array */,
|
|
604
597
|
id,
|
|
605
598
|
NIL,
|
|
606
|
-
current.length,
|
|
607
599
|
NIL,
|
|
608
600
|
NIL,
|
|
609
601
|
NIL,
|
|
@@ -624,7 +616,6 @@ function createBoxedNode(id, boxed) {
|
|
|
624
616
|
NIL,
|
|
625
617
|
NIL,
|
|
626
618
|
NIL,
|
|
627
|
-
NIL,
|
|
628
619
|
boxed,
|
|
629
620
|
NIL,
|
|
630
621
|
NIL
|
|
@@ -635,7 +626,6 @@ function createTypedArrayNode(id, current, buffer) {
|
|
|
635
626
|
15 /* TypedArray */,
|
|
636
627
|
id,
|
|
637
628
|
NIL,
|
|
638
|
-
current.length,
|
|
639
629
|
current.constructor.name,
|
|
640
630
|
NIL,
|
|
641
631
|
NIL,
|
|
@@ -651,7 +641,6 @@ function createBigIntTypedArrayNode(id, current, buffer) {
|
|
|
651
641
|
16 /* BigIntTypedArray */,
|
|
652
642
|
id,
|
|
653
643
|
NIL,
|
|
654
|
-
current.length,
|
|
655
644
|
current.constructor.name,
|
|
656
645
|
NIL,
|
|
657
646
|
NIL,
|
|
@@ -667,7 +656,6 @@ function createDataViewNode(id, current, buffer) {
|
|
|
667
656
|
20 /* DataView */,
|
|
668
657
|
id,
|
|
669
658
|
NIL,
|
|
670
|
-
current.byteLength,
|
|
671
659
|
NIL,
|
|
672
660
|
NIL,
|
|
673
661
|
NIL,
|
|
@@ -684,7 +672,6 @@ function createErrorNode(id, current, options) {
|
|
|
684
672
|
id,
|
|
685
673
|
getErrorConstructor(current),
|
|
686
674
|
NIL,
|
|
687
|
-
NIL,
|
|
688
675
|
serializeString(current.message),
|
|
689
676
|
options,
|
|
690
677
|
NIL,
|
|
@@ -700,7 +687,6 @@ function createAggregateErrorNode(id, current, options) {
|
|
|
700
687
|
id,
|
|
701
688
|
getErrorConstructor(current),
|
|
702
689
|
NIL,
|
|
703
|
-
NIL,
|
|
704
690
|
serializeString(current.message),
|
|
705
691
|
options,
|
|
706
692
|
NIL,
|
|
@@ -710,12 +696,11 @@ function createAggregateErrorNode(id, current, options) {
|
|
|
710
696
|
NIL
|
|
711
697
|
);
|
|
712
698
|
}
|
|
713
|
-
function createSetNode(id,
|
|
699
|
+
function createSetNode(id, items) {
|
|
714
700
|
return createSerovalNode(
|
|
715
701
|
7 /* Set */,
|
|
716
702
|
id,
|
|
717
703
|
NIL,
|
|
718
|
-
size,
|
|
719
704
|
NIL,
|
|
720
705
|
NIL,
|
|
721
706
|
NIL,
|
|
@@ -735,7 +720,6 @@ function createIteratorFactoryInstanceNode(factory, items) {
|
|
|
735
720
|
NIL,
|
|
736
721
|
NIL,
|
|
737
722
|
NIL,
|
|
738
|
-
NIL,
|
|
739
723
|
[factory, items],
|
|
740
724
|
NIL,
|
|
741
725
|
NIL,
|
|
@@ -751,7 +735,6 @@ function createAsyncIteratorFactoryInstanceNode(factory, items) {
|
|
|
751
735
|
NIL,
|
|
752
736
|
NIL,
|
|
753
737
|
NIL,
|
|
754
|
-
NIL,
|
|
755
738
|
[factory, items],
|
|
756
739
|
NIL,
|
|
757
740
|
NIL,
|
|
@@ -767,7 +750,6 @@ function createStreamConstructorNode(id, factory, sequence) {
|
|
|
767
750
|
NIL,
|
|
768
751
|
NIL,
|
|
769
752
|
NIL,
|
|
770
|
-
NIL,
|
|
771
753
|
sequence,
|
|
772
754
|
factory,
|
|
773
755
|
NIL,
|
|
@@ -784,7 +766,6 @@ function createStreamNextNode(id, parsed) {
|
|
|
784
766
|
NIL,
|
|
785
767
|
NIL,
|
|
786
768
|
NIL,
|
|
787
|
-
NIL,
|
|
788
769
|
parsed,
|
|
789
770
|
NIL,
|
|
790
771
|
NIL
|
|
@@ -800,7 +781,6 @@ function createStreamThrowNode(id, parsed) {
|
|
|
800
781
|
NIL,
|
|
801
782
|
NIL,
|
|
802
783
|
NIL,
|
|
803
|
-
NIL,
|
|
804
784
|
parsed,
|
|
805
785
|
NIL,
|
|
806
786
|
NIL
|
|
@@ -816,7 +796,6 @@ function createStreamReturnNode(id, parsed) {
|
|
|
816
796
|
NIL,
|
|
817
797
|
NIL,
|
|
818
798
|
NIL,
|
|
819
|
-
NIL,
|
|
820
799
|
parsed,
|
|
821
800
|
NIL,
|
|
822
801
|
NIL
|
|
@@ -918,6 +897,27 @@ var SerovalUnknownTypedArrayError = class extends Error {
|
|
|
918
897
|
);
|
|
919
898
|
}
|
|
920
899
|
};
|
|
900
|
+
var SerovalMalformedNodeError = class extends Error {
|
|
901
|
+
constructor(node) {
|
|
902
|
+
super(
|
|
903
|
+
false ? getSpecificErrorMessage(8 /* MalformedNode */) : 'Malformed node type "' + node.t + '".'
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
var SerovalConflictedNodeIdError = class extends Error {
|
|
908
|
+
constructor(node) {
|
|
909
|
+
super(
|
|
910
|
+
false ? getSpecificErrorMessage(9 /* ConflictedNodeId */) : 'Conflicted node id "' + node.i + '".'
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
var SerovalDepthLimitError = class extends Error {
|
|
915
|
+
constructor(limit) {
|
|
916
|
+
super(
|
|
917
|
+
false ? getSpecificErrorMessage(9 /* ConflictedNodeId */) : "Depth limit of " + limit + " reached"
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
921
|
|
|
922
922
|
// src/core/opaque-reference.ts
|
|
923
923
|
var OpaqueReference = class {
|
|
@@ -1127,8 +1127,9 @@ var ASYNC_ITERATOR_CONSTRUCTOR = (symbol, createPromise) => (stream) => () => {
|
|
|
1127
1127
|
return instance;
|
|
1128
1128
|
};
|
|
1129
1129
|
var SERIALIZED_ASYNC_ITERATOR_CONSTRUCTOR = /* @__PURE__ */ ASYNC_ITERATOR_CONSTRUCTOR.toString();
|
|
1130
|
-
var ARRAY_BUFFER_CONSTRUCTOR = (
|
|
1130
|
+
var ARRAY_BUFFER_CONSTRUCTOR = (b64) => {
|
|
1131
1131
|
const decoded = atob(b64);
|
|
1132
|
+
const length = decoded.length;
|
|
1132
1133
|
const arr = new Uint8Array(length);
|
|
1133
1134
|
for (let i = 0; i < length; i++) {
|
|
1134
1135
|
arr[i] = decoded.charCodeAt(i);
|
|
@@ -1240,7 +1241,8 @@ function createBaseParserContext(mode, options) {
|
|
|
1240
1241
|
mode,
|
|
1241
1242
|
marked: /* @__PURE__ */ new Set(),
|
|
1242
1243
|
features: ALL_ENABLED ^ (options.disabledFeatures || 0),
|
|
1243
|
-
refs: options.refs || /* @__PURE__ */ new Map()
|
|
1244
|
+
refs: options.refs || /* @__PURE__ */ new Map(),
|
|
1245
|
+
depthLimit: options.depthLimit || 1e3
|
|
1244
1246
|
};
|
|
1245
1247
|
}
|
|
1246
1248
|
function markParserRef(ctx, id) {
|
|
@@ -1304,7 +1306,6 @@ function parseSpecialReference(ctx, ref) {
|
|
|
1304
1306
|
NIL,
|
|
1305
1307
|
NIL,
|
|
1306
1308
|
NIL,
|
|
1307
|
-
NIL,
|
|
1308
1309
|
NIL
|
|
1309
1310
|
);
|
|
1310
1311
|
}
|
|
@@ -1322,7 +1323,6 @@ function parseIteratorFactory(ctx) {
|
|
|
1322
1323
|
NIL,
|
|
1323
1324
|
NIL,
|
|
1324
1325
|
NIL,
|
|
1325
|
-
NIL,
|
|
1326
1326
|
parseWellKnownSymbol(ctx, SYM_ITERATOR),
|
|
1327
1327
|
NIL,
|
|
1328
1328
|
NIL
|
|
@@ -1341,7 +1341,6 @@ function parseAsyncIteratorFactory(ctx) {
|
|
|
1341
1341
|
NIL,
|
|
1342
1342
|
NIL,
|
|
1343
1343
|
NIL,
|
|
1344
|
-
NIL,
|
|
1345
1344
|
[
|
|
1346
1345
|
parseSpecialReference(ctx, 1 /* PromiseConstructor */),
|
|
1347
1346
|
parseWellKnownSymbol(ctx, SYM_ASYNC_ITERATOR)
|
|
@@ -1358,7 +1357,6 @@ function createObjectNode(id, current, empty, record) {
|
|
|
1358
1357
|
NIL,
|
|
1359
1358
|
NIL,
|
|
1360
1359
|
NIL,
|
|
1361
|
-
NIL,
|
|
1362
1360
|
record,
|
|
1363
1361
|
NIL,
|
|
1364
1362
|
NIL,
|
|
@@ -1367,7 +1365,7 @@ function createObjectNode(id, current, empty, record) {
|
|
|
1367
1365
|
getObjectFlag(current)
|
|
1368
1366
|
);
|
|
1369
1367
|
}
|
|
1370
|
-
function createMapNode(ctx, id, k, v
|
|
1368
|
+
function createMapNode(ctx, id, k, v) {
|
|
1371
1369
|
return createSerovalNode(
|
|
1372
1370
|
8 /* Map */,
|
|
1373
1371
|
id,
|
|
@@ -1375,8 +1373,7 @@ function createMapNode(ctx, id, k, v, s) {
|
|
|
1375
1373
|
NIL,
|
|
1376
1374
|
NIL,
|
|
1377
1375
|
NIL,
|
|
1378
|
-
|
|
1379
|
-
{ k, v, s },
|
|
1376
|
+
{ k, v },
|
|
1380
1377
|
NIL,
|
|
1381
1378
|
parseSpecialReference(ctx, 0 /* MapSentinel */),
|
|
1382
1379
|
NIL,
|
|
@@ -1393,7 +1390,6 @@ function createPromiseConstructorNode(ctx, id, resolver) {
|
|
|
1393
1390
|
NIL,
|
|
1394
1391
|
NIL,
|
|
1395
1392
|
NIL,
|
|
1396
|
-
NIL,
|
|
1397
1393
|
parseSpecialReference(ctx, 1 /* PromiseConstructor */),
|
|
1398
1394
|
NIL,
|
|
1399
1395
|
NIL
|
|
@@ -1401,16 +1397,14 @@ function createPromiseConstructorNode(ctx, id, resolver) {
|
|
|
1401
1397
|
}
|
|
1402
1398
|
function createArrayBufferNode(ctx, id, current) {
|
|
1403
1399
|
const bytes = new Uint8Array(current);
|
|
1404
|
-
const len = bytes.length;
|
|
1405
1400
|
let result = "";
|
|
1406
|
-
for (let i = 0; i < len; i++) {
|
|
1401
|
+
for (let i = 0, len = bytes.length; i < len; i++) {
|
|
1407
1402
|
result += String.fromCharCode(bytes[i]);
|
|
1408
1403
|
}
|
|
1409
1404
|
return createSerovalNode(
|
|
1410
1405
|
19 /* ArrayBuffer */,
|
|
1411
1406
|
id,
|
|
1412
1407
|
serializeString(btoa(result)),
|
|
1413
|
-
len,
|
|
1414
1408
|
NIL,
|
|
1415
1409
|
NIL,
|
|
1416
1410
|
NIL,
|
|
@@ -1430,32 +1424,35 @@ function createAsyncParserContext(mode, options) {
|
|
|
1430
1424
|
};
|
|
1431
1425
|
}
|
|
1432
1426
|
var AsyncParsePluginContext = class {
|
|
1433
|
-
constructor(_p) {
|
|
1427
|
+
constructor(_p, depth) {
|
|
1434
1428
|
this._p = _p;
|
|
1429
|
+
this.depth = depth;
|
|
1435
1430
|
}
|
|
1436
1431
|
parse(current) {
|
|
1437
|
-
return parseAsync(this._p, current);
|
|
1432
|
+
return parseAsync(this._p, this.depth, current);
|
|
1438
1433
|
}
|
|
1439
1434
|
};
|
|
1440
|
-
async function parseItems(ctx, current) {
|
|
1435
|
+
async function parseItems(ctx, depth, current) {
|
|
1441
1436
|
const nodes = [];
|
|
1442
1437
|
for (let i = 0, len = current.length; i < len; i++) {
|
|
1443
1438
|
if (i in current) {
|
|
1444
|
-
nodes[i] = await parseAsync(ctx, current[i]);
|
|
1439
|
+
nodes[i] = await parseAsync(ctx, depth, current[i]);
|
|
1440
|
+
} else {
|
|
1441
|
+
nodes[i] = 0;
|
|
1445
1442
|
}
|
|
1446
1443
|
}
|
|
1447
1444
|
return nodes;
|
|
1448
1445
|
}
|
|
1449
|
-
async function parseArray(ctx, id, current) {
|
|
1450
|
-
return createArrayNode(id, current, await parseItems(ctx, current));
|
|
1446
|
+
async function parseArray(ctx, depth, id, current) {
|
|
1447
|
+
return createArrayNode(id, current, await parseItems(ctx, depth, current));
|
|
1451
1448
|
}
|
|
1452
|
-
async function parseProperties(ctx, properties) {
|
|
1449
|
+
async function parseProperties(ctx, depth, properties) {
|
|
1453
1450
|
const entries = Object.entries(properties);
|
|
1454
1451
|
const keyNodes = [];
|
|
1455
1452
|
const valueNodes = [];
|
|
1456
1453
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
1457
1454
|
keyNodes.push(serializeString(entries[i][0]));
|
|
1458
|
-
valueNodes.push(await parseAsync(ctx, entries[i][1]));
|
|
1455
|
+
valueNodes.push(await parseAsync(ctx, depth, entries[i][1]));
|
|
1459
1456
|
}
|
|
1460
1457
|
if (SYM_ITERATOR in properties) {
|
|
1461
1458
|
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ITERATOR));
|
|
@@ -1464,6 +1461,7 @@ async function parseProperties(ctx, properties) {
|
|
|
1464
1461
|
parseIteratorFactory(ctx.base),
|
|
1465
1462
|
await parseAsync(
|
|
1466
1463
|
ctx,
|
|
1464
|
+
depth,
|
|
1467
1465
|
iteratorToSequence(properties)
|
|
1468
1466
|
)
|
|
1469
1467
|
)
|
|
@@ -1476,6 +1474,7 @@ async function parseProperties(ctx, properties) {
|
|
|
1476
1474
|
parseAsyncIteratorFactory(ctx.base),
|
|
1477
1475
|
await parseAsync(
|
|
1478
1476
|
ctx,
|
|
1477
|
+
depth,
|
|
1479
1478
|
createStreamFromAsyncIterable(
|
|
1480
1479
|
properties
|
|
1481
1480
|
)
|
|
@@ -1495,92 +1494,96 @@ async function parseProperties(ctx, properties) {
|
|
|
1495
1494
|
}
|
|
1496
1495
|
return {
|
|
1497
1496
|
k: keyNodes,
|
|
1498
|
-
v: valueNodes
|
|
1499
|
-
s: keyNodes.length
|
|
1497
|
+
v: valueNodes
|
|
1500
1498
|
};
|
|
1501
1499
|
}
|
|
1502
|
-
async function parsePlainObject(ctx, id, current, empty) {
|
|
1500
|
+
async function parsePlainObject(ctx, depth, id, current, empty) {
|
|
1503
1501
|
return createObjectNode(
|
|
1504
1502
|
id,
|
|
1505
1503
|
current,
|
|
1506
1504
|
empty,
|
|
1507
|
-
await parseProperties(ctx, current)
|
|
1505
|
+
await parseProperties(ctx, depth, current)
|
|
1508
1506
|
);
|
|
1509
1507
|
}
|
|
1510
|
-
async function parseBoxed(ctx, id, current) {
|
|
1511
|
-
return createBoxedNode(id, await parseAsync(ctx, current.valueOf()));
|
|
1508
|
+
async function parseBoxed(ctx, depth, id, current) {
|
|
1509
|
+
return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
|
|
1512
1510
|
}
|
|
1513
|
-
async function parseTypedArray(ctx, id, current) {
|
|
1511
|
+
async function parseTypedArray(ctx, depth, id, current) {
|
|
1514
1512
|
return createTypedArrayNode(
|
|
1515
1513
|
id,
|
|
1516
1514
|
current,
|
|
1517
|
-
await parseAsync(ctx, current.buffer)
|
|
1515
|
+
await parseAsync(ctx, depth, current.buffer)
|
|
1518
1516
|
);
|
|
1519
1517
|
}
|
|
1520
|
-
async function parseBigIntTypedArray(ctx, id, current) {
|
|
1518
|
+
async function parseBigIntTypedArray(ctx, depth, id, current) {
|
|
1521
1519
|
return createBigIntTypedArrayNode(
|
|
1522
1520
|
id,
|
|
1523
1521
|
current,
|
|
1524
|
-
await parseAsync(ctx, current.buffer)
|
|
1522
|
+
await parseAsync(ctx, depth, current.buffer)
|
|
1525
1523
|
);
|
|
1526
1524
|
}
|
|
1527
|
-
async function parseDataView(ctx, id, current) {
|
|
1528
|
-
return createDataViewNode(
|
|
1525
|
+
async function parseDataView(ctx, depth, id, current) {
|
|
1526
|
+
return createDataViewNode(
|
|
1527
|
+
id,
|
|
1528
|
+
current,
|
|
1529
|
+
await parseAsync(ctx, depth, current.buffer)
|
|
1530
|
+
);
|
|
1529
1531
|
}
|
|
1530
|
-
async function parseError(ctx, id, current) {
|
|
1532
|
+
async function parseError(ctx, depth, id, current) {
|
|
1531
1533
|
const options = getErrorOptions(current, ctx.base.features);
|
|
1532
1534
|
return createErrorNode(
|
|
1533
1535
|
id,
|
|
1534
1536
|
current,
|
|
1535
|
-
options ? await parseProperties(ctx, options) : NIL
|
|
1537
|
+
options ? await parseProperties(ctx, depth, options) : NIL
|
|
1536
1538
|
);
|
|
1537
1539
|
}
|
|
1538
|
-
async function parseAggregateError(ctx, id, current) {
|
|
1540
|
+
async function parseAggregateError(ctx, depth, id, current) {
|
|
1539
1541
|
const options = getErrorOptions(current, ctx.base.features);
|
|
1540
1542
|
return createAggregateErrorNode(
|
|
1541
1543
|
id,
|
|
1542
1544
|
current,
|
|
1543
|
-
options ? await parseProperties(ctx, options) : NIL
|
|
1545
|
+
options ? await parseProperties(ctx, depth, options) : NIL
|
|
1544
1546
|
);
|
|
1545
1547
|
}
|
|
1546
|
-
async function parseMap(ctx, id, current) {
|
|
1548
|
+
async function parseMap(ctx, depth, id, current) {
|
|
1547
1549
|
const keyNodes = [];
|
|
1548
1550
|
const valueNodes = [];
|
|
1549
1551
|
for (const [key, value] of current.entries()) {
|
|
1550
|
-
keyNodes.push(await parseAsync(ctx, key));
|
|
1551
|
-
valueNodes.push(await parseAsync(ctx, value));
|
|
1552
|
+
keyNodes.push(await parseAsync(ctx, depth, key));
|
|
1553
|
+
valueNodes.push(await parseAsync(ctx, depth, value));
|
|
1552
1554
|
}
|
|
1553
|
-
return createMapNode(ctx.base, id, keyNodes, valueNodes
|
|
1555
|
+
return createMapNode(ctx.base, id, keyNodes, valueNodes);
|
|
1554
1556
|
}
|
|
1555
|
-
async function parseSet(ctx, id, current) {
|
|
1557
|
+
async function parseSet(ctx, depth, id, current) {
|
|
1556
1558
|
const items = [];
|
|
1557
1559
|
for (const item of current.keys()) {
|
|
1558
|
-
items.push(await parseAsync(ctx, item));
|
|
1560
|
+
items.push(await parseAsync(ctx, depth, item));
|
|
1559
1561
|
}
|
|
1560
|
-
return createSetNode(id,
|
|
1562
|
+
return createSetNode(id, items);
|
|
1561
1563
|
}
|
|
1562
|
-
async function parsePlugin(ctx, id, current) {
|
|
1564
|
+
async function parsePlugin(ctx, depth, id, current) {
|
|
1563
1565
|
const currentPlugins = ctx.base.plugins;
|
|
1564
1566
|
if (currentPlugins) {
|
|
1565
1567
|
for (let i = 0, len = currentPlugins.length; i < len; i++) {
|
|
1566
1568
|
const plugin = currentPlugins[i];
|
|
1567
1569
|
if (plugin.parse.async && plugin.test(current)) {
|
|
1568
|
-
if (ctx.child == null) {
|
|
1569
|
-
ctx.child = new AsyncParsePluginContext(ctx);
|
|
1570
|
-
}
|
|
1571
1570
|
return createPluginNode(
|
|
1572
1571
|
id,
|
|
1573
1572
|
plugin.tag,
|
|
1574
|
-
await plugin.parse.async(
|
|
1575
|
-
|
|
1576
|
-
|
|
1573
|
+
await plugin.parse.async(
|
|
1574
|
+
current,
|
|
1575
|
+
new AsyncParsePluginContext(ctx, depth),
|
|
1576
|
+
{
|
|
1577
|
+
id
|
|
1578
|
+
}
|
|
1579
|
+
)
|
|
1577
1580
|
);
|
|
1578
1581
|
}
|
|
1579
1582
|
}
|
|
1580
1583
|
}
|
|
1581
1584
|
return NIL;
|
|
1582
1585
|
}
|
|
1583
|
-
async function parsePromise(ctx, id, current) {
|
|
1586
|
+
async function parsePromise(ctx, depth, id, current) {
|
|
1584
1587
|
const [status, result] = await promiseToResult(current);
|
|
1585
1588
|
return createSerovalNode(
|
|
1586
1589
|
12 /* Promise */,
|
|
@@ -1591,18 +1594,17 @@ async function parsePromise(ctx, id, current) {
|
|
|
1591
1594
|
NIL,
|
|
1592
1595
|
NIL,
|
|
1593
1596
|
NIL,
|
|
1594
|
-
|
|
1595
|
-
await parseAsync(ctx, result),
|
|
1597
|
+
await parseAsync(ctx, depth, result),
|
|
1596
1598
|
NIL,
|
|
1597
1599
|
NIL
|
|
1598
1600
|
);
|
|
1599
1601
|
}
|
|
1600
|
-
function parseStreamHandle(id, current, resolve, reject) {
|
|
1602
|
+
function parseStreamHandle(depth, id, current, resolve, reject) {
|
|
1601
1603
|
const sequence = [];
|
|
1602
1604
|
const cleanup = current.on({
|
|
1603
1605
|
next: (value) => {
|
|
1604
1606
|
markParserRef(this.base, id);
|
|
1605
|
-
parseAsync(this, value).then(
|
|
1607
|
+
parseAsync(this, depth, value).then(
|
|
1606
1608
|
(data) => {
|
|
1607
1609
|
sequence.push(createStreamNextNode(id, data));
|
|
1608
1610
|
},
|
|
@@ -1614,7 +1616,7 @@ function parseStreamHandle(id, current, resolve, reject) {
|
|
|
1614
1616
|
},
|
|
1615
1617
|
throw: (value) => {
|
|
1616
1618
|
markParserRef(this.base, id);
|
|
1617
|
-
parseAsync(this, value).then(
|
|
1619
|
+
parseAsync(this, depth, value).then(
|
|
1618
1620
|
(data) => {
|
|
1619
1621
|
sequence.push(createStreamThrowNode(id, data));
|
|
1620
1622
|
resolve(sequence);
|
|
@@ -1628,7 +1630,7 @@ function parseStreamHandle(id, current, resolve, reject) {
|
|
|
1628
1630
|
},
|
|
1629
1631
|
return: (value) => {
|
|
1630
1632
|
markParserRef(this.base, id);
|
|
1631
|
-
parseAsync(this, value).then(
|
|
1633
|
+
parseAsync(this, depth, value).then(
|
|
1632
1634
|
(data) => {
|
|
1633
1635
|
sequence.push(createStreamReturnNode(id, data));
|
|
1634
1636
|
resolve(sequence);
|
|
@@ -1642,28 +1644,31 @@ function parseStreamHandle(id, current, resolve, reject) {
|
|
|
1642
1644
|
}
|
|
1643
1645
|
});
|
|
1644
1646
|
}
|
|
1645
|
-
async function parseStream(ctx, id, current) {
|
|
1647
|
+
async function parseStream(ctx, depth, id, current) {
|
|
1646
1648
|
return createStreamConstructorNode(
|
|
1647
1649
|
id,
|
|
1648
1650
|
parseSpecialReference(ctx.base, 4 /* StreamConstructor */),
|
|
1649
|
-
await new Promise(
|
|
1651
|
+
await new Promise(
|
|
1652
|
+
parseStreamHandle.bind(ctx, depth, id, current)
|
|
1653
|
+
)
|
|
1650
1654
|
);
|
|
1651
1655
|
}
|
|
1652
|
-
async function parseObjectAsync(ctx, id, current) {
|
|
1656
|
+
async function parseObjectAsync(ctx, depth, id, current) {
|
|
1653
1657
|
if (Array.isArray(current)) {
|
|
1654
|
-
return parseArray(ctx, id, current);
|
|
1658
|
+
return parseArray(ctx, depth, id, current);
|
|
1655
1659
|
}
|
|
1656
1660
|
if (isStream(current)) {
|
|
1657
|
-
return parseStream(ctx, id, current);
|
|
1661
|
+
return parseStream(ctx, depth, id, current);
|
|
1658
1662
|
}
|
|
1659
1663
|
const currentClass = current.constructor;
|
|
1660
1664
|
if (currentClass === OpaqueReference) {
|
|
1661
1665
|
return parseAsync(
|
|
1662
1666
|
ctx,
|
|
1667
|
+
depth,
|
|
1663
1668
|
current.replacement
|
|
1664
1669
|
);
|
|
1665
1670
|
}
|
|
1666
|
-
const parsed = await parsePlugin(ctx, id, current);
|
|
1671
|
+
const parsed = await parsePlugin(ctx, depth, id, current);
|
|
1667
1672
|
if (parsed) {
|
|
1668
1673
|
return parsed;
|
|
1669
1674
|
}
|
|
@@ -1671,6 +1676,7 @@ async function parseObjectAsync(ctx, id, current) {
|
|
|
1671
1676
|
case Object:
|
|
1672
1677
|
return parsePlainObject(
|
|
1673
1678
|
ctx,
|
|
1679
|
+
depth,
|
|
1674
1680
|
id,
|
|
1675
1681
|
current,
|
|
1676
1682
|
false
|
|
@@ -1678,14 +1684,13 @@ async function parseObjectAsync(ctx, id, current) {
|
|
|
1678
1684
|
case NIL:
|
|
1679
1685
|
return parsePlainObject(
|
|
1680
1686
|
ctx,
|
|
1687
|
+
depth,
|
|
1681
1688
|
id,
|
|
1682
1689
|
current,
|
|
1683
1690
|
true
|
|
1684
1691
|
);
|
|
1685
1692
|
case Date:
|
|
1686
1693
|
return createDateNode(id, current);
|
|
1687
|
-
case RegExp:
|
|
1688
|
-
return createRegExpNode(id, current);
|
|
1689
1694
|
case Error:
|
|
1690
1695
|
case EvalError:
|
|
1691
1696
|
case RangeError:
|
|
@@ -1693,12 +1698,12 @@ async function parseObjectAsync(ctx, id, current) {
|
|
|
1693
1698
|
case SyntaxError:
|
|
1694
1699
|
case TypeError:
|
|
1695
1700
|
case URIError:
|
|
1696
|
-
return parseError(ctx, id, current);
|
|
1701
|
+
return parseError(ctx, depth, id, current);
|
|
1697
1702
|
case Number:
|
|
1698
1703
|
case Boolean:
|
|
1699
1704
|
case String:
|
|
1700
1705
|
case BigInt:
|
|
1701
|
-
return parseBoxed(ctx, id, current);
|
|
1706
|
+
return parseBoxed(ctx, depth, id, current);
|
|
1702
1707
|
case ArrayBuffer:
|
|
1703
1708
|
return createArrayBufferNode(
|
|
1704
1709
|
ctx.base,
|
|
@@ -1714,26 +1719,40 @@ async function parseObjectAsync(ctx, id, current) {
|
|
|
1714
1719
|
case Uint8ClampedArray:
|
|
1715
1720
|
case Float32Array:
|
|
1716
1721
|
case Float64Array:
|
|
1717
|
-
return parseTypedArray(
|
|
1722
|
+
return parseTypedArray(
|
|
1723
|
+
ctx,
|
|
1724
|
+
depth,
|
|
1725
|
+
id,
|
|
1726
|
+
current
|
|
1727
|
+
);
|
|
1718
1728
|
case DataView:
|
|
1719
|
-
return parseDataView(ctx, id, current);
|
|
1729
|
+
return parseDataView(ctx, depth, id, current);
|
|
1720
1730
|
case Map:
|
|
1721
|
-
return parseMap(
|
|
1731
|
+
return parseMap(
|
|
1732
|
+
ctx,
|
|
1733
|
+
depth,
|
|
1734
|
+
id,
|
|
1735
|
+
current
|
|
1736
|
+
);
|
|
1722
1737
|
case Set:
|
|
1723
|
-
return parseSet(ctx, id, current);
|
|
1738
|
+
return parseSet(ctx, depth, id, current);
|
|
1724
1739
|
default:
|
|
1725
1740
|
break;
|
|
1726
1741
|
}
|
|
1727
1742
|
if (currentClass === Promise || current instanceof Promise) {
|
|
1728
|
-
return parsePromise(ctx, id, current);
|
|
1743
|
+
return parsePromise(ctx, depth, id, current);
|
|
1729
1744
|
}
|
|
1730
1745
|
const currentFeatures = ctx.base.features;
|
|
1746
|
+
if (currentFeatures & 32 /* RegExp */ && currentClass === RegExp) {
|
|
1747
|
+
return createRegExpNode(id, current);
|
|
1748
|
+
}
|
|
1731
1749
|
if (currentFeatures & 16 /* BigIntTypedArray */) {
|
|
1732
1750
|
switch (currentClass) {
|
|
1733
1751
|
case BigInt64Array:
|
|
1734
1752
|
case BigUint64Array:
|
|
1735
1753
|
return parseBigIntTypedArray(
|
|
1736
1754
|
ctx,
|
|
1755
|
+
depth,
|
|
1737
1756
|
id,
|
|
1738
1757
|
current
|
|
1739
1758
|
);
|
|
@@ -1742,28 +1761,33 @@ async function parseObjectAsync(ctx, id, current) {
|
|
|
1742
1761
|
}
|
|
1743
1762
|
}
|
|
1744
1763
|
if (currentFeatures & 1 /* AggregateError */ && typeof AggregateError !== "undefined" && (currentClass === AggregateError || current instanceof AggregateError)) {
|
|
1745
|
-
return parseAggregateError(
|
|
1764
|
+
return parseAggregateError(
|
|
1765
|
+
ctx,
|
|
1766
|
+
depth,
|
|
1767
|
+
id,
|
|
1768
|
+
current
|
|
1769
|
+
);
|
|
1746
1770
|
}
|
|
1747
1771
|
if (current instanceof Error) {
|
|
1748
|
-
return parseError(ctx, id, current);
|
|
1772
|
+
return parseError(ctx, depth, id, current);
|
|
1749
1773
|
}
|
|
1750
1774
|
if (SYM_ITERATOR in current || SYM_ASYNC_ITERATOR in current) {
|
|
1751
|
-
return parsePlainObject(ctx, id, current, !!currentClass);
|
|
1775
|
+
return parsePlainObject(ctx, depth, id, current, !!currentClass);
|
|
1752
1776
|
}
|
|
1753
1777
|
throw new SerovalUnsupportedTypeError(current);
|
|
1754
1778
|
}
|
|
1755
|
-
async function parseFunctionAsync(ctx, current) {
|
|
1779
|
+
async function parseFunctionAsync(ctx, depth, current) {
|
|
1756
1780
|
const ref = getReferenceNode(ctx.base, current);
|
|
1757
1781
|
if (ref.type !== 0 /* Fresh */) {
|
|
1758
1782
|
return ref.value;
|
|
1759
1783
|
}
|
|
1760
|
-
const plugin = await parsePlugin(ctx, ref.value, current);
|
|
1784
|
+
const plugin = await parsePlugin(ctx, depth, ref.value, current);
|
|
1761
1785
|
if (plugin) {
|
|
1762
1786
|
return plugin;
|
|
1763
1787
|
}
|
|
1764
1788
|
throw new SerovalUnsupportedTypeError(current);
|
|
1765
1789
|
}
|
|
1766
|
-
async function parseAsync(ctx, current) {
|
|
1790
|
+
async function parseAsync(ctx, depth, current) {
|
|
1767
1791
|
switch (typeof current) {
|
|
1768
1792
|
case "boolean":
|
|
1769
1793
|
return current ? TRUE_NODE : FALSE_NODE;
|
|
@@ -1778,21 +1802,21 @@ async function parseAsync(ctx, current) {
|
|
|
1778
1802
|
case "object": {
|
|
1779
1803
|
if (current) {
|
|
1780
1804
|
const ref = getReferenceNode(ctx.base, current);
|
|
1781
|
-
return ref.type === 0 ? await parseObjectAsync(ctx, ref.value, current) : ref.value;
|
|
1805
|
+
return ref.type === 0 ? await parseObjectAsync(ctx, depth + 1, ref.value, current) : ref.value;
|
|
1782
1806
|
}
|
|
1783
1807
|
return NULL_NODE;
|
|
1784
1808
|
}
|
|
1785
1809
|
case "symbol":
|
|
1786
1810
|
return parseWellKnownSymbol(ctx.base, current);
|
|
1787
1811
|
case "function":
|
|
1788
|
-
return parseFunctionAsync(ctx, current);
|
|
1812
|
+
return parseFunctionAsync(ctx, depth, current);
|
|
1789
1813
|
default:
|
|
1790
1814
|
throw new SerovalUnsupportedTypeError(current);
|
|
1791
1815
|
}
|
|
1792
1816
|
}
|
|
1793
1817
|
async function parseTopAsync(ctx, current) {
|
|
1794
1818
|
try {
|
|
1795
|
-
return await parseAsync(ctx, current);
|
|
1819
|
+
return await parseAsync(ctx, 0, current);
|
|
1796
1820
|
} catch (error) {
|
|
1797
1821
|
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
1798
1822
|
}
|
|
@@ -1858,6 +1882,9 @@ function getTypedArrayConstructor(name) {
|
|
|
1858
1882
|
}
|
|
1859
1883
|
|
|
1860
1884
|
// src/core/context/deserializer.ts
|
|
1885
|
+
var MAX_BASE64_LENGTH = 1e6;
|
|
1886
|
+
var MAX_BIGINT_LENGTH = 1e4;
|
|
1887
|
+
var MAX_REGEXP_SOURCE_LENGTH = 2e4;
|
|
1861
1888
|
function applyObjectFlag(obj, flag) {
|
|
1862
1889
|
switch (flag) {
|
|
1863
1890
|
case 3 /* Frozen */:
|
|
@@ -1870,18 +1897,22 @@ function applyObjectFlag(obj, flag) {
|
|
|
1870
1897
|
return obj;
|
|
1871
1898
|
}
|
|
1872
1899
|
}
|
|
1900
|
+
var DEFAULT_DEPTH_LIMIT = 1e3;
|
|
1873
1901
|
function createBaseDeserializerContext(mode, options) {
|
|
1902
|
+
var _a;
|
|
1874
1903
|
return {
|
|
1875
1904
|
mode,
|
|
1876
1905
|
plugins: options.plugins,
|
|
1877
|
-
refs: options.refs || /* @__PURE__ */ new Map()
|
|
1906
|
+
refs: options.refs || /* @__PURE__ */ new Map(),
|
|
1907
|
+
features: (_a = options.features) != null ? _a : ALL_ENABLED ^ (options.disabledFeatures || 0),
|
|
1908
|
+
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT
|
|
1878
1909
|
};
|
|
1879
1910
|
}
|
|
1880
1911
|
function createVanillaDeserializerContext(options) {
|
|
1881
1912
|
return {
|
|
1882
1913
|
mode: 1 /* Vanilla */,
|
|
1883
1914
|
base: createBaseDeserializerContext(1 /* Vanilla */, options),
|
|
1884
|
-
child:
|
|
1915
|
+
child: NIL,
|
|
1885
1916
|
state: {
|
|
1886
1917
|
marked: new Set(options.markedRefs)
|
|
1887
1918
|
}
|
|
@@ -1891,32 +1922,50 @@ function createCrossDeserializerContext(options) {
|
|
|
1891
1922
|
return {
|
|
1892
1923
|
mode: 2 /* Cross */,
|
|
1893
1924
|
base: createBaseDeserializerContext(2 /* Cross */, options),
|
|
1894
|
-
child:
|
|
1925
|
+
child: NIL
|
|
1895
1926
|
};
|
|
1896
1927
|
}
|
|
1897
1928
|
var DeserializePluginContext = class {
|
|
1898
|
-
constructor(_p) {
|
|
1929
|
+
constructor(_p, depth) {
|
|
1899
1930
|
this._p = _p;
|
|
1931
|
+
this.depth = depth;
|
|
1900
1932
|
}
|
|
1901
1933
|
deserialize(node) {
|
|
1902
|
-
return deserialize(this._p, node);
|
|
1934
|
+
return deserialize(this._p, this.depth, node);
|
|
1903
1935
|
}
|
|
1904
1936
|
};
|
|
1937
|
+
function guardIndexedValue(ctx, id) {
|
|
1938
|
+
if (id < 0 || !Number.isFinite(id) || !Number.isInteger(id)) {
|
|
1939
|
+
throw new SerovalMalformedNodeError({
|
|
1940
|
+
t: 4 /* IndexedValue */,
|
|
1941
|
+
i: id
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
if (ctx.refs.has(id)) {
|
|
1945
|
+
throw new Error("Conflicted ref id: " + id);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1905
1948
|
function assignIndexedValueVanilla(ctx, id, value) {
|
|
1949
|
+
guardIndexedValue(ctx.base, id);
|
|
1906
1950
|
if (ctx.state.marked.has(id)) {
|
|
1907
1951
|
ctx.base.refs.set(id, value);
|
|
1908
1952
|
}
|
|
1909
1953
|
return value;
|
|
1910
1954
|
}
|
|
1911
1955
|
function assignIndexedValueCross(ctx, id, value) {
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
}
|
|
1956
|
+
guardIndexedValue(ctx.base, id);
|
|
1957
|
+
ctx.base.refs.set(id, value);
|
|
1915
1958
|
return value;
|
|
1916
1959
|
}
|
|
1917
1960
|
function assignIndexedValue(ctx, id, value) {
|
|
1918
1961
|
return ctx.mode === 1 /* Vanilla */ ? assignIndexedValueVanilla(ctx, id, value) : assignIndexedValueCross(ctx, id, value);
|
|
1919
1962
|
}
|
|
1963
|
+
function deserializeKnownValue(node, record, key) {
|
|
1964
|
+
if (Object.hasOwn(record, key)) {
|
|
1965
|
+
return record[key];
|
|
1966
|
+
}
|
|
1967
|
+
throw new SerovalMalformedNodeError(node);
|
|
1968
|
+
}
|
|
1920
1969
|
function deserializeReference(ctx, node) {
|
|
1921
1970
|
return assignIndexedValue(
|
|
1922
1971
|
ctx,
|
|
@@ -1924,46 +1973,96 @@ function deserializeReference(ctx, node) {
|
|
|
1924
1973
|
getReference(deserializeString(node.s))
|
|
1925
1974
|
);
|
|
1926
1975
|
}
|
|
1927
|
-
function deserializeArray(ctx, node) {
|
|
1928
|
-
const
|
|
1976
|
+
function deserializeArray(ctx, depth, node) {
|
|
1977
|
+
const items = node.a;
|
|
1978
|
+
const len = items.length;
|
|
1929
1979
|
const result = assignIndexedValue(
|
|
1930
1980
|
ctx,
|
|
1931
1981
|
node.i,
|
|
1932
1982
|
new Array(len)
|
|
1933
1983
|
);
|
|
1934
|
-
let item;
|
|
1935
|
-
|
|
1936
|
-
item = node.a[i];
|
|
1984
|
+
for (let i = 0, item; i < len; i++) {
|
|
1985
|
+
item = items[i];
|
|
1937
1986
|
if (item) {
|
|
1938
|
-
result[i] = deserialize(ctx, item);
|
|
1987
|
+
result[i] = deserialize(ctx, depth, item);
|
|
1939
1988
|
}
|
|
1940
1989
|
}
|
|
1941
1990
|
applyObjectFlag(result, node.o);
|
|
1942
1991
|
return result;
|
|
1943
1992
|
}
|
|
1944
|
-
function
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1993
|
+
function isValidKey(key) {
|
|
1994
|
+
switch (key) {
|
|
1995
|
+
case "constructor":
|
|
1996
|
+
case "__proto__":
|
|
1997
|
+
case "prototype":
|
|
1998
|
+
case "__defineGetter__":
|
|
1999
|
+
case "__defineSetter__":
|
|
2000
|
+
case "__lookupGetter__":
|
|
2001
|
+
case "__lookupSetter__":
|
|
2002
|
+
return false;
|
|
2003
|
+
default:
|
|
2004
|
+
return true;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
function isValidSymbol(symbol) {
|
|
2008
|
+
switch (symbol) {
|
|
2009
|
+
case SYM_ASYNC_ITERATOR:
|
|
2010
|
+
case SYM_IS_CONCAT_SPREADABLE:
|
|
2011
|
+
case SYM_TO_STRING_TAG:
|
|
2012
|
+
case SYM_ITERATOR:
|
|
2013
|
+
return true;
|
|
2014
|
+
default:
|
|
2015
|
+
return false;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
function assignStringProperty(object, key, value) {
|
|
2019
|
+
if (isValidKey(key)) {
|
|
2020
|
+
object[key] = value;
|
|
2021
|
+
} else {
|
|
2022
|
+
Object.defineProperty(object, key, {
|
|
2023
|
+
value,
|
|
2024
|
+
configurable: true,
|
|
2025
|
+
enumerable: true,
|
|
2026
|
+
writable: true
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
function assignProperty(ctx, depth, object, key, value) {
|
|
2031
|
+
if (typeof key === "string") {
|
|
2032
|
+
assignStringProperty(object, key, deserialize(ctx, depth, value));
|
|
2033
|
+
} else {
|
|
2034
|
+
const actual = deserialize(ctx, depth, key);
|
|
2035
|
+
switch (typeof actual) {
|
|
2036
|
+
case "string":
|
|
2037
|
+
assignStringProperty(object, actual, deserialize(ctx, depth, value));
|
|
2038
|
+
break;
|
|
2039
|
+
case "symbol":
|
|
2040
|
+
if (isValidSymbol(actual)) {
|
|
2041
|
+
object[actual] = deserialize(ctx, depth, value);
|
|
2042
|
+
}
|
|
2043
|
+
break;
|
|
2044
|
+
default:
|
|
2045
|
+
throw new SerovalMalformedNodeError(key);
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
function deserializeProperties(ctx, depth, node, result) {
|
|
2050
|
+
const keys = node.k;
|
|
2051
|
+
const len = keys.length;
|
|
2052
|
+
if (len > 0) {
|
|
2053
|
+
for (let i = 0, vals = node.v, len2 = keys.length; i < len2; i++) {
|
|
2054
|
+
assignProperty(ctx, depth, result, keys[i], vals[i]);
|
|
1956
2055
|
}
|
|
1957
2056
|
}
|
|
1958
2057
|
return result;
|
|
1959
2058
|
}
|
|
1960
|
-
function deserializeObject(ctx, node) {
|
|
2059
|
+
function deserializeObject(ctx, depth, node) {
|
|
1961
2060
|
const result = assignIndexedValue(
|
|
1962
2061
|
ctx,
|
|
1963
2062
|
node.i,
|
|
1964
2063
|
node.t === 10 /* Object */ ? {} : /* @__PURE__ */ Object.create(null)
|
|
1965
2064
|
);
|
|
1966
|
-
deserializeProperties(ctx, node.p, result);
|
|
2065
|
+
deserializeProperties(ctx, depth, node.p, result);
|
|
1967
2066
|
applyObjectFlag(result, node.o);
|
|
1968
2067
|
return result;
|
|
1969
2068
|
}
|
|
@@ -1971,84 +2070,92 @@ function deserializeDate(ctx, node) {
|
|
|
1971
2070
|
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1972
2071
|
}
|
|
1973
2072
|
function deserializeRegExp(ctx, node) {
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
2073
|
+
if (ctx.base.features & 32 /* RegExp */) {
|
|
2074
|
+
const source = deserializeString(node.c);
|
|
2075
|
+
if (source.length > MAX_REGEXP_SOURCE_LENGTH) {
|
|
2076
|
+
throw new SerovalMalformedNodeError(node);
|
|
2077
|
+
}
|
|
2078
|
+
return assignIndexedValue(ctx, node.i, new RegExp(source, node.m));
|
|
2079
|
+
}
|
|
2080
|
+
throw new SerovalUnsupportedNodeError(node);
|
|
1979
2081
|
}
|
|
1980
|
-
function deserializeSet(ctx, node) {
|
|
2082
|
+
function deserializeSet(ctx, depth, node) {
|
|
1981
2083
|
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
result.add(deserialize(ctx, items[i]));
|
|
2084
|
+
for (let i = 0, items = node.a, len = items.length; i < len; i++) {
|
|
2085
|
+
result.add(deserialize(ctx, depth, items[i]));
|
|
1985
2086
|
}
|
|
1986
2087
|
return result;
|
|
1987
2088
|
}
|
|
1988
|
-
function deserializeMap(ctx, node) {
|
|
2089
|
+
function deserializeMap(ctx, depth, node) {
|
|
1989
2090
|
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Map());
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
2091
|
+
for (let i = 0, keys = node.e.k, vals = node.e.v, len = keys.length; i < len; i++) {
|
|
2092
|
+
result.set(
|
|
2093
|
+
deserialize(ctx, depth, keys[i]),
|
|
2094
|
+
deserialize(ctx, depth, vals[i])
|
|
2095
|
+
);
|
|
1994
2096
|
}
|
|
1995
2097
|
return result;
|
|
1996
2098
|
}
|
|
1997
2099
|
function deserializeArrayBuffer(ctx, node) {
|
|
2100
|
+
if (node.s.length > MAX_BASE64_LENGTH) {
|
|
2101
|
+
throw new SerovalMalformedNodeError(node);
|
|
2102
|
+
}
|
|
1998
2103
|
const result = assignIndexedValue(
|
|
1999
2104
|
ctx,
|
|
2000
2105
|
node.i,
|
|
2001
|
-
ARRAY_BUFFER_CONSTRUCTOR(
|
|
2106
|
+
ARRAY_BUFFER_CONSTRUCTOR(deserializeString(node.s))
|
|
2002
2107
|
);
|
|
2003
2108
|
return result;
|
|
2004
2109
|
}
|
|
2005
|
-
function deserializeTypedArray(ctx, node) {
|
|
2110
|
+
function deserializeTypedArray(ctx, depth, node) {
|
|
2111
|
+
var _a;
|
|
2006
2112
|
const construct = getTypedArrayConstructor(node.c);
|
|
2007
|
-
const source = deserialize(ctx, node.f);
|
|
2008
|
-
const
|
|
2009
|
-
|
|
2010
|
-
node
|
|
2011
|
-
|
|
2012
|
-
);
|
|
2113
|
+
const source = deserialize(ctx, depth, node.f);
|
|
2114
|
+
const offset = (_a = node.b) != null ? _a : 0;
|
|
2115
|
+
if (offset < 0 || offset > source.byteLength) {
|
|
2116
|
+
throw new SerovalMalformedNodeError(node);
|
|
2117
|
+
}
|
|
2118
|
+
const result = assignIndexedValue(ctx, node.i, new construct(source, offset));
|
|
2013
2119
|
return result;
|
|
2014
2120
|
}
|
|
2015
|
-
function deserializeDataView(ctx, node) {
|
|
2016
|
-
|
|
2017
|
-
const
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
new
|
|
2021
|
-
|
|
2121
|
+
function deserializeDataView(ctx, depth, node) {
|
|
2122
|
+
var _a;
|
|
2123
|
+
const source = deserialize(ctx, depth, node.f);
|
|
2124
|
+
const offset = (_a = node.b) != null ? _a : 0;
|
|
2125
|
+
if (offset < 0 || offset > source.byteLength) {
|
|
2126
|
+
throw new SerovalMalformedNodeError(node);
|
|
2127
|
+
}
|
|
2128
|
+
const result = assignIndexedValue(ctx, node.i, new DataView(source, offset));
|
|
2022
2129
|
return result;
|
|
2023
2130
|
}
|
|
2024
|
-
function deserializeDictionary(ctx, node, result) {
|
|
2131
|
+
function deserializeDictionary(ctx, depth, node, result) {
|
|
2025
2132
|
if (node.p) {
|
|
2026
|
-
const fields = deserializeProperties(ctx, node.p, {});
|
|
2027
|
-
Object.
|
|
2133
|
+
const fields = deserializeProperties(ctx, depth, node.p, {});
|
|
2134
|
+
Object.defineProperties(result, Object.getOwnPropertyDescriptors(fields));
|
|
2028
2135
|
}
|
|
2029
2136
|
return result;
|
|
2030
2137
|
}
|
|
2031
|
-
function deserializeAggregateError(ctx, node) {
|
|
2138
|
+
function deserializeAggregateError(ctx, depth, node) {
|
|
2032
2139
|
const result = assignIndexedValue(
|
|
2033
2140
|
ctx,
|
|
2034
2141
|
node.i,
|
|
2035
2142
|
new AggregateError([], deserializeString(node.m))
|
|
2036
2143
|
);
|
|
2037
|
-
return deserializeDictionary(ctx, node, result);
|
|
2144
|
+
return deserializeDictionary(ctx, depth, node, result);
|
|
2038
2145
|
}
|
|
2039
|
-
function deserializeError(ctx, node) {
|
|
2040
|
-
const construct = ERROR_CONSTRUCTOR
|
|
2146
|
+
function deserializeError(ctx, depth, node) {
|
|
2147
|
+
const construct = deserializeKnownValue(node, ERROR_CONSTRUCTOR, node.s);
|
|
2041
2148
|
const result = assignIndexedValue(
|
|
2042
2149
|
ctx,
|
|
2043
2150
|
node.i,
|
|
2044
2151
|
new construct(deserializeString(node.m))
|
|
2045
2152
|
);
|
|
2046
|
-
return deserializeDictionary(ctx, node, result);
|
|
2153
|
+
return deserializeDictionary(ctx, depth, node, result);
|
|
2047
2154
|
}
|
|
2048
|
-
function deserializePromise(ctx, node) {
|
|
2155
|
+
function deserializePromise(ctx, depth, node) {
|
|
2049
2156
|
const deferred = PROMISE_CONSTRUCTOR();
|
|
2050
2157
|
const result = assignIndexedValue(ctx, node.i, deferred.p);
|
|
2051
|
-
const deserialized = deserialize(ctx, node.f);
|
|
2158
|
+
const deserialized = deserialize(ctx, depth, node.f);
|
|
2052
2159
|
if (node.s) {
|
|
2053
2160
|
deferred.s(deserialized);
|
|
2054
2161
|
} else {
|
|
@@ -2056,23 +2163,25 @@ function deserializePromise(ctx, node) {
|
|
|
2056
2163
|
}
|
|
2057
2164
|
return result;
|
|
2058
2165
|
}
|
|
2059
|
-
function deserializeBoxed(ctx, node) {
|
|
2060
|
-
return assignIndexedValue(
|
|
2166
|
+
function deserializeBoxed(ctx, depth, node) {
|
|
2167
|
+
return assignIndexedValue(
|
|
2168
|
+
ctx,
|
|
2169
|
+
node.i,
|
|
2170
|
+
// biome-ignore lint/style/useConsistentBuiltinInstantiation: intended
|
|
2171
|
+
Object(deserialize(ctx, depth, node.f))
|
|
2172
|
+
);
|
|
2061
2173
|
}
|
|
2062
|
-
function deserializePlugin(ctx, node) {
|
|
2174
|
+
function deserializePlugin(ctx, depth, node) {
|
|
2063
2175
|
const currentPlugins = ctx.base.plugins;
|
|
2064
2176
|
if (currentPlugins) {
|
|
2065
2177
|
const tag = deserializeString(node.c);
|
|
2066
2178
|
for (let i = 0, len = currentPlugins.length; i < len; i++) {
|
|
2067
2179
|
const plugin = currentPlugins[i];
|
|
2068
2180
|
if (plugin.tag === tag) {
|
|
2069
|
-
if (ctx.child == null) {
|
|
2070
|
-
ctx.child = new DeserializePluginContext(ctx);
|
|
2071
|
-
}
|
|
2072
2181
|
return assignIndexedValue(
|
|
2073
2182
|
ctx,
|
|
2074
2183
|
node.i,
|
|
2075
|
-
plugin.deserialize(node.s, ctx
|
|
2184
|
+
plugin.deserialize(node.s, new DeserializePluginContext(ctx, depth), {
|
|
2076
2185
|
id: node.i
|
|
2077
2186
|
})
|
|
2078
2187
|
);
|
|
@@ -2088,142 +2197,150 @@ function deserializePromiseConstructor(ctx, node) {
|
|
|
2088
2197
|
assignIndexedValue(ctx, node.s, PROMISE_CONSTRUCTOR()).p
|
|
2089
2198
|
);
|
|
2090
2199
|
}
|
|
2091
|
-
function deserializePromiseResolve(ctx, node) {
|
|
2200
|
+
function deserializePromiseResolve(ctx, depth, node) {
|
|
2092
2201
|
const deferred = ctx.base.refs.get(node.i);
|
|
2093
2202
|
if (deferred) {
|
|
2094
|
-
deferred.s(deserialize(ctx, node.a[1]));
|
|
2095
|
-
return
|
|
2203
|
+
deferred.s(deserialize(ctx, depth, node.a[1]));
|
|
2204
|
+
return NIL;
|
|
2096
2205
|
}
|
|
2097
2206
|
throw new SerovalMissingInstanceError("Promise");
|
|
2098
2207
|
}
|
|
2099
|
-
function deserializePromiseReject(ctx, node) {
|
|
2208
|
+
function deserializePromiseReject(ctx, depth, node) {
|
|
2100
2209
|
const deferred = ctx.base.refs.get(node.i);
|
|
2101
2210
|
if (deferred) {
|
|
2102
|
-
deferred.f(deserialize(ctx, node.a[1]));
|
|
2103
|
-
return
|
|
2211
|
+
deferred.f(deserialize(ctx, depth, node.a[1]));
|
|
2212
|
+
return NIL;
|
|
2104
2213
|
}
|
|
2105
2214
|
throw new SerovalMissingInstanceError("Promise");
|
|
2106
2215
|
}
|
|
2107
|
-
function deserializeIteratorFactoryInstance(ctx, node) {
|
|
2108
|
-
deserialize(ctx, node.a[0]);
|
|
2109
|
-
const source = deserialize(ctx, node.a[1]);
|
|
2216
|
+
function deserializeIteratorFactoryInstance(ctx, depth, node) {
|
|
2217
|
+
deserialize(ctx, depth, node.a[0]);
|
|
2218
|
+
const source = deserialize(ctx, depth, node.a[1]);
|
|
2110
2219
|
return sequenceToIterator(source);
|
|
2111
2220
|
}
|
|
2112
|
-
function deserializeAsyncIteratorFactoryInstance(ctx, node) {
|
|
2113
|
-
deserialize(ctx, node.a[0]);
|
|
2114
|
-
const source = deserialize(ctx, node.a[1]);
|
|
2221
|
+
function deserializeAsyncIteratorFactoryInstance(ctx, depth, node) {
|
|
2222
|
+
deserialize(ctx, depth, node.a[0]);
|
|
2223
|
+
const source = deserialize(ctx, depth, node.a[1]);
|
|
2115
2224
|
return streamToAsyncIterable(source);
|
|
2116
2225
|
}
|
|
2117
|
-
function deserializeStreamConstructor(ctx, node) {
|
|
2226
|
+
function deserializeStreamConstructor(ctx, depth, node) {
|
|
2118
2227
|
const result = assignIndexedValue(ctx, node.i, createStream());
|
|
2119
|
-
const
|
|
2228
|
+
const items = node.a;
|
|
2229
|
+
const len = items.length;
|
|
2120
2230
|
if (len) {
|
|
2121
2231
|
for (let i = 0; i < len; i++) {
|
|
2122
|
-
deserialize(ctx,
|
|
2232
|
+
deserialize(ctx, depth, items[i]);
|
|
2123
2233
|
}
|
|
2124
2234
|
}
|
|
2125
2235
|
return result;
|
|
2126
2236
|
}
|
|
2127
|
-
function deserializeStreamNext(ctx, node) {
|
|
2237
|
+
function deserializeStreamNext(ctx, depth, node) {
|
|
2128
2238
|
const deferred = ctx.base.refs.get(node.i);
|
|
2129
|
-
if (deferred) {
|
|
2130
|
-
deferred.next(deserialize(ctx, node.f));
|
|
2131
|
-
return
|
|
2239
|
+
if (deferred && isStream(deferred)) {
|
|
2240
|
+
deferred.next(deserialize(ctx, depth, node.f));
|
|
2241
|
+
return NIL;
|
|
2132
2242
|
}
|
|
2133
2243
|
throw new SerovalMissingInstanceError("Stream");
|
|
2134
2244
|
}
|
|
2135
|
-
function deserializeStreamThrow(ctx, node) {
|
|
2245
|
+
function deserializeStreamThrow(ctx, depth, node) {
|
|
2136
2246
|
const deferred = ctx.base.refs.get(node.i);
|
|
2137
|
-
if (deferred) {
|
|
2138
|
-
deferred.throw(deserialize(ctx, node.f));
|
|
2139
|
-
return
|
|
2247
|
+
if (deferred && isStream(deferred)) {
|
|
2248
|
+
deferred.throw(deserialize(ctx, depth, node.f));
|
|
2249
|
+
return NIL;
|
|
2140
2250
|
}
|
|
2141
2251
|
throw new SerovalMissingInstanceError("Stream");
|
|
2142
2252
|
}
|
|
2143
|
-
function deserializeStreamReturn(ctx, node) {
|
|
2253
|
+
function deserializeStreamReturn(ctx, depth, node) {
|
|
2144
2254
|
const deferred = ctx.base.refs.get(node.i);
|
|
2145
|
-
if (deferred) {
|
|
2146
|
-
deferred.return(deserialize(ctx, node.f));
|
|
2147
|
-
return
|
|
2255
|
+
if (deferred && isStream(deferred)) {
|
|
2256
|
+
deferred.return(deserialize(ctx, depth, node.f));
|
|
2257
|
+
return NIL;
|
|
2148
2258
|
}
|
|
2149
2259
|
throw new SerovalMissingInstanceError("Stream");
|
|
2150
2260
|
}
|
|
2151
|
-
function deserializeIteratorFactory(ctx, node) {
|
|
2152
|
-
deserialize(ctx, node.f);
|
|
2153
|
-
return
|
|
2261
|
+
function deserializeIteratorFactory(ctx, depth, node) {
|
|
2262
|
+
deserialize(ctx, depth, node.f);
|
|
2263
|
+
return NIL;
|
|
2154
2264
|
}
|
|
2155
|
-
function deserializeAsyncIteratorFactory(ctx, node) {
|
|
2156
|
-
deserialize(ctx, node.a[1]);
|
|
2157
|
-
return
|
|
2265
|
+
function deserializeAsyncIteratorFactory(ctx, depth, node) {
|
|
2266
|
+
deserialize(ctx, depth, node.a[1]);
|
|
2267
|
+
return NIL;
|
|
2158
2268
|
}
|
|
2159
|
-
function deserialize(ctx, node) {
|
|
2269
|
+
function deserialize(ctx, depth, node) {
|
|
2270
|
+
if (depth > ctx.base.depthLimit) {
|
|
2271
|
+
throw new SerovalDepthLimitError(ctx.base.depthLimit);
|
|
2272
|
+
}
|
|
2273
|
+
depth += 1;
|
|
2160
2274
|
switch (node.t) {
|
|
2161
2275
|
case 2 /* Constant */:
|
|
2162
|
-
return CONSTANT_VAL
|
|
2276
|
+
return deserializeKnownValue(node, CONSTANT_VAL, node.s);
|
|
2163
2277
|
case 0 /* Number */:
|
|
2164
|
-
return node.s;
|
|
2278
|
+
return Number(node.s);
|
|
2165
2279
|
case 1 /* String */:
|
|
2166
|
-
return deserializeString(node.s);
|
|
2280
|
+
return deserializeString(String(node.s));
|
|
2167
2281
|
case 3 /* BigInt */:
|
|
2282
|
+
if (String(node.s).length > MAX_BIGINT_LENGTH) {
|
|
2283
|
+
throw new SerovalMalformedNodeError(node);
|
|
2284
|
+
}
|
|
2168
2285
|
return BigInt(node.s);
|
|
2169
2286
|
case 4 /* IndexedValue */:
|
|
2170
2287
|
return ctx.base.refs.get(node.i);
|
|
2171
2288
|
case 18 /* Reference */:
|
|
2172
2289
|
return deserializeReference(ctx, node);
|
|
2173
2290
|
case 9 /* Array */:
|
|
2174
|
-
return deserializeArray(ctx, node);
|
|
2291
|
+
return deserializeArray(ctx, depth, node);
|
|
2175
2292
|
case 10 /* Object */:
|
|
2176
2293
|
case 11 /* NullConstructor */:
|
|
2177
|
-
return deserializeObject(ctx, node);
|
|
2294
|
+
return deserializeObject(ctx, depth, node);
|
|
2178
2295
|
case 5 /* Date */:
|
|
2179
2296
|
return deserializeDate(ctx, node);
|
|
2180
2297
|
case 6 /* RegExp */:
|
|
2181
2298
|
return deserializeRegExp(ctx, node);
|
|
2182
2299
|
case 7 /* Set */:
|
|
2183
|
-
return deserializeSet(ctx, node);
|
|
2300
|
+
return deserializeSet(ctx, depth, node);
|
|
2184
2301
|
case 8 /* Map */:
|
|
2185
|
-
return deserializeMap(ctx, node);
|
|
2302
|
+
return deserializeMap(ctx, depth, node);
|
|
2186
2303
|
case 19 /* ArrayBuffer */:
|
|
2187
2304
|
return deserializeArrayBuffer(ctx, node);
|
|
2188
2305
|
case 16 /* BigIntTypedArray */:
|
|
2189
2306
|
case 15 /* TypedArray */:
|
|
2190
|
-
return deserializeTypedArray(ctx, node);
|
|
2307
|
+
return deserializeTypedArray(ctx, depth, node);
|
|
2191
2308
|
case 20 /* DataView */:
|
|
2192
|
-
return deserializeDataView(ctx, node);
|
|
2309
|
+
return deserializeDataView(ctx, depth, node);
|
|
2193
2310
|
case 14 /* AggregateError */:
|
|
2194
|
-
return deserializeAggregateError(ctx, node);
|
|
2311
|
+
return deserializeAggregateError(ctx, depth, node);
|
|
2195
2312
|
case 13 /* Error */:
|
|
2196
|
-
return deserializeError(ctx, node);
|
|
2313
|
+
return deserializeError(ctx, depth, node);
|
|
2197
2314
|
case 12 /* Promise */:
|
|
2198
|
-
return deserializePromise(ctx, node);
|
|
2315
|
+
return deserializePromise(ctx, depth, node);
|
|
2199
2316
|
case 17 /* WKSymbol */:
|
|
2200
|
-
return SYMBOL_REF
|
|
2317
|
+
return deserializeKnownValue(node, SYMBOL_REF, node.s);
|
|
2201
2318
|
case 21 /* Boxed */:
|
|
2202
|
-
return deserializeBoxed(ctx, node);
|
|
2319
|
+
return deserializeBoxed(ctx, depth, node);
|
|
2203
2320
|
case 25 /* Plugin */:
|
|
2204
|
-
return deserializePlugin(ctx, node);
|
|
2321
|
+
return deserializePlugin(ctx, depth, node);
|
|
2205
2322
|
case 22 /* PromiseConstructor */:
|
|
2206
2323
|
return deserializePromiseConstructor(ctx, node);
|
|
2207
2324
|
case 23 /* PromiseSuccess */:
|
|
2208
|
-
return deserializePromiseResolve(ctx, node);
|
|
2325
|
+
return deserializePromiseResolve(ctx, depth, node);
|
|
2209
2326
|
case 24 /* PromiseFailure */:
|
|
2210
|
-
return deserializePromiseReject(ctx, node);
|
|
2327
|
+
return deserializePromiseReject(ctx, depth, node);
|
|
2211
2328
|
case 28 /* IteratorFactoryInstance */:
|
|
2212
|
-
return deserializeIteratorFactoryInstance(ctx, node);
|
|
2329
|
+
return deserializeIteratorFactoryInstance(ctx, depth, node);
|
|
2213
2330
|
case 30 /* AsyncIteratorFactoryInstance */:
|
|
2214
|
-
return deserializeAsyncIteratorFactoryInstance(ctx, node);
|
|
2331
|
+
return deserializeAsyncIteratorFactoryInstance(ctx, depth, node);
|
|
2215
2332
|
case 31 /* StreamConstructor */:
|
|
2216
|
-
return deserializeStreamConstructor(ctx, node);
|
|
2333
|
+
return deserializeStreamConstructor(ctx, depth, node);
|
|
2217
2334
|
case 32 /* StreamNext */:
|
|
2218
|
-
return deserializeStreamNext(ctx, node);
|
|
2335
|
+
return deserializeStreamNext(ctx, depth, node);
|
|
2219
2336
|
case 33 /* StreamThrow */:
|
|
2220
|
-
return deserializeStreamThrow(ctx, node);
|
|
2337
|
+
return deserializeStreamThrow(ctx, depth, node);
|
|
2221
2338
|
case 34 /* StreamReturn */:
|
|
2222
|
-
return deserializeStreamReturn(ctx, node);
|
|
2339
|
+
return deserializeStreamReturn(ctx, depth, node);
|
|
2223
2340
|
case 27 /* IteratorFactory */:
|
|
2224
|
-
return deserializeIteratorFactory(ctx, node);
|
|
2341
|
+
return deserializeIteratorFactory(ctx, depth, node);
|
|
2225
2342
|
case 29 /* AsyncIteratorFactory */:
|
|
2226
|
-
return deserializeAsyncIteratorFactory(ctx, node);
|
|
2343
|
+
return deserializeAsyncIteratorFactory(ctx, depth, node);
|
|
2227
2344
|
// case SerovalNodeType.SpecialReference:
|
|
2228
2345
|
default:
|
|
2229
2346
|
throw new SerovalUnsupportedNodeError(node);
|
|
@@ -2231,7 +2348,7 @@ function deserialize(ctx, node) {
|
|
|
2231
2348
|
}
|
|
2232
2349
|
function deserializeTop(ctx, node) {
|
|
2233
2350
|
try {
|
|
2234
|
-
return deserialize(ctx, node);
|
|
2351
|
+
return deserialize(ctx, 0, node);
|
|
2235
2352
|
} catch (error) {
|
|
2236
2353
|
throw new SerovalDeserializationError(error);
|
|
2237
2354
|
}
|
|
@@ -2379,7 +2496,7 @@ function createVanillaSerializerContext(options) {
|
|
|
2379
2496
|
mode: 1 /* Vanilla */,
|
|
2380
2497
|
base: createBaseSerializerContext(1 /* Vanilla */, options),
|
|
2381
2498
|
state: createVanillaSerializerState(),
|
|
2382
|
-
child:
|
|
2499
|
+
child: NIL
|
|
2383
2500
|
};
|
|
2384
2501
|
}
|
|
2385
2502
|
function createCrossSerializerContext(options) {
|
|
@@ -2387,7 +2504,7 @@ function createCrossSerializerContext(options) {
|
|
|
2387
2504
|
mode: 2 /* Cross */,
|
|
2388
2505
|
base: createBaseSerializerContext(2 /* Cross */, options),
|
|
2389
2506
|
state: options,
|
|
2390
|
-
child:
|
|
2507
|
+
child: NIL
|
|
2391
2508
|
};
|
|
2392
2509
|
}
|
|
2393
2510
|
var SerializePluginContext = class {
|
|
@@ -2519,12 +2636,13 @@ function serializeArrayItem(ctx, id, item, index) {
|
|
|
2519
2636
|
}
|
|
2520
2637
|
function serializeArray(ctx, node) {
|
|
2521
2638
|
const id = node.i;
|
|
2522
|
-
|
|
2639
|
+
const list = node.a;
|
|
2640
|
+
const len = list.length;
|
|
2641
|
+
if (len > 0) {
|
|
2523
2642
|
ctx.base.stack.push(id);
|
|
2524
|
-
const list = node.a;
|
|
2525
2643
|
let values = serializeArrayItem(ctx, id, list[0], 0);
|
|
2526
2644
|
let isHoley = values === "";
|
|
2527
|
-
for (let i = 1,
|
|
2645
|
+
for (let i = 1, item; i < len; i++) {
|
|
2528
2646
|
item = serializeArrayItem(ctx, id, list[i], i);
|
|
2529
2647
|
values += "," + item;
|
|
2530
2648
|
isHoley = item === "";
|
|
@@ -2570,9 +2688,9 @@ function serializeProperty(ctx, source, key, val) {
|
|
|
2570
2688
|
return "[" + serialize(ctx, key) + "]:" + serialize(ctx, val);
|
|
2571
2689
|
}
|
|
2572
2690
|
function serializeProperties(ctx, source, record) {
|
|
2573
|
-
const
|
|
2574
|
-
|
|
2575
|
-
|
|
2691
|
+
const keys = record.k;
|
|
2692
|
+
const len = keys.length;
|
|
2693
|
+
if (len > 0) {
|
|
2576
2694
|
const values = record.v;
|
|
2577
2695
|
ctx.base.stack.push(source.i);
|
|
2578
2696
|
let result = serializeProperty(ctx, source, keys[0], values[0]);
|
|
@@ -2655,10 +2773,10 @@ function serializeAssignment(ctx, source, mainAssignments, key, value) {
|
|
|
2655
2773
|
}
|
|
2656
2774
|
}
|
|
2657
2775
|
function serializeAssignments(ctx, source, node) {
|
|
2658
|
-
const
|
|
2659
|
-
|
|
2776
|
+
const keys = node.k;
|
|
2777
|
+
const len = keys.length;
|
|
2778
|
+
if (len > 0) {
|
|
2660
2779
|
const mainAssignments = [];
|
|
2661
|
-
const keys = node.k;
|
|
2662
2780
|
const values = node.v;
|
|
2663
2781
|
ctx.base.stack.push(source.i);
|
|
2664
2782
|
for (let i = 0; i < len; i++) {
|
|
@@ -2691,8 +2809,11 @@ function serializeNullConstructor(ctx, node) {
|
|
|
2691
2809
|
function serializeDate(node) {
|
|
2692
2810
|
return 'new Date("' + node.s + '")';
|
|
2693
2811
|
}
|
|
2694
|
-
function serializeRegExp(node) {
|
|
2695
|
-
|
|
2812
|
+
function serializeRegExp(ctx, node) {
|
|
2813
|
+
if (ctx.base.features & 32 /* RegExp */) {
|
|
2814
|
+
return "/" + node.c + "/" + node.m;
|
|
2815
|
+
}
|
|
2816
|
+
throw new SerovalUnsupportedNodeError(node);
|
|
2696
2817
|
}
|
|
2697
2818
|
function serializeSetItem(ctx, id, item) {
|
|
2698
2819
|
const base = ctx.base;
|
|
@@ -2709,10 +2830,10 @@ function serializeSetItem(ctx, id, item) {
|
|
|
2709
2830
|
}
|
|
2710
2831
|
function serializeSet(ctx, node) {
|
|
2711
2832
|
let serialized = SET_CONSTRUCTOR;
|
|
2712
|
-
const
|
|
2833
|
+
const items = node.a;
|
|
2834
|
+
const size = items.length;
|
|
2713
2835
|
const id = node.i;
|
|
2714
|
-
if (size) {
|
|
2715
|
-
const items = node.a;
|
|
2836
|
+
if (size > 0) {
|
|
2716
2837
|
ctx.base.stack.push(id);
|
|
2717
2838
|
let result = serializeSetItem(ctx, id, items[0]);
|
|
2718
2839
|
for (let i = 1, item = result; i < size; i++) {
|
|
@@ -2767,13 +2888,13 @@ function serializeMapEntry(ctx, id, key, val, sentinel) {
|
|
|
2767
2888
|
}
|
|
2768
2889
|
function serializeMap(ctx, node) {
|
|
2769
2890
|
let serialized = MAP_CONSTRUCTOR;
|
|
2770
|
-
const
|
|
2891
|
+
const keys = node.e.k;
|
|
2892
|
+
const size = keys.length;
|
|
2771
2893
|
const id = node.i;
|
|
2772
2894
|
const sentinel = node.f;
|
|
2773
2895
|
const sentinelId = getRefParam(ctx, sentinel.i);
|
|
2774
2896
|
const base = ctx.base;
|
|
2775
|
-
if (size) {
|
|
2776
|
-
const keys = node.e.k;
|
|
2897
|
+
if (size > 0) {
|
|
2777
2898
|
const vals = node.e.v;
|
|
2778
2899
|
base.stack.push(id);
|
|
2779
2900
|
let result = serializeMapEntry(ctx, id, keys[0], vals[0], sentinelId);
|
|
@@ -2793,13 +2914,13 @@ function serializeMap(ctx, node) {
|
|
|
2793
2914
|
return serialized;
|
|
2794
2915
|
}
|
|
2795
2916
|
function serializeArrayBuffer(ctx, node) {
|
|
2796
|
-
return getConstructor(ctx, node.f) +
|
|
2917
|
+
return getConstructor(ctx, node.f) + '("' + node.s + '")';
|
|
2797
2918
|
}
|
|
2798
2919
|
function serializeTypedArray(ctx, node) {
|
|
2799
|
-
return "new " + node.c + "(" + serialize(ctx, node.f) + "," + node.b + "
|
|
2920
|
+
return "new " + node.c + "(" + serialize(ctx, node.f) + "," + node.b + ")";
|
|
2800
2921
|
}
|
|
2801
2922
|
function serializeDataView(ctx, node) {
|
|
2802
|
-
return "new DataView(" + serialize(ctx, node.f) + "," + node.b + "
|
|
2923
|
+
return "new DataView(" + serialize(ctx, node.f) + "," + node.b + ")";
|
|
2803
2924
|
}
|
|
2804
2925
|
function serializeAggregateError(ctx, node) {
|
|
2805
2926
|
const id = node.i;
|
|
@@ -2973,7 +3094,7 @@ function serializeAssignable(ctx, node) {
|
|
|
2973
3094
|
case 5 /* Date */:
|
|
2974
3095
|
return serializeDate(node);
|
|
2975
3096
|
case 6 /* RegExp */:
|
|
2976
|
-
return serializeRegExp(node);
|
|
3097
|
+
return serializeRegExp(ctx, node);
|
|
2977
3098
|
case 7 /* Set */:
|
|
2978
3099
|
return serializeSet(ctx, node);
|
|
2979
3100
|
case 8 /* Map */:
|
|
@@ -3085,26 +3206,28 @@ function createSyncParserContext(mode, options) {
|
|
|
3085
3206
|
return {
|
|
3086
3207
|
type: 1 /* Sync */,
|
|
3087
3208
|
base: createBaseParserContext(mode, options),
|
|
3088
|
-
child:
|
|
3209
|
+
child: NIL
|
|
3089
3210
|
};
|
|
3090
3211
|
}
|
|
3091
3212
|
var SyncParsePluginContext = class {
|
|
3092
|
-
constructor(_p) {
|
|
3213
|
+
constructor(_p, depth) {
|
|
3093
3214
|
this._p = _p;
|
|
3215
|
+
this.depth = depth;
|
|
3094
3216
|
}
|
|
3095
3217
|
parse(current) {
|
|
3096
|
-
return parseSOS(this._p, current);
|
|
3218
|
+
return parseSOS(this._p, this.depth, current);
|
|
3097
3219
|
}
|
|
3098
3220
|
};
|
|
3099
3221
|
var StreamParsePluginContext = class {
|
|
3100
|
-
constructor(_p) {
|
|
3222
|
+
constructor(_p, depth) {
|
|
3101
3223
|
this._p = _p;
|
|
3224
|
+
this.depth = depth;
|
|
3102
3225
|
}
|
|
3103
3226
|
parse(current) {
|
|
3104
|
-
return parseSOS(this._p, current);
|
|
3227
|
+
return parseSOS(this._p, this.depth, current);
|
|
3105
3228
|
}
|
|
3106
3229
|
parseWithError(current) {
|
|
3107
|
-
return parseWithError(this._p, current);
|
|
3230
|
+
return parseWithError(this._p, this.depth, current);
|
|
3108
3231
|
}
|
|
3109
3232
|
isAlive() {
|
|
3110
3233
|
return this._p.state.alive;
|
|
@@ -3137,29 +3260,30 @@ function createStreamParserContext(options) {
|
|
|
3137
3260
|
return {
|
|
3138
3261
|
type: 2 /* Stream */,
|
|
3139
3262
|
base: createBaseParserContext(2 /* Cross */, options),
|
|
3140
|
-
child: void 0,
|
|
3141
3263
|
state: createStreamParserState(options)
|
|
3142
3264
|
};
|
|
3143
3265
|
}
|
|
3144
|
-
function parseItems2(ctx, current) {
|
|
3266
|
+
function parseItems2(ctx, depth, current) {
|
|
3145
3267
|
const nodes = [];
|
|
3146
3268
|
for (let i = 0, len = current.length; i < len; i++) {
|
|
3147
3269
|
if (i in current) {
|
|
3148
|
-
nodes[i] = parseSOS(ctx, current[i]);
|
|
3270
|
+
nodes[i] = parseSOS(ctx, depth, current[i]);
|
|
3271
|
+
} else {
|
|
3272
|
+
nodes[i] = 0;
|
|
3149
3273
|
}
|
|
3150
3274
|
}
|
|
3151
3275
|
return nodes;
|
|
3152
3276
|
}
|
|
3153
|
-
function parseArray2(ctx, id, current) {
|
|
3154
|
-
return createArrayNode(id, current, parseItems2(ctx, current));
|
|
3277
|
+
function parseArray2(ctx, depth, id, current) {
|
|
3278
|
+
return createArrayNode(id, current, parseItems2(ctx, depth, current));
|
|
3155
3279
|
}
|
|
3156
|
-
function parseProperties2(ctx, properties) {
|
|
3280
|
+
function parseProperties2(ctx, depth, properties) {
|
|
3157
3281
|
const entries = Object.entries(properties);
|
|
3158
3282
|
const keyNodes = [];
|
|
3159
3283
|
const valueNodes = [];
|
|
3160
3284
|
for (let i = 0, len = entries.length; i < len; i++) {
|
|
3161
3285
|
keyNodes.push(serializeString(entries[i][0]));
|
|
3162
|
-
valueNodes.push(parseSOS(ctx, entries[i][1]));
|
|
3286
|
+
valueNodes.push(parseSOS(ctx, depth, entries[i][1]));
|
|
3163
3287
|
}
|
|
3164
3288
|
if (SYM_ITERATOR in properties) {
|
|
3165
3289
|
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ITERATOR));
|
|
@@ -3168,6 +3292,7 @@ function parseProperties2(ctx, properties) {
|
|
|
3168
3292
|
parseIteratorFactory(ctx.base),
|
|
3169
3293
|
parseSOS(
|
|
3170
3294
|
ctx,
|
|
3295
|
+
depth,
|
|
3171
3296
|
iteratorToSequence(properties)
|
|
3172
3297
|
)
|
|
3173
3298
|
)
|
|
@@ -3180,6 +3305,7 @@ function parseProperties2(ctx, properties) {
|
|
|
3180
3305
|
parseAsyncIteratorFactory(ctx.base),
|
|
3181
3306
|
parseSOS(
|
|
3182
3307
|
ctx,
|
|
3308
|
+
depth,
|
|
3183
3309
|
ctx.type === 1 /* Sync */ ? createStream() : createStreamFromAsyncIterable(
|
|
3184
3310
|
properties
|
|
3185
3311
|
)
|
|
@@ -3199,58 +3325,70 @@ function parseProperties2(ctx, properties) {
|
|
|
3199
3325
|
}
|
|
3200
3326
|
return {
|
|
3201
3327
|
k: keyNodes,
|
|
3202
|
-
v: valueNodes
|
|
3203
|
-
s: keyNodes.length
|
|
3328
|
+
v: valueNodes
|
|
3204
3329
|
};
|
|
3205
3330
|
}
|
|
3206
|
-
function parsePlainObject2(ctx, id, current, empty) {
|
|
3207
|
-
return createObjectNode(
|
|
3331
|
+
function parsePlainObject2(ctx, depth, id, current, empty) {
|
|
3332
|
+
return createObjectNode(
|
|
3333
|
+
id,
|
|
3334
|
+
current,
|
|
3335
|
+
empty,
|
|
3336
|
+
parseProperties2(ctx, depth, current)
|
|
3337
|
+
);
|
|
3208
3338
|
}
|
|
3209
|
-
function parseBoxed2(ctx, id, current) {
|
|
3210
|
-
return createBoxedNode(id, parseSOS(ctx, current.valueOf()));
|
|
3339
|
+
function parseBoxed2(ctx, depth, id, current) {
|
|
3340
|
+
return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
|
|
3211
3341
|
}
|
|
3212
|
-
function parseTypedArray2(ctx, id, current) {
|
|
3213
|
-
return createTypedArrayNode(
|
|
3342
|
+
function parseTypedArray2(ctx, depth, id, current) {
|
|
3343
|
+
return createTypedArrayNode(
|
|
3344
|
+
id,
|
|
3345
|
+
current,
|
|
3346
|
+
parseSOS(ctx, depth, current.buffer)
|
|
3347
|
+
);
|
|
3214
3348
|
}
|
|
3215
|
-
function parseBigIntTypedArray2(ctx, id, current) {
|
|
3216
|
-
return createBigIntTypedArrayNode(
|
|
3349
|
+
function parseBigIntTypedArray2(ctx, depth, id, current) {
|
|
3350
|
+
return createBigIntTypedArrayNode(
|
|
3351
|
+
id,
|
|
3352
|
+
current,
|
|
3353
|
+
parseSOS(ctx, depth, current.buffer)
|
|
3354
|
+
);
|
|
3217
3355
|
}
|
|
3218
|
-
function parseDataView2(ctx, id, current) {
|
|
3219
|
-
return createDataViewNode(id, current, parseSOS(ctx, current.buffer));
|
|
3356
|
+
function parseDataView2(ctx, depth, id, current) {
|
|
3357
|
+
return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
3220
3358
|
}
|
|
3221
|
-
function parseError2(ctx, id, current) {
|
|
3359
|
+
function parseError2(ctx, depth, id, current) {
|
|
3222
3360
|
const options = getErrorOptions(current, ctx.base.features);
|
|
3223
3361
|
return createErrorNode(
|
|
3224
3362
|
id,
|
|
3225
3363
|
current,
|
|
3226
|
-
options ? parseProperties2(ctx, options) : NIL
|
|
3364
|
+
options ? parseProperties2(ctx, depth, options) : NIL
|
|
3227
3365
|
);
|
|
3228
3366
|
}
|
|
3229
|
-
function parseAggregateError2(ctx, id, current) {
|
|
3367
|
+
function parseAggregateError2(ctx, depth, id, current) {
|
|
3230
3368
|
const options = getErrorOptions(current, ctx.base.features);
|
|
3231
3369
|
return createAggregateErrorNode(
|
|
3232
3370
|
id,
|
|
3233
3371
|
current,
|
|
3234
|
-
options ? parseProperties2(ctx, options) : NIL
|
|
3372
|
+
options ? parseProperties2(ctx, depth, options) : NIL
|
|
3235
3373
|
);
|
|
3236
3374
|
}
|
|
3237
|
-
function parseMap2(ctx, id, current) {
|
|
3375
|
+
function parseMap2(ctx, depth, id, current) {
|
|
3238
3376
|
const keyNodes = [];
|
|
3239
3377
|
const valueNodes = [];
|
|
3240
3378
|
for (const [key, value] of current.entries()) {
|
|
3241
|
-
keyNodes.push(parseSOS(ctx, key));
|
|
3242
|
-
valueNodes.push(parseSOS(ctx, value));
|
|
3379
|
+
keyNodes.push(parseSOS(ctx, depth, key));
|
|
3380
|
+
valueNodes.push(parseSOS(ctx, depth, value));
|
|
3243
3381
|
}
|
|
3244
|
-
return createMapNode(ctx.base, id, keyNodes, valueNodes
|
|
3382
|
+
return createMapNode(ctx.base, id, keyNodes, valueNodes);
|
|
3245
3383
|
}
|
|
3246
|
-
function parseSet2(ctx, id, current) {
|
|
3384
|
+
function parseSet2(ctx, depth, id, current) {
|
|
3247
3385
|
const items = [];
|
|
3248
3386
|
for (const item of current.keys()) {
|
|
3249
|
-
items.push(parseSOS(ctx, item));
|
|
3387
|
+
items.push(parseSOS(ctx, depth, item));
|
|
3250
3388
|
}
|
|
3251
|
-
return createSetNode(id,
|
|
3389
|
+
return createSetNode(id, items);
|
|
3252
3390
|
}
|
|
3253
|
-
function parseStream2(ctx, id, current) {
|
|
3391
|
+
function parseStream2(ctx, depth, id, current) {
|
|
3254
3392
|
const result = createStreamConstructorNode(
|
|
3255
3393
|
id,
|
|
3256
3394
|
parseSpecialReference(ctx.base, 4 /* StreamConstructor */),
|
|
@@ -3263,7 +3401,7 @@ function parseStream2(ctx, id, current) {
|
|
|
3263
3401
|
current.on({
|
|
3264
3402
|
next: (value) => {
|
|
3265
3403
|
if (ctx.state.alive) {
|
|
3266
|
-
const parsed = parseWithError(ctx, value);
|
|
3404
|
+
const parsed = parseWithError(ctx, depth, value);
|
|
3267
3405
|
if (parsed) {
|
|
3268
3406
|
onParse(ctx, createStreamNextNode(id, parsed));
|
|
3269
3407
|
}
|
|
@@ -3271,7 +3409,7 @@ function parseStream2(ctx, id, current) {
|
|
|
3271
3409
|
},
|
|
3272
3410
|
throw: (value) => {
|
|
3273
3411
|
if (ctx.state.alive) {
|
|
3274
|
-
const parsed = parseWithError(ctx, value);
|
|
3412
|
+
const parsed = parseWithError(ctx, depth, value);
|
|
3275
3413
|
if (parsed) {
|
|
3276
3414
|
onParse(ctx, createStreamThrowNode(id, parsed));
|
|
3277
3415
|
}
|
|
@@ -3280,7 +3418,7 @@ function parseStream2(ctx, id, current) {
|
|
|
3280
3418
|
},
|
|
3281
3419
|
return: (value) => {
|
|
3282
3420
|
if (ctx.state.alive) {
|
|
3283
|
-
const parsed = parseWithError(ctx, value);
|
|
3421
|
+
const parsed = parseWithError(ctx, depth, value);
|
|
3284
3422
|
if (parsed) {
|
|
3285
3423
|
onParse(ctx, createStreamReturnNode(id, parsed));
|
|
3286
3424
|
}
|
|
@@ -3290,9 +3428,9 @@ function parseStream2(ctx, id, current) {
|
|
|
3290
3428
|
});
|
|
3291
3429
|
return result;
|
|
3292
3430
|
}
|
|
3293
|
-
function handlePromiseSuccess(id, data) {
|
|
3431
|
+
function handlePromiseSuccess(id, depth, data) {
|
|
3294
3432
|
if (this.state.alive) {
|
|
3295
|
-
const parsed = parseWithError(this, data);
|
|
3433
|
+
const parsed = parseWithError(this, depth, data);
|
|
3296
3434
|
if (parsed) {
|
|
3297
3435
|
onParse(
|
|
3298
3436
|
this,
|
|
@@ -3304,7 +3442,6 @@ function handlePromiseSuccess(id, data) {
|
|
|
3304
3442
|
NIL,
|
|
3305
3443
|
NIL,
|
|
3306
3444
|
NIL,
|
|
3307
|
-
NIL,
|
|
3308
3445
|
[
|
|
3309
3446
|
parseSpecialReference(this.base, 2 /* PromiseSuccess */),
|
|
3310
3447
|
parsed
|
|
@@ -3318,9 +3455,9 @@ function handlePromiseSuccess(id, data) {
|
|
|
3318
3455
|
popPendingState(this);
|
|
3319
3456
|
}
|
|
3320
3457
|
}
|
|
3321
|
-
function handlePromiseFailure(id, data) {
|
|
3458
|
+
function handlePromiseFailure(id, depth, data) {
|
|
3322
3459
|
if (this.state.alive) {
|
|
3323
|
-
const parsed = parseWithError(this, data);
|
|
3460
|
+
const parsed = parseWithError(this, depth, data);
|
|
3324
3461
|
if (parsed) {
|
|
3325
3462
|
onParse(
|
|
3326
3463
|
this,
|
|
@@ -3332,7 +3469,6 @@ function handlePromiseFailure(id, data) {
|
|
|
3332
3469
|
NIL,
|
|
3333
3470
|
NIL,
|
|
3334
3471
|
NIL,
|
|
3335
|
-
NIL,
|
|
3336
3472
|
[
|
|
3337
3473
|
parseSpecialReference(this.base, 3 /* PromiseFailure */),
|
|
3338
3474
|
parsed
|
|
@@ -3346,80 +3482,74 @@ function handlePromiseFailure(id, data) {
|
|
|
3346
3482
|
}
|
|
3347
3483
|
popPendingState(this);
|
|
3348
3484
|
}
|
|
3349
|
-
function parsePromise2(ctx, id, current) {
|
|
3485
|
+
function parsePromise2(ctx, depth, id, current) {
|
|
3350
3486
|
const resolver = createIndexForValue(ctx.base, {});
|
|
3351
3487
|
if (ctx.type === 2 /* Stream */) {
|
|
3352
3488
|
pushPendingState(ctx);
|
|
3353
3489
|
current.then(
|
|
3354
|
-
handlePromiseSuccess.bind(ctx, resolver),
|
|
3355
|
-
handlePromiseFailure.bind(ctx, resolver)
|
|
3490
|
+
handlePromiseSuccess.bind(ctx, resolver, depth),
|
|
3491
|
+
handlePromiseFailure.bind(ctx, resolver, depth)
|
|
3356
3492
|
);
|
|
3357
3493
|
}
|
|
3358
3494
|
return createPromiseConstructorNode(ctx.base, id, resolver);
|
|
3359
3495
|
}
|
|
3360
|
-
function parsePluginSync(ctx, id, current, currentPlugins) {
|
|
3496
|
+
function parsePluginSync(ctx, depth, id, current, currentPlugins) {
|
|
3361
3497
|
for (let i = 0, len = currentPlugins.length; i < len; i++) {
|
|
3362
3498
|
const plugin = currentPlugins[i];
|
|
3363
3499
|
if (plugin.parse.sync && plugin.test(current)) {
|
|
3364
|
-
if (ctx.child == null) {
|
|
3365
|
-
ctx.child = new SyncParsePluginContext(ctx);
|
|
3366
|
-
}
|
|
3367
3500
|
return createPluginNode(
|
|
3368
3501
|
id,
|
|
3369
3502
|
plugin.tag,
|
|
3370
|
-
plugin.parse.sync(current, ctx
|
|
3503
|
+
plugin.parse.sync(current, new SyncParsePluginContext(ctx, depth), {
|
|
3371
3504
|
id
|
|
3372
3505
|
})
|
|
3373
3506
|
);
|
|
3374
3507
|
}
|
|
3375
3508
|
}
|
|
3376
|
-
return
|
|
3509
|
+
return NIL;
|
|
3377
3510
|
}
|
|
3378
|
-
function parsePluginStream(ctx, id, current, currentPlugins) {
|
|
3511
|
+
function parsePluginStream(ctx, depth, id, current, currentPlugins) {
|
|
3379
3512
|
for (let i = 0, len = currentPlugins.length; i < len; i++) {
|
|
3380
3513
|
const plugin = currentPlugins[i];
|
|
3381
3514
|
if (plugin.parse.stream && plugin.test(current)) {
|
|
3382
|
-
if (ctx.child == null) {
|
|
3383
|
-
ctx.child = new StreamParsePluginContext(ctx);
|
|
3384
|
-
}
|
|
3385
3515
|
return createPluginNode(
|
|
3386
3516
|
id,
|
|
3387
3517
|
plugin.tag,
|
|
3388
|
-
plugin.parse.stream(current, ctx
|
|
3518
|
+
plugin.parse.stream(current, new StreamParsePluginContext(ctx, depth), {
|
|
3389
3519
|
id
|
|
3390
3520
|
})
|
|
3391
3521
|
);
|
|
3392
3522
|
}
|
|
3393
3523
|
}
|
|
3394
|
-
return
|
|
3524
|
+
return NIL;
|
|
3395
3525
|
}
|
|
3396
|
-
function parsePlugin2(ctx, id, current) {
|
|
3526
|
+
function parsePlugin2(ctx, depth, id, current) {
|
|
3397
3527
|
const currentPlugins = ctx.base.plugins;
|
|
3398
3528
|
if (currentPlugins) {
|
|
3399
|
-
return ctx.type === 1 /* Sync */ ? parsePluginSync(ctx, id, current, currentPlugins) : parsePluginStream(ctx, id, current, currentPlugins);
|
|
3529
|
+
return ctx.type === 1 /* Sync */ ? parsePluginSync(ctx, depth, id, current, currentPlugins) : parsePluginStream(ctx, depth, id, current, currentPlugins);
|
|
3400
3530
|
}
|
|
3401
|
-
return
|
|
3531
|
+
return NIL;
|
|
3402
3532
|
}
|
|
3403
|
-
function parseObjectPhase2(ctx, id, current, currentClass) {
|
|
3533
|
+
function parseObjectPhase2(ctx, depth, id, current, currentClass) {
|
|
3404
3534
|
switch (currentClass) {
|
|
3405
3535
|
case Object:
|
|
3406
3536
|
return parsePlainObject2(
|
|
3407
3537
|
ctx,
|
|
3538
|
+
depth,
|
|
3408
3539
|
id,
|
|
3409
3540
|
current,
|
|
3410
3541
|
false
|
|
3411
3542
|
);
|
|
3412
|
-
case
|
|
3543
|
+
case NIL:
|
|
3413
3544
|
return parsePlainObject2(
|
|
3414
3545
|
ctx,
|
|
3546
|
+
depth,
|
|
3415
3547
|
id,
|
|
3416
3548
|
current,
|
|
3417
3549
|
true
|
|
3418
3550
|
);
|
|
3419
3551
|
case Date:
|
|
3420
3552
|
return createDateNode(id, current);
|
|
3421
|
-
case RegExp:
|
|
3422
|
-
return createRegExpNode(id, current);
|
|
3423
3553
|
case Error:
|
|
3424
3554
|
case EvalError:
|
|
3425
3555
|
case RangeError:
|
|
@@ -3427,12 +3557,12 @@ function parseObjectPhase2(ctx, id, current, currentClass) {
|
|
|
3427
3557
|
case SyntaxError:
|
|
3428
3558
|
case TypeError:
|
|
3429
3559
|
case URIError:
|
|
3430
|
-
return parseError2(ctx, id, current);
|
|
3560
|
+
return parseError2(ctx, depth, id, current);
|
|
3431
3561
|
case Number:
|
|
3432
3562
|
case Boolean:
|
|
3433
3563
|
case String:
|
|
3434
3564
|
case BigInt:
|
|
3435
|
-
return parseBoxed2(ctx, id, current);
|
|
3565
|
+
return parseBoxed2(ctx, depth, id, current);
|
|
3436
3566
|
case ArrayBuffer:
|
|
3437
3567
|
return createArrayBufferNode(
|
|
3438
3568
|
ctx.base,
|
|
@@ -3448,26 +3578,40 @@ function parseObjectPhase2(ctx, id, current, currentClass) {
|
|
|
3448
3578
|
case Uint8ClampedArray:
|
|
3449
3579
|
case Float32Array:
|
|
3450
3580
|
case Float64Array:
|
|
3451
|
-
return parseTypedArray2(
|
|
3581
|
+
return parseTypedArray2(
|
|
3582
|
+
ctx,
|
|
3583
|
+
depth,
|
|
3584
|
+
id,
|
|
3585
|
+
current
|
|
3586
|
+
);
|
|
3452
3587
|
case DataView:
|
|
3453
|
-
return parseDataView2(ctx, id, current);
|
|
3588
|
+
return parseDataView2(ctx, depth, id, current);
|
|
3454
3589
|
case Map:
|
|
3455
|
-
return parseMap2(
|
|
3590
|
+
return parseMap2(
|
|
3591
|
+
ctx,
|
|
3592
|
+
depth,
|
|
3593
|
+
id,
|
|
3594
|
+
current
|
|
3595
|
+
);
|
|
3456
3596
|
case Set:
|
|
3457
|
-
return parseSet2(ctx, id, current);
|
|
3597
|
+
return parseSet2(ctx, depth, id, current);
|
|
3458
3598
|
default:
|
|
3459
3599
|
break;
|
|
3460
3600
|
}
|
|
3461
3601
|
if (currentClass === Promise || current instanceof Promise) {
|
|
3462
|
-
return parsePromise2(ctx, id, current);
|
|
3602
|
+
return parsePromise2(ctx, depth, id, current);
|
|
3463
3603
|
}
|
|
3464
3604
|
const currentFeatures = ctx.base.features;
|
|
3605
|
+
if (currentFeatures & 32 /* RegExp */ && currentClass === RegExp) {
|
|
3606
|
+
return createRegExpNode(id, current);
|
|
3607
|
+
}
|
|
3465
3608
|
if (currentFeatures & 16 /* BigIntTypedArray */) {
|
|
3466
3609
|
switch (currentClass) {
|
|
3467
3610
|
case BigInt64Array:
|
|
3468
3611
|
case BigUint64Array:
|
|
3469
3612
|
return parseBigIntTypedArray2(
|
|
3470
3613
|
ctx,
|
|
3614
|
+
depth,
|
|
3471
3615
|
id,
|
|
3472
3616
|
current
|
|
3473
3617
|
);
|
|
@@ -3476,48 +3620,57 @@ function parseObjectPhase2(ctx, id, current, currentClass) {
|
|
|
3476
3620
|
}
|
|
3477
3621
|
}
|
|
3478
3622
|
if (currentFeatures & 1 /* AggregateError */ && typeof AggregateError !== "undefined" && (currentClass === AggregateError || current instanceof AggregateError)) {
|
|
3479
|
-
return parseAggregateError2(
|
|
3623
|
+
return parseAggregateError2(
|
|
3624
|
+
ctx,
|
|
3625
|
+
depth,
|
|
3626
|
+
id,
|
|
3627
|
+
current
|
|
3628
|
+
);
|
|
3480
3629
|
}
|
|
3481
3630
|
if (current instanceof Error) {
|
|
3482
|
-
return parseError2(ctx, id, current);
|
|
3631
|
+
return parseError2(ctx, depth, id, current);
|
|
3483
3632
|
}
|
|
3484
3633
|
if (SYM_ITERATOR in current || SYM_ASYNC_ITERATOR in current) {
|
|
3485
|
-
return parsePlainObject2(ctx, id, current, !!currentClass);
|
|
3634
|
+
return parsePlainObject2(ctx, depth, id, current, !!currentClass);
|
|
3486
3635
|
}
|
|
3487
3636
|
throw new SerovalUnsupportedTypeError(current);
|
|
3488
3637
|
}
|
|
3489
|
-
function parseObject(ctx, id, current) {
|
|
3638
|
+
function parseObject(ctx, depth, id, current) {
|
|
3490
3639
|
if (Array.isArray(current)) {
|
|
3491
|
-
return parseArray2(ctx, id, current);
|
|
3640
|
+
return parseArray2(ctx, depth, id, current);
|
|
3492
3641
|
}
|
|
3493
3642
|
if (isStream(current)) {
|
|
3494
|
-
return parseStream2(ctx, id, current);
|
|
3643
|
+
return parseStream2(ctx, depth, id, current);
|
|
3495
3644
|
}
|
|
3496
3645
|
const currentClass = current.constructor;
|
|
3497
3646
|
if (currentClass === OpaqueReference) {
|
|
3498
3647
|
return parseSOS(
|
|
3499
3648
|
ctx,
|
|
3649
|
+
depth,
|
|
3500
3650
|
current.replacement
|
|
3501
3651
|
);
|
|
3502
3652
|
}
|
|
3503
|
-
const parsed = parsePlugin2(ctx, id, current);
|
|
3653
|
+
const parsed = parsePlugin2(ctx, depth, id, current);
|
|
3504
3654
|
if (parsed) {
|
|
3505
3655
|
return parsed;
|
|
3506
3656
|
}
|
|
3507
|
-
return parseObjectPhase2(ctx, id, current, currentClass);
|
|
3657
|
+
return parseObjectPhase2(ctx, depth, id, current, currentClass);
|
|
3508
3658
|
}
|
|
3509
|
-
function parseFunction(ctx, current) {
|
|
3659
|
+
function parseFunction(ctx, depth, current) {
|
|
3510
3660
|
const ref = getReferenceNode(ctx.base, current);
|
|
3511
3661
|
if (ref.type !== 0 /* Fresh */) {
|
|
3512
3662
|
return ref.value;
|
|
3513
3663
|
}
|
|
3514
|
-
const plugin = parsePlugin2(ctx, ref.value, current);
|
|
3664
|
+
const plugin = parsePlugin2(ctx, depth, ref.value, current);
|
|
3515
3665
|
if (plugin) {
|
|
3516
3666
|
return plugin;
|
|
3517
3667
|
}
|
|
3518
3668
|
throw new SerovalUnsupportedTypeError(current);
|
|
3519
3669
|
}
|
|
3520
|
-
function parseSOS(ctx, current) {
|
|
3670
|
+
function parseSOS(ctx, depth, current) {
|
|
3671
|
+
if (depth >= ctx.base.depthLimit) {
|
|
3672
|
+
throw new SerovalDepthLimitError(ctx.base.depthLimit);
|
|
3673
|
+
}
|
|
3521
3674
|
switch (typeof current) {
|
|
3522
3675
|
case "boolean":
|
|
3523
3676
|
return current ? TRUE_NODE : FALSE_NODE;
|
|
@@ -3532,14 +3685,14 @@ function parseSOS(ctx, current) {
|
|
|
3532
3685
|
case "object": {
|
|
3533
3686
|
if (current) {
|
|
3534
3687
|
const ref = getReferenceNode(ctx.base, current);
|
|
3535
|
-
return ref.type === 0 /* Fresh */ ? parseObject(ctx, ref.value, current) : ref.value;
|
|
3688
|
+
return ref.type === 0 /* Fresh */ ? parseObject(ctx, depth + 1, ref.value, current) : ref.value;
|
|
3536
3689
|
}
|
|
3537
3690
|
return NULL_NODE;
|
|
3538
3691
|
}
|
|
3539
3692
|
case "symbol":
|
|
3540
3693
|
return parseWellKnownSymbol(ctx.base, current);
|
|
3541
3694
|
case "function": {
|
|
3542
|
-
return parseFunction(ctx, current);
|
|
3695
|
+
return parseFunction(ctx, depth, current);
|
|
3543
3696
|
}
|
|
3544
3697
|
default:
|
|
3545
3698
|
throw new SerovalUnsupportedTypeError(current);
|
|
@@ -3547,7 +3700,7 @@ function parseSOS(ctx, current) {
|
|
|
3547
3700
|
}
|
|
3548
3701
|
function parseTop(ctx, current) {
|
|
3549
3702
|
try {
|
|
3550
|
-
return parseSOS(ctx, current);
|
|
3703
|
+
return parseSOS(ctx, 0, current);
|
|
3551
3704
|
} catch (error) {
|
|
3552
3705
|
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3553
3706
|
}
|
|
@@ -3586,16 +3739,16 @@ function popPendingState(ctx) {
|
|
|
3586
3739
|
onDone(ctx);
|
|
3587
3740
|
}
|
|
3588
3741
|
}
|
|
3589
|
-
function parseWithError(ctx, current) {
|
|
3742
|
+
function parseWithError(ctx, depth, current) {
|
|
3590
3743
|
try {
|
|
3591
|
-
return parseSOS(ctx, current);
|
|
3744
|
+
return parseSOS(ctx, depth, current);
|
|
3592
3745
|
} catch (err) {
|
|
3593
3746
|
onError(ctx, err);
|
|
3594
3747
|
return NIL;
|
|
3595
3748
|
}
|
|
3596
3749
|
}
|
|
3597
3750
|
function startStreamParse(ctx, current) {
|
|
3598
|
-
const parsed = parseWithError(ctx, current);
|
|
3751
|
+
const parsed = parseWithError(ctx, 0, current);
|
|
3599
3752
|
if (parsed) {
|
|
3600
3753
|
onParseInternal(ctx, parsed, true);
|
|
3601
3754
|
ctx.state.initial = false;
|
|
@@ -3715,7 +3868,9 @@ function fromCrossJSON(source, options) {
|
|
|
3715
3868
|
const plugins = resolvePlugins(options.plugins);
|
|
3716
3869
|
const ctx = createCrossDeserializerContext({
|
|
3717
3870
|
plugins,
|
|
3718
|
-
refs: options.refs
|
|
3871
|
+
refs: options.refs,
|
|
3872
|
+
features: options.features,
|
|
3873
|
+
disabledFeatures: options.disabledFeatures
|
|
3719
3874
|
});
|
|
3720
3875
|
return deserializeTop(ctx, source);
|
|
3721
3876
|
}
|
|
@@ -3865,10 +4020,15 @@ function compileJSON(source, options = {}) {
|
|
|
3865
4020
|
return serializeTopVanilla(ctx, source.t);
|
|
3866
4021
|
}
|
|
3867
4022
|
function fromJSON(source, options = {}) {
|
|
4023
|
+
var _a;
|
|
3868
4024
|
const plugins = resolvePlugins(options.plugins);
|
|
4025
|
+
const disabledFeatures = options.disabledFeatures || 0;
|
|
4026
|
+
const sourceFeatures = (_a = source.f) != null ? _a : ALL_ENABLED;
|
|
3869
4027
|
const ctx = createVanillaDeserializerContext({
|
|
3870
4028
|
plugins,
|
|
3871
|
-
markedRefs: source.m
|
|
4029
|
+
markedRefs: source.m,
|
|
4030
|
+
features: sourceFeatures & ~disabledFeatures,
|
|
4031
|
+
disabledFeatures
|
|
3872
4032
|
});
|
|
3873
4033
|
return deserializeTop(ctx, source.t);
|
|
3874
4034
|
}
|