seroval 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/development/index.cjs +184 -44
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +184 -44
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/base-primitives.d.ts +5 -4
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +2 -1
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/constructors.d.ts +1 -5
- package/dist/types/core/constructors.d.ts.map +1 -1
- package/dist/types/core/context/async-parser.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts.map +1 -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.map +1 -1
- package/dist/types/core/errors.d.ts +5 -5
- 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/plugin.d.ts +11 -7
- package/dist/types/core/plugin.d.ts.map +1 -1
- package/dist/types/core/sequence.d.ts +11 -0
- package/dist/types/core/sequence.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +15 -4
- package/dist/types/core/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/core/Serializer.ts +119 -0
- package/src/core/base-primitives.ts +537 -0
- package/src/core/compat.ts +23 -0
- package/src/core/constants.ts +202 -0
- package/src/core/constructors.ts +265 -0
- package/src/core/context/async-parser.ts +663 -0
- package/src/core/context/deserializer.ts +828 -0
- package/src/core/context/parser.ts +335 -0
- package/src/core/context/serializer.ts +1460 -0
- package/src/core/context/sync-parser.ts +932 -0
- package/src/core/cross/index.ts +188 -0
- package/src/core/errors.ts +196 -0
- package/src/core/function-string.ts +32 -0
- package/src/core/keys.ts +17 -0
- package/src/core/literals.ts +43 -0
- package/src/core/node.ts +40 -0
- package/src/core/opaque-reference.ts +9 -0
- package/src/core/plugin.ts +105 -0
- package/src/core/reference.ts +66 -0
- package/src/core/sequence.ts +55 -0
- package/src/core/special-reference.ts +42 -0
- package/src/core/stream.ts +71 -0
- package/src/core/string.ts +86 -0
- package/src/core/symbols.ts +18 -0
- package/src/core/tree/index.ts +134 -0
- package/src/core/types.ts +377 -0
- package/src/core/utils/error.ts +73 -0
- package/src/core/utils/get-identifier.ts +18 -0
- package/src/core/utils/get-object-flag.ts +14 -0
- package/src/core/utils/is-valid-identifier.ts +12 -0
- package/src/core/utils/promise-to-result.ts +9 -0
- package/src/core/utils/typed-array.ts +56 -0
- package/src/index.ts +36 -0
- package/dist/types/core/utils/iterator-to-sequence.d.ts +0 -8
- package/dist/types/core/utils/iterator-to-sequence.d.ts.map +0 -1
|
@@ -174,7 +174,7 @@ var ERROR_CONSTRUCTOR = {
|
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
// src/core/node.ts
|
|
177
|
-
function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o) {
|
|
177
|
+
function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o, l) {
|
|
178
178
|
return {
|
|
179
179
|
t,
|
|
180
180
|
i,
|
|
@@ -186,7 +186,8 @@ function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o) {
|
|
|
186
186
|
a,
|
|
187
187
|
f,
|
|
188
188
|
b,
|
|
189
|
-
o
|
|
189
|
+
o,
|
|
190
|
+
l
|
|
190
191
|
};
|
|
191
192
|
}
|
|
192
193
|
|
|
@@ -203,6 +204,7 @@ function createConstantNode(value) {
|
|
|
203
204
|
NIL,
|
|
204
205
|
NIL,
|
|
205
206
|
NIL,
|
|
207
|
+
NIL,
|
|
206
208
|
NIL
|
|
207
209
|
);
|
|
208
210
|
}
|
|
@@ -467,6 +469,7 @@ function createNumberNode(value) {
|
|
|
467
469
|
NIL,
|
|
468
470
|
NIL,
|
|
469
471
|
NIL,
|
|
472
|
+
NIL,
|
|
470
473
|
NIL
|
|
471
474
|
);
|
|
472
475
|
}
|
|
@@ -482,6 +485,7 @@ function createStringNode(value) {
|
|
|
482
485
|
NIL,
|
|
483
486
|
NIL,
|
|
484
487
|
NIL,
|
|
488
|
+
NIL,
|
|
485
489
|
NIL
|
|
486
490
|
);
|
|
487
491
|
}
|
|
@@ -497,6 +501,7 @@ function createBigIntNode(current) {
|
|
|
497
501
|
NIL,
|
|
498
502
|
NIL,
|
|
499
503
|
NIL,
|
|
504
|
+
NIL,
|
|
500
505
|
NIL
|
|
501
506
|
);
|
|
502
507
|
}
|
|
@@ -512,6 +517,7 @@ function createIndexedValueNode(id) {
|
|
|
512
517
|
NIL,
|
|
513
518
|
NIL,
|
|
514
519
|
NIL,
|
|
520
|
+
NIL,
|
|
515
521
|
NIL
|
|
516
522
|
);
|
|
517
523
|
}
|
|
@@ -528,6 +534,7 @@ function createDateNode(id, current) {
|
|
|
528
534
|
NIL,
|
|
529
535
|
NIL,
|
|
530
536
|
NIL,
|
|
537
|
+
NIL,
|
|
531
538
|
NIL
|
|
532
539
|
);
|
|
533
540
|
}
|
|
@@ -543,6 +550,7 @@ function createRegExpNode(id, current) {
|
|
|
543
550
|
NIL,
|
|
544
551
|
NIL,
|
|
545
552
|
NIL,
|
|
553
|
+
NIL,
|
|
546
554
|
NIL
|
|
547
555
|
);
|
|
548
556
|
}
|
|
@@ -558,6 +566,7 @@ function createWKSymbolNode(id, current) {
|
|
|
558
566
|
NIL,
|
|
559
567
|
NIL,
|
|
560
568
|
NIL,
|
|
569
|
+
NIL,
|
|
561
570
|
NIL
|
|
562
571
|
);
|
|
563
572
|
}
|
|
@@ -573,6 +582,7 @@ function createReferenceNode(id, ref) {
|
|
|
573
582
|
NIL,
|
|
574
583
|
NIL,
|
|
575
584
|
NIL,
|
|
585
|
+
NIL,
|
|
576
586
|
NIL
|
|
577
587
|
);
|
|
578
588
|
}
|
|
@@ -588,6 +598,7 @@ function createPluginNode(id, tag, value) {
|
|
|
588
598
|
NIL,
|
|
589
599
|
NIL,
|
|
590
600
|
NIL,
|
|
601
|
+
NIL,
|
|
591
602
|
NIL
|
|
592
603
|
);
|
|
593
604
|
}
|
|
@@ -603,7 +614,8 @@ function createArrayNode(id, current, parsedItems) {
|
|
|
603
614
|
parsedItems,
|
|
604
615
|
NIL,
|
|
605
616
|
NIL,
|
|
606
|
-
getObjectFlag(current)
|
|
617
|
+
getObjectFlag(current),
|
|
618
|
+
NIL
|
|
607
619
|
);
|
|
608
620
|
}
|
|
609
621
|
function createBoxedNode(id, boxed) {
|
|
@@ -618,6 +630,7 @@ function createBoxedNode(id, boxed) {
|
|
|
618
630
|
NIL,
|
|
619
631
|
boxed,
|
|
620
632
|
NIL,
|
|
633
|
+
NIL,
|
|
621
634
|
NIL
|
|
622
635
|
);
|
|
623
636
|
}
|
|
@@ -633,7 +646,8 @@ function createTypedArrayNode(id, current, buffer) {
|
|
|
633
646
|
NIL,
|
|
634
647
|
buffer,
|
|
635
648
|
current.byteOffset,
|
|
636
|
-
NIL
|
|
649
|
+
NIL,
|
|
650
|
+
current.length
|
|
637
651
|
);
|
|
638
652
|
}
|
|
639
653
|
function createBigIntTypedArrayNode(id, current, buffer) {
|
|
@@ -648,7 +662,8 @@ function createBigIntTypedArrayNode(id, current, buffer) {
|
|
|
648
662
|
NIL,
|
|
649
663
|
buffer,
|
|
650
664
|
current.byteOffset,
|
|
651
|
-
NIL
|
|
665
|
+
NIL,
|
|
666
|
+
current.byteLength
|
|
652
667
|
);
|
|
653
668
|
}
|
|
654
669
|
function createDataViewNode(id, current, buffer) {
|
|
@@ -663,7 +678,8 @@ function createDataViewNode(id, current, buffer) {
|
|
|
663
678
|
NIL,
|
|
664
679
|
buffer,
|
|
665
680
|
current.byteOffset,
|
|
666
|
-
NIL
|
|
681
|
+
NIL,
|
|
682
|
+
current.byteLength
|
|
667
683
|
);
|
|
668
684
|
}
|
|
669
685
|
function createErrorNode(id, current, options) {
|
|
@@ -678,6 +694,7 @@ function createErrorNode(id, current, options) {
|
|
|
678
694
|
NIL,
|
|
679
695
|
NIL,
|
|
680
696
|
NIL,
|
|
697
|
+
NIL,
|
|
681
698
|
NIL
|
|
682
699
|
);
|
|
683
700
|
}
|
|
@@ -693,6 +710,7 @@ function createAggregateErrorNode(id, current, options) {
|
|
|
693
710
|
NIL,
|
|
694
711
|
NIL,
|
|
695
712
|
NIL,
|
|
713
|
+
NIL,
|
|
696
714
|
NIL
|
|
697
715
|
);
|
|
698
716
|
}
|
|
@@ -708,6 +726,7 @@ function createSetNode(id, items) {
|
|
|
708
726
|
items,
|
|
709
727
|
NIL,
|
|
710
728
|
NIL,
|
|
729
|
+
NIL,
|
|
711
730
|
NIL
|
|
712
731
|
);
|
|
713
732
|
}
|
|
@@ -723,6 +742,7 @@ function createIteratorFactoryInstanceNode(factory, items) {
|
|
|
723
742
|
[factory, items],
|
|
724
743
|
NIL,
|
|
725
744
|
NIL,
|
|
745
|
+
NIL,
|
|
726
746
|
NIL
|
|
727
747
|
);
|
|
728
748
|
}
|
|
@@ -738,6 +758,7 @@ function createAsyncIteratorFactoryInstanceNode(factory, items) {
|
|
|
738
758
|
[factory, items],
|
|
739
759
|
NIL,
|
|
740
760
|
NIL,
|
|
761
|
+
NIL,
|
|
741
762
|
NIL
|
|
742
763
|
);
|
|
743
764
|
}
|
|
@@ -753,6 +774,7 @@ function createStreamConstructorNode(id, factory, sequence) {
|
|
|
753
774
|
sequence,
|
|
754
775
|
factory,
|
|
755
776
|
NIL,
|
|
777
|
+
NIL,
|
|
756
778
|
NIL
|
|
757
779
|
);
|
|
758
780
|
}
|
|
@@ -768,6 +790,7 @@ function createStreamNextNode(id, parsed) {
|
|
|
768
790
|
NIL,
|
|
769
791
|
parsed,
|
|
770
792
|
NIL,
|
|
793
|
+
NIL,
|
|
771
794
|
NIL
|
|
772
795
|
);
|
|
773
796
|
}
|
|
@@ -783,6 +806,7 @@ function createStreamThrowNode(id, parsed) {
|
|
|
783
806
|
NIL,
|
|
784
807
|
parsed,
|
|
785
808
|
NIL,
|
|
809
|
+
NIL,
|
|
786
810
|
NIL
|
|
787
811
|
);
|
|
788
812
|
}
|
|
@@ -798,16 +822,33 @@ function createStreamReturnNode(id, parsed) {
|
|
|
798
822
|
NIL,
|
|
799
823
|
parsed,
|
|
800
824
|
NIL,
|
|
825
|
+
NIL,
|
|
801
826
|
NIL
|
|
802
827
|
);
|
|
803
828
|
}
|
|
829
|
+
function createSequenceNode(id, sequence, throwAt, doneAt) {
|
|
830
|
+
return createSerovalNode(
|
|
831
|
+
35 /* Sequence */,
|
|
832
|
+
id,
|
|
833
|
+
throwAt,
|
|
834
|
+
NIL,
|
|
835
|
+
NIL,
|
|
836
|
+
NIL,
|
|
837
|
+
NIL,
|
|
838
|
+
sequence,
|
|
839
|
+
NIL,
|
|
840
|
+
NIL,
|
|
841
|
+
NIL,
|
|
842
|
+
doneAt
|
|
843
|
+
);
|
|
844
|
+
}
|
|
804
845
|
|
|
805
846
|
// src/core/errors.ts
|
|
806
847
|
var { toString: objectToString } = Object.prototype;
|
|
807
848
|
function getErrorMessageDev(type, cause) {
|
|
808
849
|
if (cause instanceof Error) {
|
|
809
850
|
return `Seroval caught an error during the ${type} process.
|
|
810
|
-
|
|
851
|
+
|
|
811
852
|
${cause.name}
|
|
812
853
|
${cause.message}
|
|
813
854
|
|
|
@@ -1138,6 +1179,43 @@ var ARRAY_BUFFER_CONSTRUCTOR = (b64) => {
|
|
|
1138
1179
|
};
|
|
1139
1180
|
var SERIALIZED_ARRAY_BUFFER_CONSTRUCTOR = /* @__PURE__ */ ARRAY_BUFFER_CONSTRUCTOR.toString();
|
|
1140
1181
|
|
|
1182
|
+
// src/core/sequence.ts
|
|
1183
|
+
function isSequence(value) {
|
|
1184
|
+
return "__SEROVAL_SEQUENCE__" in value;
|
|
1185
|
+
}
|
|
1186
|
+
function createSequence(values, throwAt, doneAt) {
|
|
1187
|
+
return {
|
|
1188
|
+
__SEROVAL_SEQUENCE__: true,
|
|
1189
|
+
v: values,
|
|
1190
|
+
t: throwAt,
|
|
1191
|
+
d: doneAt
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
function createSequenceFromIterable(source) {
|
|
1195
|
+
const values = [];
|
|
1196
|
+
let throwsAt = -1;
|
|
1197
|
+
let doneAt = -1;
|
|
1198
|
+
const iterator = source[SYM_ITERATOR]();
|
|
1199
|
+
while (true) {
|
|
1200
|
+
try {
|
|
1201
|
+
const value = iterator.next();
|
|
1202
|
+
values.push(value.value);
|
|
1203
|
+
if (value.done) {
|
|
1204
|
+
doneAt = values.length - 1;
|
|
1205
|
+
break;
|
|
1206
|
+
}
|
|
1207
|
+
} catch (error) {
|
|
1208
|
+
throwsAt = values.length;
|
|
1209
|
+
values.push(error);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
return createSequence(values, throwsAt, doneAt);
|
|
1213
|
+
}
|
|
1214
|
+
var createIterator = ITERATOR_CONSTRUCTOR(SYM_ITERATOR);
|
|
1215
|
+
function sequenceToIterator(sequence) {
|
|
1216
|
+
return createIterator(sequence);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1141
1219
|
// src/core/special-reference.ts
|
|
1142
1220
|
var ITERATOR = {};
|
|
1143
1221
|
var ASYNC_ITERATOR = {};
|
|
@@ -1195,36 +1273,6 @@ function streamToAsyncIterable(stream) {
|
|
|
1195
1273
|
);
|
|
1196
1274
|
}
|
|
1197
1275
|
|
|
1198
|
-
// src/core/utils/iterator-to-sequence.ts
|
|
1199
|
-
function iteratorToSequence(source) {
|
|
1200
|
-
const values = [];
|
|
1201
|
-
let throwsAt = -1;
|
|
1202
|
-
let doneAt = -1;
|
|
1203
|
-
const iterator = source[SYM_ITERATOR]();
|
|
1204
|
-
while (true) {
|
|
1205
|
-
try {
|
|
1206
|
-
const value = iterator.next();
|
|
1207
|
-
values.push(value.value);
|
|
1208
|
-
if (value.done) {
|
|
1209
|
-
doneAt = values.length - 1;
|
|
1210
|
-
break;
|
|
1211
|
-
}
|
|
1212
|
-
} catch (error) {
|
|
1213
|
-
throwsAt = values.length;
|
|
1214
|
-
values.push(error);
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
return {
|
|
1218
|
-
v: values,
|
|
1219
|
-
t: throwsAt,
|
|
1220
|
-
d: doneAt
|
|
1221
|
-
};
|
|
1222
|
-
}
|
|
1223
|
-
var createIterator = ITERATOR_CONSTRUCTOR(SYM_ITERATOR);
|
|
1224
|
-
function sequenceToIterator(sequence) {
|
|
1225
|
-
return createIterator(sequence);
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
1276
|
// src/core/utils/promise-to-result.ts
|
|
1229
1277
|
async function promiseToResult(current) {
|
|
1230
1278
|
try {
|
|
@@ -1306,6 +1354,7 @@ function parseSpecialReference(ctx, ref) {
|
|
|
1306
1354
|
NIL,
|
|
1307
1355
|
NIL,
|
|
1308
1356
|
NIL,
|
|
1357
|
+
NIL,
|
|
1309
1358
|
NIL
|
|
1310
1359
|
);
|
|
1311
1360
|
}
|
|
@@ -1325,6 +1374,7 @@ function parseIteratorFactory(ctx) {
|
|
|
1325
1374
|
NIL,
|
|
1326
1375
|
parseWellKnownSymbol(ctx, SYM_ITERATOR),
|
|
1327
1376
|
NIL,
|
|
1377
|
+
NIL,
|
|
1328
1378
|
NIL
|
|
1329
1379
|
);
|
|
1330
1380
|
}
|
|
@@ -1347,6 +1397,7 @@ function parseAsyncIteratorFactory(ctx) {
|
|
|
1347
1397
|
],
|
|
1348
1398
|
NIL,
|
|
1349
1399
|
NIL,
|
|
1400
|
+
NIL,
|
|
1350
1401
|
NIL
|
|
1351
1402
|
);
|
|
1352
1403
|
}
|
|
@@ -1362,7 +1413,8 @@ function createObjectNode(id, current, empty, record) {
|
|
|
1362
1413
|
NIL,
|
|
1363
1414
|
NIL,
|
|
1364
1415
|
NIL,
|
|
1365
|
-
getObjectFlag(current)
|
|
1416
|
+
getObjectFlag(current),
|
|
1417
|
+
NIL
|
|
1366
1418
|
);
|
|
1367
1419
|
}
|
|
1368
1420
|
function createMapNode(ctx, id, k, v) {
|
|
@@ -1377,6 +1429,7 @@ function createMapNode(ctx, id, k, v) {
|
|
|
1377
1429
|
NIL,
|
|
1378
1430
|
parseSpecialReference(ctx, 0 /* MapSentinel */),
|
|
1379
1431
|
NIL,
|
|
1432
|
+
NIL,
|
|
1380
1433
|
NIL
|
|
1381
1434
|
);
|
|
1382
1435
|
}
|
|
@@ -1392,6 +1445,7 @@ function createPromiseConstructorNode(ctx, id, resolver) {
|
|
|
1392
1445
|
NIL,
|
|
1393
1446
|
parseSpecialReference(ctx, 1 /* PromiseConstructor */),
|
|
1394
1447
|
NIL,
|
|
1448
|
+
NIL,
|
|
1395
1449
|
NIL
|
|
1396
1450
|
);
|
|
1397
1451
|
}
|
|
@@ -1412,6 +1466,7 @@ function createArrayBufferNode(ctx, id, current) {
|
|
|
1412
1466
|
NIL,
|
|
1413
1467
|
parseSpecialReference(ctx, 5 /* ArrayBufferConstructor */),
|
|
1414
1468
|
NIL,
|
|
1469
|
+
NIL,
|
|
1415
1470
|
NIL
|
|
1416
1471
|
);
|
|
1417
1472
|
}
|
|
@@ -1462,7 +1517,9 @@ async function parseProperties(ctx, depth, properties) {
|
|
|
1462
1517
|
await parseAsync(
|
|
1463
1518
|
ctx,
|
|
1464
1519
|
depth,
|
|
1465
|
-
|
|
1520
|
+
createSequenceFromIterable(
|
|
1521
|
+
properties
|
|
1522
|
+
)
|
|
1466
1523
|
)
|
|
1467
1524
|
)
|
|
1468
1525
|
);
|
|
@@ -1596,6 +1653,7 @@ async function parsePromise(ctx, depth, id, current) {
|
|
|
1596
1653
|
NIL,
|
|
1597
1654
|
await parseAsync(ctx, depth, result),
|
|
1598
1655
|
NIL,
|
|
1656
|
+
NIL,
|
|
1599
1657
|
NIL
|
|
1600
1658
|
);
|
|
1601
1659
|
}
|
|
@@ -1653,6 +1711,13 @@ async function parseStream(ctx, depth, id, current) {
|
|
|
1653
1711
|
)
|
|
1654
1712
|
);
|
|
1655
1713
|
}
|
|
1714
|
+
async function parseSequence(ctx, depth, id, current) {
|
|
1715
|
+
const nodes = [];
|
|
1716
|
+
for (let i = 0, len = current.v.length; i < len; i++) {
|
|
1717
|
+
nodes[i] = await parseAsync(ctx, depth, current.v[i]);
|
|
1718
|
+
}
|
|
1719
|
+
return createSequenceNode(id, nodes, current.t, current.d);
|
|
1720
|
+
}
|
|
1656
1721
|
async function parseObjectAsync(ctx, depth, id, current) {
|
|
1657
1722
|
if (Array.isArray(current)) {
|
|
1658
1723
|
return parseArray(ctx, depth, id, current);
|
|
@@ -1660,6 +1725,9 @@ async function parseObjectAsync(ctx, depth, id, current) {
|
|
|
1660
1725
|
if (isStream(current)) {
|
|
1661
1726
|
return parseStream(ctx, depth, id, current);
|
|
1662
1727
|
}
|
|
1728
|
+
if (isSequence(current)) {
|
|
1729
|
+
return parseSequence(ctx, depth, id, current);
|
|
1730
|
+
}
|
|
1663
1731
|
const currentClass = current.constructor;
|
|
1664
1732
|
if (currentClass === OpaqueReference) {
|
|
1665
1733
|
return parseAsync(
|
|
@@ -2115,7 +2183,11 @@ function deserializeTypedArray(ctx, depth, node) {
|
|
|
2115
2183
|
if (offset < 0 || offset > source.byteLength) {
|
|
2116
2184
|
throw new SerovalMalformedNodeError(node);
|
|
2117
2185
|
}
|
|
2118
|
-
const result = assignIndexedValue(
|
|
2186
|
+
const result = assignIndexedValue(
|
|
2187
|
+
ctx,
|
|
2188
|
+
node.i,
|
|
2189
|
+
new construct(source, offset, node.l)
|
|
2190
|
+
);
|
|
2119
2191
|
return result;
|
|
2120
2192
|
}
|
|
2121
2193
|
function deserializeDataView(ctx, depth, node) {
|
|
@@ -2125,7 +2197,11 @@ function deserializeDataView(ctx, depth, node) {
|
|
|
2125
2197
|
if (offset < 0 || offset > source.byteLength) {
|
|
2126
2198
|
throw new SerovalMalformedNodeError(node);
|
|
2127
2199
|
}
|
|
2128
|
-
const result = assignIndexedValue(
|
|
2200
|
+
const result = assignIndexedValue(
|
|
2201
|
+
ctx,
|
|
2202
|
+
node.i,
|
|
2203
|
+
new DataView(source, offset, node.l)
|
|
2204
|
+
);
|
|
2129
2205
|
return result;
|
|
2130
2206
|
}
|
|
2131
2207
|
function deserializeDictionary(ctx, depth, node, result) {
|
|
@@ -2266,6 +2342,17 @@ function deserializeAsyncIteratorFactory(ctx, depth, node) {
|
|
|
2266
2342
|
deserialize(ctx, depth, node.a[1]);
|
|
2267
2343
|
return NIL;
|
|
2268
2344
|
}
|
|
2345
|
+
function deserializeSequence(ctx, depth, node) {
|
|
2346
|
+
const result = assignIndexedValue(
|
|
2347
|
+
ctx,
|
|
2348
|
+
node.i,
|
|
2349
|
+
createSequence([], node.s, node.l)
|
|
2350
|
+
);
|
|
2351
|
+
for (let i = 0, len = node.a.length; i < len; i++) {
|
|
2352
|
+
result.v[i] = deserialize(ctx, depth, node.a[i]);
|
|
2353
|
+
}
|
|
2354
|
+
return result;
|
|
2355
|
+
}
|
|
2269
2356
|
function deserialize(ctx, depth, node) {
|
|
2270
2357
|
if (depth > ctx.base.depthLimit) {
|
|
2271
2358
|
throw new SerovalDepthLimitError(ctx.base.depthLimit);
|
|
@@ -2342,6 +2429,8 @@ function deserialize(ctx, depth, node) {
|
|
|
2342
2429
|
case 29 /* AsyncIteratorFactory */:
|
|
2343
2430
|
return deserializeAsyncIteratorFactory(ctx, depth, node);
|
|
2344
2431
|
// case SerovalNodeType.SpecialReference:
|
|
2432
|
+
case 35 /* Sequence */:
|
|
2433
|
+
return deserializeSequence(ctx, depth, node);
|
|
2345
2434
|
default:
|
|
2346
2435
|
throw new SerovalUnsupportedNodeError(node);
|
|
2347
2436
|
}
|
|
@@ -2606,6 +2695,9 @@ function createArrayAssign(ctx, ref, index, value) {
|
|
|
2606
2695
|
function createObjectAssign(ctx, ref, key, value) {
|
|
2607
2696
|
createAssignment(ctx.base, getRefParam(ctx, ref) + "." + key, value);
|
|
2608
2697
|
}
|
|
2698
|
+
function createSequenceAssign(ctx, ref, index, value) {
|
|
2699
|
+
createAssignment(ctx.base, getRefParam(ctx, ref) + ".v[" + index + "]", value);
|
|
2700
|
+
}
|
|
2609
2701
|
function isIndexedValueInStack(ctx, node) {
|
|
2610
2702
|
return node.t === 4 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
2611
2703
|
}
|
|
@@ -2917,10 +3009,10 @@ function serializeArrayBuffer(ctx, node) {
|
|
|
2917
3009
|
return getConstructor(ctx, node.f) + '("' + node.s + '")';
|
|
2918
3010
|
}
|
|
2919
3011
|
function serializeTypedArray(ctx, node) {
|
|
2920
|
-
return "new " + node.c + "(" + serialize(ctx, node.f) + "," + node.b + ")";
|
|
3012
|
+
return "new " + node.c + "(" + serialize(ctx, node.f) + "," + node.b + "," + node.l + ")";
|
|
2921
3013
|
}
|
|
2922
3014
|
function serializeDataView(ctx, node) {
|
|
2923
|
-
return "new DataView(" + serialize(ctx, node.f) + "," + node.b + ")";
|
|
3015
|
+
return "new DataView(" + serialize(ctx, node.f) + "," + node.b + "," + node.l + ")";
|
|
2924
3016
|
}
|
|
2925
3017
|
function serializeAggregateError(ctx, node) {
|
|
2926
3018
|
const id = node.i;
|
|
@@ -3079,6 +3171,38 @@ function serializeStreamThrow(ctx, node) {
|
|
|
3079
3171
|
function serializeStreamReturn(ctx, node) {
|
|
3080
3172
|
return getRefParam(ctx, node.i) + ".return(" + serialize(ctx, node.f) + ")";
|
|
3081
3173
|
}
|
|
3174
|
+
function serializeSequenceItem(ctx, id, index, item) {
|
|
3175
|
+
const base = ctx.base;
|
|
3176
|
+
if (isIndexedValueInStack(base, item)) {
|
|
3177
|
+
markSerializerRef(base, id);
|
|
3178
|
+
createSequenceAssign(
|
|
3179
|
+
ctx,
|
|
3180
|
+
id,
|
|
3181
|
+
index,
|
|
3182
|
+
getRefParam(ctx, item.i)
|
|
3183
|
+
);
|
|
3184
|
+
return "";
|
|
3185
|
+
}
|
|
3186
|
+
return serialize(ctx, item);
|
|
3187
|
+
}
|
|
3188
|
+
function serializeSequence(ctx, node) {
|
|
3189
|
+
const items = node.a;
|
|
3190
|
+
const size = items.length;
|
|
3191
|
+
const id = node.i;
|
|
3192
|
+
if (size > 0) {
|
|
3193
|
+
ctx.base.stack.push(id);
|
|
3194
|
+
let result = serializeSequenceItem(ctx, id, 0, items[0]);
|
|
3195
|
+
for (let i = 1, item = result; i < size; i++) {
|
|
3196
|
+
item = serializeSequenceItem(ctx, id, i, items[i]);
|
|
3197
|
+
result += (item && result && ",") + item;
|
|
3198
|
+
}
|
|
3199
|
+
ctx.base.stack.pop();
|
|
3200
|
+
if (result) {
|
|
3201
|
+
return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + node.s + ",d:" + node.l + "}";
|
|
3202
|
+
}
|
|
3203
|
+
}
|
|
3204
|
+
return "{__SEROVAL_SEQUENCE__:!0,v:[],t:-1,d:0}";
|
|
3205
|
+
}
|
|
3082
3206
|
function serializeAssignable(ctx, node) {
|
|
3083
3207
|
switch (node.t) {
|
|
3084
3208
|
case 17 /* WKSymbol */:
|
|
@@ -3120,6 +3244,8 @@ function serializeAssignable(ctx, node) {
|
|
|
3120
3244
|
return serializePlugin(ctx, node);
|
|
3121
3245
|
case 26 /* SpecialReference */:
|
|
3122
3246
|
return SPECIAL_REF_STRING[node.s];
|
|
3247
|
+
case 35 /* Sequence */:
|
|
3248
|
+
return serializeSequence(ctx, node);
|
|
3123
3249
|
default:
|
|
3124
3250
|
throw new SerovalUnsupportedNodeError(node);
|
|
3125
3251
|
}
|
|
@@ -3293,7 +3419,9 @@ function parseProperties2(ctx, depth, properties) {
|
|
|
3293
3419
|
parseSOS(
|
|
3294
3420
|
ctx,
|
|
3295
3421
|
depth,
|
|
3296
|
-
|
|
3422
|
+
createSequenceFromIterable(
|
|
3423
|
+
properties
|
|
3424
|
+
)
|
|
3297
3425
|
)
|
|
3298
3426
|
)
|
|
3299
3427
|
);
|
|
@@ -3448,6 +3576,7 @@ function handlePromiseSuccess(id, depth, data) {
|
|
|
3448
3576
|
],
|
|
3449
3577
|
NIL,
|
|
3450
3578
|
NIL,
|
|
3579
|
+
NIL,
|
|
3451
3580
|
NIL
|
|
3452
3581
|
)
|
|
3453
3582
|
);
|
|
@@ -3475,6 +3604,7 @@ function handlePromiseFailure(id, depth, data) {
|
|
|
3475
3604
|
],
|
|
3476
3605
|
NIL,
|
|
3477
3606
|
NIL,
|
|
3607
|
+
NIL,
|
|
3478
3608
|
NIL
|
|
3479
3609
|
)
|
|
3480
3610
|
);
|
|
@@ -3530,6 +3660,13 @@ function parsePlugin2(ctx, depth, id, current) {
|
|
|
3530
3660
|
}
|
|
3531
3661
|
return NIL;
|
|
3532
3662
|
}
|
|
3663
|
+
function parseSequence2(ctx, depth, id, current) {
|
|
3664
|
+
const nodes = [];
|
|
3665
|
+
for (let i = 0, len = current.v.length; i < len; i++) {
|
|
3666
|
+
nodes[i] = parseSOS(ctx, depth, current.v[i]);
|
|
3667
|
+
}
|
|
3668
|
+
return createSequenceNode(id, nodes, current.t, current.d);
|
|
3669
|
+
}
|
|
3533
3670
|
function parseObjectPhase2(ctx, depth, id, current, currentClass) {
|
|
3534
3671
|
switch (currentClass) {
|
|
3535
3672
|
case Object:
|
|
@@ -3642,6 +3779,9 @@ function parseObject(ctx, depth, id, current) {
|
|
|
3642
3779
|
if (isStream(current)) {
|
|
3643
3780
|
return parseStream2(ctx, depth, id, current);
|
|
3644
3781
|
}
|
|
3782
|
+
if (isSequence(current)) {
|
|
3783
|
+
return parseSequence2(ctx, depth, id, current);
|
|
3784
|
+
}
|
|
3645
3785
|
const currentClass = current.constructor;
|
|
3646
3786
|
if (currentClass === OpaqueReference) {
|
|
3647
3787
|
return parseSOS(
|