seroval 0.11.1 → 0.11.2

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.
@@ -661,30 +661,53 @@ function getErrorOptions(ctx, error) {
661
661
  }
662
662
  return options;
663
663
  }
664
- function isIterable(value) {
664
+ function isIterable(ctx, value) {
665
665
  if (!value || typeof value !== "object") {
666
666
  return false;
667
667
  }
668
668
  if (Array.isArray(value)) {
669
669
  return false;
670
670
  }
671
- switch (value.constructor) {
672
- case Map:
673
- case Set:
674
- case Int8Array:
675
- case Int16Array:
676
- case Int32Array:
677
- case Uint8Array:
678
- case Uint16Array:
679
- case Uint32Array:
680
- case Uint8ClampedArray:
681
- case Float32Array:
682
- case Float64Array:
683
- case BigInt64Array:
684
- case BigUint64Array:
685
- return false;
686
- default:
687
- break;
671
+ const currentClass = value.constructor;
672
+ if (ctx.features & 2048 /* TypedArray */) {
673
+ switch (currentClass) {
674
+ case Int8Array:
675
+ case Int16Array:
676
+ case Int32Array:
677
+ case Uint8Array:
678
+ case Uint16Array:
679
+ case Uint32Array:
680
+ case Uint8ClampedArray:
681
+ case Float32Array:
682
+ case Float64Array:
683
+ return false;
684
+ default:
685
+ break;
686
+ }
687
+ }
688
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
689
+ switch (currentClass) {
690
+ case BigInt64Array:
691
+ case BigUint64Array:
692
+ return false;
693
+ default:
694
+ break;
695
+ }
696
+ }
697
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
698
+ return false;
699
+ }
700
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
701
+ return false;
702
+ }
703
+ if (ctx.features & 8192 /* WebAPI */) {
704
+ switch (currentClass) {
705
+ case Headers:
706
+ case File:
707
+ return false;
708
+ default:
709
+ break;
710
+ }
688
711
  }
689
712
  return Symbol.iterator in value;
690
713
  }
