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.
@@ -661,32 +661,58 @@ 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
+ }
688
687
  }
689
- return Symbol.iterator in value;
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
+ }
711
+ }
712
+ if (ctx.features & 1024 /* Symbol */) {
713
+ return Symbol.iterator in value;
714
+ }
715
+ return false;
690
716
  }
691
717
  function getTypedArrayConstructor(name) {
692
718
  switch (name) {
@@ -875,7 +901,7 @@ async function generateNodeList(ctx, current) {
875
901
  for (let i = 0; i < size; i++) {
876
902
  if (i in current) {
877
903
  item = current[i];
878
- if (isIterable(item)) {
904
+ if (isIterable(ctx, item)) {
879
905
  deferred[i] = item;
880
906
  } else {
881
907
  nodes[i] = await parseAsync(ctx, item);
@@ -914,7 +940,7 @@ async function generateMapNode(ctx, id, current) {
914
940
  let deferredSize = 0;
915
941
  let nodeSize = 0;
916
942
  for (const [key, value] of current.entries()) {
917
- if (isIterable(key) || isIterable(value)) {
943
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
918
944
  deferredKey[deferredSize] = key;
919
945
  deferredValue[deferredSize] = value;
920
946
  deferredSize++;
@@ -950,7 +976,7 @@ async function generateSetNode(ctx, id, current) {
950
976
  let deferredSize = 0;
951
977
  let nodeSize = 0;
952
978
  for (const item of current.keys()) {
953
- if (isIterable(item)) {
979
+ if (isIterable(ctx, item)) {
954
980
  deferred[deferredSize++] = item;
955
981
  } else {
956
982
  nodes[nodeSize++] = await parseAsync(ctx, item);
@@ -988,7 +1014,7 @@ async function generateProperties(ctx, properties) {
988
1014
  for (const key of keys) {
989
1015
  item = properties[key];
990
1016
  escaped = serializeString(key);
991
- if (isIterable(item)) {
1017
+ if (isIterable(ctx, item)) {
992
1018
  deferredKeys[deferredSize] = escaped;
993
1019
  deferredValues[deferredSize] = item;
994
1020
  deferredSize++;
@@ -1034,7 +1060,7 @@ async function generatePlainProperties(ctx, properties) {
1034
1060
  for (const key of keys) {
1035
1061
  item = properties[key];
1036
1062
  escaped = serializeString(key);
1037
- if (isIterable(item)) {
1063
+ if (isIterable(ctx, item)) {
1038
1064
  deferredKeys[deferredSize] = escaped;
1039
1065
  deferredValues[deferredSize] = item;
1040
1066
  deferredSize++;
@@ -2433,7 +2459,7 @@ function generateNodeList2(ctx, current) {
2433
2459
  for (let i = 0; i < size; i++) {
2434
2460
  if (i in current) {
2435
2461
  item = current[i];
2436
- if (isIterable(item)) {
2462
+ if (isIterable(ctx, item)) {
2437
2463
  deferred[i] = item;
2438
2464
  } else {
2439
2465
  nodes[i] = parseSync(ctx, item);
@@ -2472,7 +2498,7 @@ function generateMapNode2(ctx, id, current) {
2472
2498
  let deferredSize = 0;
2473
2499
  let nodeSize = 0;
2474
2500
  for (const [key, value] of current.entries()) {
2475
- if (isIterable(key) || isIterable(value)) {
2501
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
2476
2502
  deferredKey[deferredSize] = key;
2477
2503
  deferredValue[deferredSize] = value;
2478
2504
  deferredSize++;
@@ -2508,7 +2534,7 @@ function generateSetNode2(ctx, id, current) {
2508
2534
  let deferredSize = 0;
2509
2535
  let nodeSize = 0;
2510
2536
  for (const item of current.keys()) {
2511
- if (isIterable(item)) {
2537
+ if (isIterable(ctx, item)) {
2512
2538
  deferred[deferredSize++] = item;
2513
2539
  } else {
2514
2540
  nodes[nodeSize++] = parseSync(ctx, item);
@@ -2546,7 +2572,7 @@ function generateProperties2(ctx, properties) {
2546
2572
  for (const key of keys) {
2547
2573
  item = properties[key];
2548
2574
  escaped = serializeString(key);
2549
- if (isIterable(item)) {
2575
+ if (isIterable(ctx, item)) {
2550
2576
  deferredKeys[deferredSize] = escaped;
2551
2577
  deferredValues[deferredSize] = item;
2552
2578
  deferredSize++;
@@ -2589,7 +2615,7 @@ function generatePlainProperties2(ctx, properties) {
2589
2615
  for (const key of keys) {
2590
2616
  item = properties[key];
2591
2617
  escaped = serializeString(key);
2592
- if (isIterable(item)) {
2618
+ if (isIterable(ctx, item)) {
2593
2619
  deferredKeys[deferredSize] = escaped;
2594
2620
  deferredValues[deferredSize] = item;
2595
2621
  deferredSize++;
@@ -3053,12 +3079,7 @@ function createTypedArrayNode2(ctx, id, current) {
3053
3079
  o: void 0
3054
3080
  };
3055
3081
  }
3056
- var BIGINT_FLAG2 = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
3057
3082
  function createBigIntTypedArrayNode2(ctx, id, current) {
3058
- assert(
3059
- (ctx.features & BIGINT_FLAG2) === BIGINT_FLAG2,
3060
- new UnsupportedTypeError(current)
3061
- );
3062
3083
  return {
3063
3084
  t: 16 /* BigIntTypedArray */,
3064
3085
  i: id,
@@ -3156,7 +3177,7 @@ async function generateNodeList3(ctx, current) {
3156
3177
  for (let i = 0; i < size; i++) {
3157
3178
  if (i in current) {
3158
3179
  item = current[i];
3159
- if (isIterable(item)) {
3180
+ if (isIterable(ctx, item)) {
3160
3181
  deferred[i] = item;
3161
3182
  } else {
3162
3183
  nodes[i] = await crossParseAsync(ctx, item);
@@ -3195,7 +3216,7 @@ async function generateMapNode3(ctx, id, current) {
3195
3216
  let deferredSize = 0;
3196
3217
  let nodeSize = 0;
3197
3218
  for (const [key, value] of current.entries()) {
3198
- if (isIterable(key) || isIterable(value)) {
3219
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
3199
3220
  deferredKey[deferredSize] = key;
3200
3221
  deferredValue[deferredSize] = value;
3201
3222
  deferredSize++;
@@ -3231,7 +3252,7 @@ async function generateSetNode3(ctx, id, current) {
3231
3252
  let deferredSize = 0;
3232
3253
  let nodeSize = 0;
3233
3254
  for (const item of current.keys()) {
3234
- if (isIterable(item)) {
3255
+ if (isIterable(ctx, item)) {
3235
3256
  deferred[deferredSize++] = item;
3236
3257
  } else {
3237
3258
  nodes[nodeSize++] = await crossParseAsync(ctx, item);
@@ -3269,7 +3290,7 @@ async function generateProperties3(ctx, properties) {
3269
3290
  for (const key of keys) {
3270
3291
  item = properties[key];
3271
3292
  escaped = serializeString(key);
3272
- if (isIterable(item)) {
3293
+ if (isIterable(ctx, item)) {
3273
3294
  deferredKeys[deferredSize] = escaped;
3274
3295
  deferredValues[deferredSize] = item;
3275
3296
  deferredSize++;
@@ -3315,7 +3336,7 @@ async function generatePlainProperties3(ctx, properties) {
3315
3336
  for (const key of keys) {
3316
3337
  item = properties[key];
3317
3338
  escaped = serializeString(key);
3318
- if (isIterable(item)) {
3339
+ if (isIterable(ctx, item)) {
3319
3340
  deferredKeys[deferredSize] = escaped;
3320
3341
  deferredValues[deferredSize] = item;
3321
3342
  deferredSize++;
@@ -4282,7 +4303,7 @@ function generateNodeList4(ctx, current) {
4282
4303
  for (let i = 0; i < size; i++) {
4283
4304
  if (i in current) {
4284
4305
  item = current[i];
4285
- if (isIterable(item)) {
4306
+ if (isIterable(ctx, item)) {
4286
4307
  deferred[i] = item;
4287
4308
  } else {
4288
4309
  nodes[i] = crossParseStream(ctx, item);
@@ -4321,7 +4342,7 @@ function generateMapNode4(ctx, id, current) {
4321
4342
  let deferredSize = 0;
4322
4343
  let nodeSize = 0;
4323
4344
  for (const [key, value] of current.entries()) {
4324
- if (isIterable(key) || isIterable(value)) {
4345
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
4325
4346
  deferredKey[deferredSize] = key;
4326
4347
  deferredValue[deferredSize] = value;
4327
4348
  deferredSize++;
@@ -4357,7 +4378,7 @@ function generateSetNode4(ctx, id, current) {
4357
4378
  let deferredSize = 0;
4358
4379
  let nodeSize = 0;
4359
4380
  for (const item of current.keys()) {
4360
- if (isIterable(item)) {
4381
+ if (isIterable(ctx, item)) {
4361
4382
  deferred[deferredSize++] = item;
4362
4383
  } else {
4363
4384
  nodes[nodeSize++] = crossParseStream(ctx, item);
@@ -4395,7 +4416,7 @@ function generateProperties4(ctx, properties) {
4395
4416
  for (const key of keys) {
4396
4417
  item = properties[key];
4397
4418
  escaped = serializeString(key);
4398
- if (isIterable(item)) {
4419
+ if (isIterable(ctx, item)) {
4399
4420
  deferredKeys[deferredSize] = escaped;
4400
4421
  deferredValues[deferredSize] = item;
4401
4422
  deferredSize++;
@@ -4441,7 +4462,7 @@ function generatePlainProperties4(ctx, properties) {
4441
4462
  for (const key of keys) {
4442
4463
  item = properties[key];
4443
4464
  escaped = serializeString(key);
4444
- if (isIterable(item)) {
4465
+ if (isIterable(ctx, item)) {
4445
4466
  deferredKeys[deferredSize] = escaped;
4446
4467
  deferredValues[deferredSize] = item;
4447
4468
  deferredSize++;
@@ -4626,52 +4647,13 @@ function generateBoxedNode4(ctx, id, current) {
4626
4647
  o: void 0
4627
4648
  };
4628
4649
  }
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) {
4650
+ function pushReadableStreamState(ctx, id, reader) {
4651
+ reader.read().then(
4652
+ (data) => {
4653
+ if (ctx.alive) {
4654
+ if (data.done) {
4673
4655
  ctx.onParse({
4674
- t: 34 /* ReadableStreamError */,
4656
+ t: 33 /* ReadableStreamClose */,
4675
4657
  i: id,
4676
4658
  s: void 0,
4677
4659
  l: void 0,
@@ -4680,16 +4662,54 @@ function generateReadableStreamNode(ctx, id, current) {
4680
4662
  p: void 0,
4681
4663
  e: void 0,
4682
4664
  a: void 0,
4683
- f: crossParseStream(ctx, value),
4665
+ f: void 0,
4684
4666
  b: void 0,
4685
4667
  o: void 0
4686
4668
  }, false);
4687
4669
  popPendingState(ctx);
4670
+ } else {
4671
+ ctx.onParse({
4672
+ t: 32 /* ReadableStreamEnqueue */,
4673
+ i: id,
4674
+ s: void 0,
4675
+ l: void 0,
4676
+ c: void 0,
4677
+ m: void 0,
4678
+ p: void 0,
4679
+ e: void 0,
4680
+ a: void 0,
4681
+ f: crossParseStream(ctx, data.value),
4682
+ b: void 0,
4683
+ o: void 0
4684
+ }, false);
4685
+ pushReadableStreamState(ctx, id, reader);
4688
4686
  }
4689
4687
  }
4690
- );
4691
- }
4692
- push();
4688
+ },
4689
+ (value) => {
4690
+ if (ctx.alive) {
4691
+ ctx.onParse({
4692
+ t: 34 /* ReadableStreamError */,
4693
+ i: id,
4694
+ s: void 0,
4695
+ l: void 0,
4696
+ c: void 0,
4697
+ m: void 0,
4698
+ p: void 0,
4699
+ e: void 0,
4700
+ a: void 0,
4701
+ f: crossParseStream(ctx, value),
4702
+ b: void 0,
4703
+ o: void 0
4704
+ }, false);
4705
+ popPendingState(ctx);
4706
+ }
4707
+ }
4708
+ );
4709
+ }
4710
+ function generateReadableStreamNode(ctx, id, current) {
4711
+ pushPendingState(ctx);
4712
+ pushReadableStreamState(ctx, id, current.getReader());
4693
4713
  return {
4694
4714
  t: 31 /* ReadableStreamConstructor */,
4695
4715
  i: id,
@@ -4938,7 +4958,7 @@ function generateNodeList5(ctx, current) {
4938
4958
  for (let i = 0; i < size; i++) {
4939
4959
  if (i in current) {
4940
4960
  item = current[i];
4941
- if (isIterable(item)) {
4961
+ if (isIterable(ctx, item)) {
4942
4962
  deferred[i] = item;
4943
4963
  } else {
4944
4964
  nodes[i] = crossParseSync(ctx, item);
@@ -4977,7 +4997,7 @@ function generateMapNode5(ctx, id, current) {
4977
4997
  let deferredSize = 0;
4978
4998
  let nodeSize = 0;
4979
4999
  for (const [key, value] of current.entries()) {
4980
- if (isIterable(key) || isIterable(value)) {
5000
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
4981
5001
  deferredKey[deferredSize] = key;
4982
5002
  deferredValue[deferredSize] = value;
4983
5003
  deferredSize++;
@@ -5013,7 +5033,7 @@ function generateSetNode5(ctx, id, current) {
5013
5033
  let deferredSize = 0;
5014
5034
  let nodeSize = 0;
5015
5035
  for (const item of current.keys()) {
5016
- if (isIterable(item)) {
5036
+ if (isIterable(ctx, item)) {
5017
5037
  deferred[deferredSize++] = item;
5018
5038
  } else {
5019
5039
  nodes[nodeSize++] = crossParseSync(ctx, item);
@@ -5051,7 +5071,7 @@ function generateProperties5(ctx, properties) {
5051
5071
  for (const key of keys) {
5052
5072
  item = properties[key];
5053
5073
  escaped = serializeString(key);
5054
- if (isIterable(item)) {
5074
+ if (isIterable(ctx, item)) {
5055
5075
  deferredKeys[deferredSize] = escaped;
5056
5076
  deferredValues[deferredSize] = item;
5057
5077
  deferredSize++;
@@ -5093,7 +5113,7 @@ function generatePlainProperties5(ctx, properties) {
5093
5113
  for (const key of keys) {
5094
5114
  item = properties[key];
5095
5115
  escaped = serializeString(key);
5096
- if (isIterable(item)) {
5116
+ if (isIterable(ctx, item)) {
5097
5117
  deferredKeys[deferredSize] = escaped;
5098
5118
  deferredValues[deferredSize] = item;
5099
5119
  deferredSize++;