seroval 0.11.1 → 0.11.3

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.
@@ -700,32 +700,58 @@ function getErrorOptions(ctx, error) {
700
700
  }
701
701
  return options;
702
702
  }
703
- function isIterable(value) {
703
+ function isIterable(ctx, value) {
704
704
  if (!value || typeof value !== "object") {
705
705
  return false;
706
706
  }
707
707
  if (Array.isArray(value)) {
708
708
  return false;
709
709
  }
710
- switch (value.constructor) {
711
- case Map:
712
- case Set:
713
- case Int8Array:
714
- case Int16Array:
715
- case Int32Array:
716
- case Uint8Array:
717
- case Uint16Array:
718
- case Uint32Array:
719
- case Uint8ClampedArray:
720
- case Float32Array:
721
- case Float64Array:
722
- case BigInt64Array:
723
- case BigUint64Array:
724
- return false;
725
- default:
726
- break;
710
+ const currentClass = value.constructor;
711
+ if (ctx.features & 2048 /* TypedArray */) {
712
+ switch (currentClass) {
713
+ case Int8Array:
714
+ case Int16Array:
715
+ case Int32Array:
716
+ case Uint8Array:
717
+ case Uint16Array:
718
+ case Uint32Array:
719
+ case Uint8ClampedArray:
720
+ case Float32Array:
721
+ case Float64Array:
722
+ return false;
723
+ default:
724
+ break;
725
+ }
727
726
  }
728
- return Symbol.iterator in value;
727
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
728
+ switch (currentClass) {
729
+ case BigInt64Array:
730
+ case BigUint64Array:
731
+ return false;
732
+ default:
733
+ break;
734
+ }
735
+ }
736
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
737
+ return false;
738
+ }
739
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
740
+ return false;
741
+ }
742
+ if (ctx.features & 8192 /* WebAPI */) {
743
+ switch (currentClass) {
744
+ case Headers:
745
+ case File:
746
+ return false;
747
+ default:
748
+ break;
749
+ }
750
+ }
751
+ if (ctx.features & 1024 /* Symbol */) {
752
+ return Symbol.iterator in value;
753
+ }
754
+ return false;
729
755
  }
