seroval 1.5.4 → 1.5.6

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.
@@ -663,7 +663,7 @@ function createBigIntTypedArrayNode(id, current, buffer) {
663
663
  buffer,
664
664
  current.byteOffset,
665
665
  NIL,
666
- current.byteLength
666
+ current.length
667
667
  );
668
668
  }
669
669
  function createDataViewNode(id, current, buffer) {
@@ -1856,6 +1856,9 @@ async function parseFunctionAsync(ctx, depth, current) {
1856
1856
  throw new SerovalUnsupportedTypeError(current);
1857
1857
  }
1858
1858
  async function parseAsync(ctx, depth, current) {
1859
+ if (depth >= ctx.base.depthLimit) {
1860
+ throw new SerovalDepthLimitError(ctx.base.depthLimit);
1861
+ }
1859
1862
  switch (typeof current) {
1860
1863
  case "boolean":
1861
1864
  return current ? TRUE_NODE : FALSE_NODE;
@@ -1949,6 +1952,33 @@ function getTypedArrayConstructor(name) {
1949
1952
  }
1950
1953
  }
1951
1954
 
1955
+ // src/core/utils/valid-properties.ts
1956
+ function isValidKey(key) {
1957
+ switch (key) {
1958
+ case "constructor":
1959
+ case "__proto__":
1960
+ case "prototype":
1961
+ case "__defineGetter__":
1962
+ case "__defineSetter__":
1963
+ case "__lookupGetter__":
1964
+ case "__lookupSetter__":
1965
+ return false;
1966
+ default:
1967
+ return true;
1968
+ }
1969
+ }
1970
+ function isValidSymbol(symbol) {
1971
+ switch (symbol) {
1972
+ case SYM_ASYNC_ITERATOR:
1973
+ case SYM_IS_CONCAT_SPREADABLE:
1974
+ case SYM_TO_STRING_TAG:
1975
+ case SYM_ITERATOR:
1976
+ return true;
1977
+ default:
1978
+ return false;
1979
+ }
1980
+ }
1981
+
1952
1982
  // src/core/context/deserializer.ts
1953
1983
  var MAX_BASE64_LENGTH = 1e6;
1954
1984
  var MAX_BIGINT_LENGTH = 1e4;
@@ -2064,31 +2094,6 @@ function deserializeArray(ctx, depth, node) {
2064
2094
  applyObjectFlag(result, node.o);
2065
2095
  return result;
2066
2096
  }
2067
- function isValidKey(key) {
2068
- switch (key) {
2069
- case "constructor":
2070
- case "__proto__":
2071
- case "prototype":
2072
- case "__defineGetter__":
2073
- case "__defineSetter__":
2074
- case "__lookupGetter__":
2075
- case "__lookupSetter__":
2076
- return false;
2077
- default:
2078
- return true;
2079
- }
2080
- }
2081
- function isValidSymbol(symbol) {
2082
- switch (symbol) {
2083
- case SYM_ASYNC_ITERATOR:
2084
- case SYM_IS_CONCAT_SPREADABLE:
2085
- case SYM_TO_STRING_TAG:
2086
- case SYM_ITERATOR:
2087
- return true;
2088
- default:
2089
- return false;
2090
- }
2091
- }
2092
2097
  function assignStringProperty(object, key, value) {
2093
2098
  if (isValidKey(key)) {
2094
2099
  object[key] = value;
@@ -2454,7 +2459,6 @@ function deserialize(ctx, depth, node) {
2454
2459
  return deserializeIteratorFactory(ctx, depth, node);
2455
2460
  case 29 /* AsyncIteratorFactory */:
2456
2461
  return deserializeAsyncIteratorFactory(ctx, depth, node);
2457
- // case SerovalNodeType.SpecialReference:
2458
2462
  case 35 /* Sequence */:
2459
2463
  return deserializeSequence(ctx, depth, node);
2460
2464
  default:
@@ -2523,6 +2527,8 @@ function getAssignmentExpression(assignment) {
2523
2527
  return assignment.s + ".add(" + assignment.v + ")";
2524
2528
  case 3 /* Delete */:
2525
2529
  return assignment.s + ".delete(" + assignment.k + ")";
2530
+ case 4 /* Define */:
2531
+ return "Object.defineProperty(" + assignment.s + ',"__proto__",{value:' + assignment.k + ",configurable:!0,enumerable:!0,writable:!0})";
2526
2532
  }
2527
2533
  }
2528
2534
  function mergeAssignments(assignments) {
@@ -2719,6 +2725,15 @@ function createArrayAssign(ctx, ref, index, value) {
2719
2725
  createAssignment(ctx.base, getRefParam(ctx, ref) + "[" + index + "]", value);
2720
2726
  }
2721
2727
  function createObjectAssign(ctx, ref, key, value) {
2728
+ if (!isValidKey(key)) {
2729
+ ctx.base.assignments.push({
2730
+ t: 4 /* Define */,
2731
+ s: getRefParam(ctx, ref),
2732
+ k: value,
2733
+ v: NIL
2734
+ });
2735
+ return;
2736
+ }
2722
2737
  createAssignment(ctx.base, getRefParam(ctx, ref) + "." + key, value);
2723
2738
  }
2724
2739
  function createSequenceAssign(ctx, ref, index, value) {
@@ -2805,7 +2820,10 @@ function serializeProperty(ctx, source, key, val) {
2805
2820
  }
2806
2821
  return "";
2807
2822
  }
2808
- return (isIdentifier ? key : '"' + key + '"') + ":" + serialize(ctx, val);
2823
+ if (isValidKey(key)) {
2824
+ return (isIdentifier ? key : '"' + key + '"') + ":" + serialize(ctx, val);
2825
+ }
2826
+ return '["' + key + '"]:' + serialize(ctx, val);
2809
2827
  }
2810
2828
  return "[" + serialize(ctx, key) + "]:" + serialize(ctx, val);
2811
2829
  }
@@ -2933,7 +2951,7 @@ function serializeDate(node) {
2933
2951
  }
2934
2952
  function serializeRegExp(ctx, node) {
2935
2953
  if (ctx.base.features & 32 /* RegExp */) {
2936
- return "/" + node.c + "/" + node.m;
2954
+ return "/" + deserializeString(node.c) + "/" + node.m;
2937
2955
  }
2938
2956
  throw new SerovalUnsupportedNodeError(node);
2939
2957
  }
@@ -3400,6 +3418,9 @@ var StreamParsePluginContext = class {
3400
3418
  onError(error) {
3401
3419
  onError(this._p, error);
3402
3420
  }
3421
+ addCleanup(callback) {
3422
+ this._p.state.cleanups.push(callback);
3423
+ }
3403
3424
  };
3404
3425
  function createStreamParserState(options) {
3405
3426
  return {
@@ -3409,7 +3430,8 @@ function createStreamParserState(options) {
3409
3430
  buffer: [],
3410
3431
  onParse: options.onParse,
3411
3432
  onError: options.onError,
3412
- onDone: options.onDone
3433
+ onDone: options.onDone,
3434
+ cleanups: []
3413
3435
  };
3414
3436
  }
3415
3437
  function createStreamParserContext(options) {
@@ -3893,6 +3915,9 @@ function onDone(ctx) {
3893
3915
  if (ctx.state.onDone) {
3894
3916
  ctx.state.onDone();
3895
3917
  }
3918
+ for (let i = 0, len = ctx.state.cleanups.length; i < len; i++) {
3919
+ ctx.state.cleanups[i]();
3920
+ }
3896
3921
  }
3897
3922
  function onParseInternal(ctx, node, initial) {
3898
3923
  try {