@@ -875,7 +898,7 @@ async function generateNodeList(ctx, current) {
875
898
  for (let i = 0; i < size; i++) {
876
899
  if (i in current) {
877
900
  item = current[i];
878
- if (isIterable(item)) {
901
+ if (isIterable(ctx, item)) {
879
902
  deferred[i] = item;
880
903
  } else {
881
904
  nodes[i] = await parseAsync(ctx, item);
@@ -914,7 +937,7 @@ async function generateMapNode(ctx, id, current) {
914
937
  let deferredSize = 0;
915
938
  let nodeSize = 0;
916
939
  for (const [key, value] of current.entries()) {
917
- if (isIterable(key) || isIterable(value)) {
940
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
918
941
  deferredKey[deferredSize] = key;
919
942
  deferredValue[deferredSize] = value;
920
943
  deferredSize++;
@@ -950,7 +973,7 @@ async function generateSetNode(ctx, id, current) {
950
973
  let deferredSize = 0;
951
974
  let nodeSize = 0;
952
975
  for (const item of current.keys()) {
953
- if (isIterable(item)) {
976
+ if (isIterable(ctx, item)) {
954
977
  deferred[deferredSize++] = item;
955
978
  } else {
956
979
  nodes[nodeSize++] = await parseAsync(ctx, item);
@@ -988,7 +1011,7 @@ async function generateProperties(ctx, properties) {
988
1011
  for (const key of keys) {
989
1012
  item = properties[key];
990
1013
  escaped = serializeString(key);
991
- if (isIterable(item)) {
1014
+ if (isIterable(ctx, item)) {
992
1015
  deferredKeys[deferredSize] = escaped;
993
1016
  deferredValues[deferredSize] = item;
994
1017
  deferredSize++;
@@ -1034,7 +1057,7 @@ async function generatePlainProperties(ctx, properties) {
1034
1057
  for (const key of keys) {
1035
1058
  item = properties[key];
1036
1059
  escaped = serializeString(key);
1037
- if (isIterable(item)) {
1060
+ if (isIterable(ctx, item)) {
1038
1061
  deferredKeys[deferredSize] = escaped;
1039
1062
  deferredValues[deferredSize] = item;
1040
1063
  deferredSize++;
@@ -2433,7 +2456,7 @@ function generateNodeList2(ctx, current) {
2433
2456
  for (let i = 0; i < size; i++) {
2434
2457
  if (i in current) {
2435
2458
  item = current[i];
2436
- if (isIterable(item)) {
2459
+ if (isIterable(ctx, item)) {
2437
2460
  deferred[i] = item;
2438
2461
  } else {
2439
2462
  nodes[i] = parseSync(ctx, item);
@@ -2472,7 +2495,7 @@ function generateMapNode2(ctx, id, current) {
2472
2495
  let deferredSize = 0;
2473
2496
  let nodeSize = 0;
2474
2497
  for (const [key, value] of current.entries()) {
2475
- if (isIterable(key) || isIterable(value)) {
2498
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
2476
2499
  deferredKey[deferredSize] = key;
2477
2500
  deferredValue[deferredSize] = value;
2478
2501
  deferredSize++;
@@ -2508,7 +2531,7 @@ function generateSetNode2(ctx, id, current) {
2508
2531
  let deferredSize = 0;
2509
2532
  let nodeSize = 0;
2510
2533
  for (const item of current.keys()) {
2511
- if (isIterable(item)) {
2534
+ if (isIterable(ctx, item)) {
2512
2535
  deferred[deferredSize++] = item;
2513
2536
  } else {
2514
2537
  nodes[nodeSize++] = parseSync(ctx, item);
@@ -2546,7 +2569,7 @@ function generateProperties2(ctx, properties) {
2546
2569
  for (const key of keys) {
2547
2570
  item = properties[key];
2548
2571
  escaped = serializeString(key);
2549
- if (isIterable(item)) {
2572
+ if (isIterable(ctx, item)) {
2550
2573
  deferredKeys[deferredSize] = escaped;
2551
2574
  deferredValues[deferredSize] = item;
2552
2575
  deferredSize++;
@@ -2589,7 +2612,7 @@ function generatePlainProperties2(ctx, properties) {
2589
2612
  for (const key of keys) {
2590
2613
  item = properties[key];
2591
2614
  escaped = serializeString(key);
2592
- if (isIterable(item)) {
2615
+ if (isIterable(ctx, item)) {
2593
2616
  deferredKeys[deferredSize] = escaped;
2594
2617
  deferredValues[deferredSize] = item;
2595
2618
  deferredSize++;
@@ -3053,12 +3076,7 @@ function createTypedArrayNode2(ctx, id, current) {
3053
3076
  o: void 0
3054
3077
  };
3055
3078
  }
3056
- var BIGINT_FLAG2 = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
3057
3079
  function createBigIntTypedArrayNode2(ctx, id, current) {
3058
- assert(
3059
- (ctx.features & BIGINT_FLAG2) === BIGINT_FLAG2,
3060
- new UnsupportedTypeError(current)
3061
- );
3062
3080
  return {
3063
3081
  t: 16 /* BigIntTypedArray */,
3064
3082
  i: id,
@@ -3156,7 +3174,7 @@ async function generateNodeList3(ctx, current) {
3156
3174
  for (let i = 0; i < size; i++) {
3157
3175
  if (i in current) {
3158
3176
  item = current[i];
3159
- if (isIterable(item)) {
3177
+ if (isIterable(ctx, item)) {
3160
3178
  deferred[i] = item;
3161
3179
  } else {
3162
3180
  nodes[i] = await crossParseAsync(ctx, item);
@@ -3195,7 +3213,7 @@ async function generateMapNode3(ctx, id, current) {
3195
3213
  let deferredSize = 0;
3196
3214
  let nodeSize = 0;
3197
3215
  for (const [key, value] of current.entries()) {
3198
- if (isIterable(key) || isIterable(value)) {
3216
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
3199
3217
  deferredKey[deferredSize] = key;
3200
3218
  deferredValue[deferredSize] = value;
3201
3219
  deferredSize++;
@@ -3231,7 +3249,7 @@ async function generateSetNode3(ctx, id, current) {
3231
3249
  let deferredSize = 0;
3232
3250
  let nodeSize = 0;
3233
3251
  for (const item of current.keys()) {
3234
- if (isIterable(item)) {
3252
+ if (isIterable(ctx, item)) {
3235
3253
  deferred[deferredSize++] = item;
3236
3254
  } else {
3237
3255
  nodes[nodeSize++] = await crossParseAsync(ctx, item);
@@ -3269,7 +3287,7 @@ async function generateProperties3(ctx, properties) {
3269
3287
  for (const key of keys) {
3270
3288
  item = properties[key];
3271
3289
  escaped = serializeString(key);
3272
- if (isIterable(item)) {
3290
+ if (isIterable(ctx, item)) {
3273
3291
  deferredKeys[deferredSize] = escaped;
3274
3292
  deferredValues[deferredSize] = item;
3275
3293
  deferredSize++;
@@ -3315,7 +3333,7 @@ async function generatePlainProperties3(ctx, properties) {
3315
3333
  for (const key of keys) {
3316
3334
  item = properties[key];
3317
3335
  escaped = serializeString(key);
3318
- if (isIterable(item)) {
3336
+ if (isIterable(ctx, item)) {
3319
3337
  deferredKeys[deferredSize] = escaped;
3320
3338
  deferredValues[deferredSize] = item;
3321
3339
  deferredSize++;
@@ -4282,7 +4300,7 @@ function generateNodeList4(ctx, current) {
4282
4300
  for (let i = 0; i < size; i++) {
4283
4301
  if (i in current) {
4284
4302
  item = current[i];
4285
- if (isIterable(item)) {
4303
+ if (isIterable(ctx, item)) {
4286
4304
  deferred[i] = item;
4287
4305
  } else {
4288
4306
  nodes[i] = crossParseStream(ctx, item);
@@ -4321,7 +4339,7 @@ function generateMapNode4(ctx, id, current) {
4321
4339
  let deferredSize = 0;
4322
4340
  let nodeSize = 0;
4323
4341
  for (const [key, value] of current.entries()) {
4324
- if (isIterable(key) || isIterable(value)) {
4342
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
4325
4343
  deferredKey[deferredSize] = key;
4326
4344
  deferredValue[deferredSize] = value;
4327
4345
  deferredSize++;
@@ -4357,7 +4375,7 @@ function generateSetNode4(ctx, id, current) {
4357
4375
  let deferredSize = 0;
4358
4376
  let nodeSize = 0;
4359
4377
  for (const item of current.keys()) {
4360
- if (isIterable(item)) {
4378
+ if (isIterable(ctx, item)) {
4361
4379
  deferred[deferredSize++] = item;
4362
4380
  } else {
4363
4381
  nodes[nodeSize++] = crossParseStream(ctx, item);
@@ -4395,7 +4413,7 @@ function generateProperties4(ctx, properties) {
4395
4413
  for (const key of keys) {
4396
4414
  item = properties[key];
4397
4415
  escaped = serializeString(key);
4398
- if (isIterable(item)) {
4416
+ if (isIterable(ctx, item)) {
4399
4417
  deferredKeys[deferredSize] = escaped;
4400
4418
  deferredValues[deferredSize] = item;
4401
4419
  deferredSize++;
@@ -4441,7 +4459,7 @@ function generatePlainProperties4(ctx, properties) {
4441
4459
  for (const key of keys) {
4442
4460
  item = properties[key];
4443
4461
  escaped = serializeString(key);
4444
- if (isIterable(item)) {
4462
+ if (isIterable(ctx, item)) {
4445
4463
  deferredKeys[deferredSize] = escaped;
4446
4464
  deferredValues[deferredSize] = item;
4447
4465
  deferredSize++;
@@ -4626,52 +4644,13 @@ function generateBoxedNode4(ctx, id, current) {
4626
4644
  o: void 0
4627
4645
  };
4628
4646
  }
4629
- function generateReadableStreamNode(ctx, id, current) {
4630
- const reader = current.getReader();
4631
- pushPendingState(ctx);
4632
- function push() {
4633
- reader.read().then(
4634
- (data) => {
4635
- if (ctx.alive) {
4636
- if (data.done) {
4637
- ctx.onParse({
4638
- t: 33 /* ReadableStreamClose */,
4639
- i: id,
4640
- s: void 0,
4641
- l: void 0,
4642
- c: void 0,
4643
- m: void 0,
4644
- p: void 0,
4645
- e: void 0,
4646
- a: void 0,
4647
- f: void 0,
4648
- b: void 0,
4649
- o: void 0
4650
- }, false);
4651
- popPendingState(ctx);
4652
- } else {
4653
- ctx.onParse({
4654
- t: 32 /* ReadableStreamEnqueue */,
4655
- i: id,
4656
- s: void 0,
4657
- l: void 0,
4658
- c: void 0,
4659
- m: void 0,
4660
- p: void 0,
4661
- e: void 0,
4662
- a: void 0,
4663
- f: crossParseStream(ctx, data.value),
4664
- b: void 0,
4665
- o: void 0
4666
- }, false);
4667
- push();
4668
- }
4669
- }
4670
- },
4671
- (value) => {
4672
- if (ctx.alive) {
4647
+ function pushReadableStreamState(ctx, id, reader) {
4648
+ reader.read().then(
4649
+ (data) => {
4650
+ if (ctx.alive) {
4651
+ if (data.done) {
4673
4652
  ctx.onParse({
4674
- t: 34 /* ReadableStreamError */,
4653
+ t: 33 /* ReadableStreamClose */,
4675
4654
  i: id,
4676
4655
  s: void 0,
4677
4656
  l: void 0,
@@ -4680,16 +4659,54 @@ function generateReadableStreamNode(ctx, id, current) {
4680
4659
  p: void 0,
4681
4660
  e: void 0,
4682
4661
  a: void 0,
4683
- f: crossParseStream(ctx, value),
4662
+ f: void 0,
4684
4663
  b: void 0,
4685
4664
  o: void 0
4686
4665
  }, false);
4687
4666
  popPendingState(ctx);
4667
+ } else {
4668
+ ctx.onParse({
4669
+ t: 32 /* ReadableStreamEnqueue */,
4670
+ i: id,
4671
+ s: void 0,
4672
+ l: void 0,
4673
+ c: void 0,
4674
+ m: void 0,
4675
+ p: void 0,
4676
+ e: void 0,
4677
+ a: void 0,
4678
+ f: crossParseStream(ctx, data.value),
4679
+ b: void 0,
4680
+ o: void 0
4681
+ }, false);
4682
+ pushReadableStreamState(ctx, id, reader);
4688
4683
  }
4689
4684
  }
4690
- );
4691
- }
4692
- push();
4685
+ },
4686
+ (value) => {
4687
+ if (ctx.alive) {
4688
+ ctx.onParse({
4689
+ t: 34 /* ReadableStreamError */,
4690
+ i: id,
4691
+ s: void 0,
4692
+ l: void 0,
4693
+ c: void 0,
4694
+ m: void 0,
4695
+ p: void 0,
4696
+ e: void 0,
4697
+ a: void 0,
4698
+ f: crossParseStream(ctx, value),
4699
+ b: void 0,
4700
+ o: void 0
4701
+ }, false);
4702
+ popPendingState(ctx);
4703
+ }
4704
+ }
4705
+ );
4706
+ }
4707
+ function generateReadableStreamNode(ctx, id, current) {
4708
+ pushPendingState(ctx);
4709
+ pushReadableStreamState(ctx, id, current.getReader());
4693
4710
  return {
4694
4711
  t: 31 /* ReadableStreamConstructor */,
4695
4712
  i: id,
@@ -4938,7 +4955,7 @@ function generateNodeList5(ctx, current) {
4938
4955
  for (let i = 0; i < size; i++) {
4939
4956
  if (i in current) {
4940
4957
  item = current[i];
4941
- if (isIterable(item)) {
4958
+ if (isIterable(ctx, item)) {
4942
4959
  deferred[i] = item;
4943
4960
  } else {
4944
4961
  nodes[i] = crossParseSync(ctx, item);
@@ -4977,7 +4994,7 @@ function generateMapNode5(ctx, id, current) {
4977
4994
  let deferredSize = 0;
4978
4995
  let nodeSize = 0;
4979
4996
  for (const [key, value] of current.entries()) {
4980
- if (isIterable(key) || isIterable(value)) {
4997
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
4981
4998
  deferredKey[deferredSize] = key;
4982
4999
  deferredValue[deferredSize] = value;
4983
5000
  deferredSize++;
@@ -5013,7 +5030,7 @@ function generateSetNode5(ctx, id, current) {
5013
5030
  let deferredSize = 0;
5014
5031
  let nodeSize = 0;
5015
5032
  for (const item of current.keys()) {
5016
- if (isIterable(item)) {
5033
+ if (isIterable(ctx, item)) {
5017
5034
  deferred[deferredSize++] = item;
5018
5035
  } else {
5019
5036
  nodes[nodeSize++] = crossParseSync(ctx, item);
@@ -5051,7 +5068,7 @@ function generateProperties5(ctx, properties) {
5051
5068
  for (const key of keys) {
5052
5069
  item = properties[key];
5053
5070
  escaped = serializeString(key);
5054
- if (isIterable(item)) {
5071
+ if (isIterable(ctx, item)) {
5055
5072
  deferredKeys[deferredSize] = escaped;
5056
5073
  deferredValues[deferredSize] = item;
5057
5074
  deferredSize++;
@@ -5093,7 +5110,7 @@ function generatePlainProperties5(ctx, properties) {
5093
5110
  for (const key of keys) {
5094
5111
  item = properties[key];
5095
5112
  escaped = serializeString(key);
5096
- if (isIterable(item)) {
5113
+ if (isIterable(ctx, item)) {
5097
5114
  deferredKeys[deferredSize] = escaped;
5098
5115
  deferredValues[deferredSize] = item;
5099
5116
  deferredSize++;