730
756
  function getTypedArrayConstructor(name) {
731
757
  switch (name) {
@@ -914,7 +940,7 @@ async function generateNodeList(ctx, current) {
914
940
  for (let i = 0; i < size; i++) {
915
941
  if (i in current) {
916
942
  item = current[i];
917
- if (isIterable(item)) {
943
+ if (isIterable(ctx, item)) {
918
944
  deferred[i] = item;
919
945
  } else {
920
946
  nodes[i] = await parseAsync(ctx, item);
@@ -953,7 +979,7 @@ async function generateMapNode(ctx, id, current) {
953
979
  let deferredSize = 0;
954
980
  let nodeSize = 0;
955
981
  for (const [key, value] of current.entries()) {
956
- if (isIterable(key) || isIterable(value)) {
982
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
957
983
  deferredKey[deferredSize] = key;
958
984
  deferredValue[deferredSize] = value;
959
985
  deferredSize++;
@@ -989,7 +1015,7 @@ async function generateSetNode(ctx, id, current) {
989
1015
  let deferredSize = 0;
990
1016
  let nodeSize = 0;
991
1017
  for (const item of current.keys()) {
992
- if (isIterable(item)) {
1018
+ if (isIterable(ctx, item)) {
993
1019
  deferred[deferredSize++] = item;
994
1020
  } else {
995
1021
  nodes[nodeSize++] = await parseAsync(ctx, item);
@@ -1027,7 +1053,7 @@ async function generateProperties(ctx, properties) {
1027
1053
  for (const key of keys) {
1028
1054
  item = properties[key];
1029
1055
  escaped = serializeString(key);
1030
- if (isIterable(item)) {
1056
+ if (isIterable(ctx, item)) {
1031
1057
  deferredKeys[deferredSize] = escaped;
1032
1058
  deferredValues[deferredSize] = item;
1033
1059
  deferredSize++;
@@ -1073,7 +1099,7 @@ async function generatePlainProperties(ctx, properties) {
1073
1099
  for (const key of keys) {
1074
1100
  item = properties[key];
1075
1101
  escaped = serializeString(key);
1076
- if (isIterable(item)) {
1102
+ if (isIterable(ctx, item)) {
1077
1103
  deferredKeys[deferredSize] = escaped;
1078
1104
  deferredValues[deferredSize] = item;
1079
1105
  deferredSize++;
@@ -2472,7 +2498,7 @@ function generateNodeList2(ctx, current) {
2472
2498
  for (let i = 0; i < size; i++) {
2473
2499
  if (i in current) {
2474
2500
  item = current[i];
2475
- if (isIterable(item)) {
2501
+ if (isIterable(ctx, item)) {
2476
2502
  deferred[i] = item;
2477
2503
  } else {
2478
2504
  nodes[i] = parseSync(ctx, item);
@@ -2511,7 +2537,7 @@ function generateMapNode2(ctx, id, current) {
2511
2537
  let deferredSize = 0;
2512
2538
  let nodeSize = 0;
2513
2539
  for (const [key, value] of current.entries()) {
2514
- if (isIterable(key) || isIterable(value)) {
2540
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
2515
2541
  deferredKey[deferredSize] = key;
2516
2542
  deferredValue[deferredSize] = value;
2517
2543
  deferredSize++;
@@ -2547,7 +2573,7 @@ function generateSetNode2(ctx, id, current) {
2547
2573
  let deferredSize = 0;
2548
2574
  let nodeSize = 0;
2549
2575
  for (const item of current.keys()) {
2550
- if (isIterable(item)) {
2576
+ if (isIterable(ctx, item)) {
2551
2577
  deferred[deferredSize++] = item;
2552
2578
  } else {
2553
2579
  nodes[nodeSize++] = parseSync(ctx, item);
@@ -2585,7 +2611,7 @@ function generateProperties2(ctx, properties) {
2585
2611
  for (const key of keys) {
2586
2612
  item = properties[key];
2587
2613
  escaped = serializeString(key);
2588
- if (isIterable(item)) {
2614
+ if (isIterable(ctx, item)) {
2589
2615
  deferredKeys[deferredSize] = escaped;
2590
2616
  deferredValues[deferredSize] = item;
2591
2617
  deferredSize++;
@@ -2628,7 +2654,7 @@ function generatePlainProperties2(ctx, properties) {
2628
2654
  for (const key of keys) {
2629
2655
  item = properties[key];
2630
2656
  escaped = serializeString(key);
2631
- if (isIterable(item)) {
2657
+ if (isIterable(ctx, item)) {
2632
2658
  deferredKeys[deferredSize] = escaped;
2633
2659
  deferredValues[deferredSize] = item;
2634
2660
  deferredSize++;
@@ -3092,12 +3118,7 @@ function createTypedArrayNode2(ctx, id, current) {
3092
3118
  o: void 0
3093
3119
  };
3094
3120
  }
3095
- var BIGINT_FLAG2 = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
3096
3121
  function createBigIntTypedArrayNode2(ctx, id, current) {
3097
- assert(
3098
- (ctx.features & BIGINT_FLAG2) === BIGINT_FLAG2,
3099
- new UnsupportedTypeError(current)
3100
- );
3101
3122
  return {
3102
3123
  t: 16 /* BigIntTypedArray */,
3103
3124
  i: id,
@@ -3195,7 +3216,7 @@ async function generateNodeList3(ctx, current) {
3195
3216
  for (let i = 0; i < size; i++) {
3196
3217
  if (i in current) {
3197
3218
  item = current[i];
3198
- if (isIterable(item)) {
3219
+ if (isIterable(ctx, item)) {
3199
3220
  deferred[i] = item;
3200
3221
  } else {
3201
3222
  nodes[i] = await crossParseAsync(ctx, item);
@@ -3234,7 +3255,7 @@ async function generateMapNode3(ctx, id, current) {
3234
3255
  let deferredSize = 0;
3235
3256
  let nodeSize = 0;
3236
3257
  for (const [key, value] of current.entries()) {
3237
- if (isIterable(key) || isIterable(value)) {
3258
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
3238
3259
  deferredKey[deferredSize] = key;
3239
3260
  deferredValue[deferredSize] = value;
3240
3261
  deferredSize++;
@@ -3270,7 +3291,7 @@ async function generateSetNode3(ctx, id, current) {
3270
3291
  let deferredSize = 0;
3271
3292
  let nodeSize = 0;
3272
3293
  for (const item of current.keys()) {
3273
- if (isIterable(item)) {
3294
+ if (isIterable(ctx, item)) {
3274
3295
  deferred[deferredSize++] = item;
3275
3296
  } else {
3276
3297
  nodes[nodeSize++] = await crossParseAsync(ctx, item);
@@ -3308,7 +3329,7 @@ async function generateProperties3(ctx, properties) {
3308
3329
  for (const key of keys) {
3309
3330
  item = properties[key];
3310
3331
  escaped = serializeString(key);
3311
- if (isIterable(item)) {
3332
+ if (isIterable(ctx, item)) {
3312
3333
  deferredKeys[deferredSize] = escaped;
3313
3334
  deferredValues[deferredSize] = item;
3314
3335
  deferredSize++;
@@ -3354,7 +3375,7 @@ async function generatePlainProperties3(ctx, properties) {
3354
3375
  for (const key of keys) {
3355
3376
  item = properties[key];
3356
3377
  escaped = serializeString(key);
3357
- if (isIterable(item)) {
3378
+ if (isIterable(ctx, item)) {
3358
3379
  deferredKeys[deferredSize] = escaped;
3359
3380
  deferredValues[deferredSize] = item;
3360
3381
  deferredSize++;
@@ -4321,7 +4342,7 @@ function generateNodeList4(ctx, current) {
4321
4342
  for (let i = 0; i < size; i++) {
4322
4343
  if (i in current) {
4323
4344
  item = current[i];
4324
- if (isIterable(item)) {
4345
+ if (isIterable(ctx, item)) {
4325
4346
  deferred[i] = item;
4326
4347
  } else {
4327
4348
  nodes[i] = crossParseStream(ctx, item);
@@ -4360,7 +4381,7 @@ function generateMapNode4(ctx, id, current) {
4360
4381
  let deferredSize = 0;
4361
4382
  let nodeSize = 0;
4362
4383
  for (const [key, value] of current.entries()) {
4363
- if (isIterable(key) || isIterable(value)) {
4384
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
4364
4385
  deferredKey[deferredSize] = key;
4365
4386
  deferredValue[deferredSize] = value;
4366
4387
  deferredSize++;
@@ -4396,7 +4417,7 @@ function generateSetNode4(ctx, id, current) {
4396
4417
  let deferredSize = 0;
4397
4418
  let nodeSize = 0;
4398
4419
  for (const item of current.keys()) {
4399
- if (isIterable(item)) {
4420
+ if (isIterable(ctx, item)) {
4400
4421
  deferred[deferredSize++] = item;
4401
4422
  } else {
4402
4423
  nodes[nodeSize++] = crossParseStream(ctx, item);
@@ -4434,7 +4455,7 @@ function generateProperties4(ctx, properties) {
4434
4455
  for (const key of keys) {
4435
4456
  item = properties[key];
4436
4457
  escaped = serializeString(key);
4437
- if (isIterable(item)) {
4458
+ if (isIterable(ctx, item)) {
4438
4459
  deferredKeys[deferredSize] = escaped;
4439
4460
  deferredValues[deferredSize] = item;
4440
4461
  deferredSize++;
@@ -4480,7 +4501,7 @@ function generatePlainProperties4(ctx, properties) {
4480
4501
  for (const key of keys) {
4481
4502
  item = properties[key];
4482
4503
  escaped = serializeString(key);
4483
- if (isIterable(item)) {
4504
+ if (isIterable(ctx, item)) {
4484
4505
  deferredKeys[deferredSize] = escaped;
4485
4506
  deferredValues[deferredSize] = item;
4486
4507
  deferredSize++;
@@ -4665,52 +4686,13 @@ function generateBoxedNode4(ctx, id, current) {
4665
4686
  o: void 0
4666
4687
  };
4667
4688
  }
4668
- function generateReadableStreamNode(ctx, id, current) {
4669
- const reader = current.getReader();
4670
- pushPendingState(ctx);
4671
- function push() {
4672
- reader.read().then(
4673
- (data) => {
4674
- if (ctx.alive) {
4675
- if (data.done) {
4676
- ctx.onParse({
4677
- t: 33 /* ReadableStreamClose */,
4678
- i: id,
4679
- s: void 0,
4680
- l: void 0,
4681
- c: void 0,
4682
- m: void 0,
4683
- p: void 0,
4684
- e: void 0,
4685
- a: void 0,
4686
- f: void 0,
4687
- b: void 0,
4688
- o: void 0
4689
- }, false);
4690
- popPendingState(ctx);
4691
- } else {
4692
- ctx.onParse({
4693
- t: 32 /* ReadableStreamEnqueue */,
4694
- i: id,
4695
- s: void 0,
4696
- l: void 0,
4697
- c: void 0,
4698
- m: void 0,
4699
- p: void 0,
4700
- e: void 0,
4701
- a: void 0,
4702
- f: crossParseStream(ctx, data.value),
4703
- b: void 0,
4704
- o: void 0
4705
- }, false);
4706
- push();
4707
- }
4708
- }
4709
- },
4710
- (value) => {
4711
- if (ctx.alive) {
4689
+ function pushReadableStreamState(ctx, id, reader) {
4690
+ reader.read().then(
4691
+ (data) => {
4692
+ if (ctx.alive) {
4693
+ if (data.done) {
4712
4694
  ctx.onParse({
4713
- t: 34 /* ReadableStreamError */,
4695
+ t: 33 /* ReadableStreamClose */,
4714
4696
  i: id,
4715
4697
  s: void 0,
4716
4698
  l: void 0,
@@ -4719,16 +4701,54 @@ function generateReadableStreamNode(ctx, id, current) {
4719
4701
  p: void 0,
4720
4702
  e: void 0,
4721
4703
  a: void 0,
4722
- f: crossParseStream(ctx, value),
4704
+ f: void 0,
4723
4705
  b: void 0,
4724
4706
  o: void 0
4725
4707
  }, false);
4726
4708
  popPendingState(ctx);
4709
+ } else {
4710
+ ctx.onParse({
4711
+ t: 32 /* ReadableStreamEnqueue */,
4712
+ i: id,
4713
+ s: void 0,
4714
+ l: void 0,
4715
+ c: void 0,
4716
+ m: void 0,
4717
+ p: void 0,
4718
+ e: void 0,
4719
+ a: void 0,
4720
+ f: crossParseStream(ctx, data.value),
4721
+ b: void 0,
4722
+ o: void 0
4723
+ }, false);
4724
+ pushReadableStreamState(ctx, id, reader);
4727
4725
  }
4728
4726
  }
4729
- );
4730
- }
4731
- push();
4727
+ },
4728
+ (value) => {
4729
+ if (ctx.alive) {
4730
+ ctx.onParse({
4731
+ t: 34 /* ReadableStreamError */,
4732
+ i: id,
4733
+ s: void 0,
4734
+ l: void 0,
4735
+ c: void 0,
4736
+ m: void 0,
4737
+ p: void 0,
4738
+ e: void 0,
4739
+ a: void 0,
4740
+ f: crossParseStream(ctx, value),
4741
+ b: void 0,
4742
+ o: void 0
4743
+ }, false);
4744
+ popPendingState(ctx);
4745
+ }
4746
+ }
4747
+ );
4748
+ }
4749
+ function generateReadableStreamNode(ctx, id, current) {
4750
+ pushPendingState(ctx);
4751
+ pushReadableStreamState(ctx, id, current.getReader());
4732
4752
  return {
4733
4753
  t: 31 /* ReadableStreamConstructor */,
4734
4754
  i: id,
@@ -4977,7 +4997,7 @@ function generateNodeList5(ctx, current) {
4977
4997
  for (let i = 0; i < size; i++) {
4978
4998
  if (i in current) {
4979
4999
  item = current[i];
4980
- if (isIterable(item)) {
5000
+ if (isIterable(ctx, item)) {
4981
5001
  deferred[i] = item;
4982
5002
  } else {
4983
5003
  nodes[i] = crossParseSync(ctx, item);
@@ -5016,7 +5036,7 @@ function generateMapNode5(ctx, id, current) {
5016
5036
  let deferredSize = 0;
5017
5037
  let nodeSize = 0;
5018
5038
  for (const [key, value] of current.entries()) {
5019
- if (isIterable(key) || isIterable(value)) {
5039
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
5020
5040
  deferredKey[deferredSize] = key;
5021
5041
  deferredValue[deferredSize] = value;
5022
5042
  deferredSize++;
@@ -5052,7 +5072,7 @@ function generateSetNode5(ctx, id, current) {
5052
5072
  let deferredSize = 0;
5053
5073
  let nodeSize = 0;
5054
5074
  for (const item of current.keys()) {
5055
- if (isIterable(item)) {
5075
+ if (isIterable(ctx, item)) {
5056
5076
  deferred[deferredSize++] = item;
5057
5077
  } else {
5058
5078
  nodes[nodeSize++] = crossParseSync(ctx, item);
@@ -5090,7 +5110,7 @@ function generateProperties5(ctx, properties) {
5090
5110
  for (const key of keys) {
5091
5111
  item = properties[key];
5092
5112
  escaped = serializeString(key);
5093
- if (isIterable(item)) {
5113
+ if (isIterable(ctx, item)) {
5094
5114
  deferredKeys[deferredSize] = escaped;
5095
5115
  deferredValues[deferredSize] = item;
5096
5116
  deferredSize++;
@@ -5132,7 +5152,7 @@ function generatePlainProperties5(ctx, properties) {
5132
5152
  for (const key of keys) {
5133
5153
  item = properties[key];
5134
5154
  escaped = serializeString(key);
5135
- if (isIterable(item)) {
5155
+ if (isIterable(ctx, item)) {
5136
5156
  deferredKeys[deferredSize] = escaped;
5137
5157
  deferredValues[deferredSize] = item;
5138
5158
  deferredSize++;