seroval 1.5.3 → 1.5.5

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) {
@@ -1949,6 +1949,33 @@ function getTypedArrayConstructor(name) {
1949
1949
  }
1950
1950
  }
1951
1951
 
1952
+ // src/core/utils/valid-properties.ts
1953
+ function isValidKey(key) {
1954
+ switch (key) {
1955
+ case "constructor":
1956
+ case "__proto__":
1957
+ case "prototype":
1958
+ case "__defineGetter__":
1959
+ case "__defineSetter__":
1960
+ case "__lookupGetter__":
1961
+ case "__lookupSetter__":
1962
+ return false;
1963
+ default:
1964
+ return true;
1965
+ }
1966
+ }
1967
+ function isValidSymbol(symbol) {
1968
+ switch (symbol) {
1969
+ case SYM_ASYNC_ITERATOR:
1970
+ case SYM_IS_CONCAT_SPREADABLE:
1971
+ case SYM_TO_STRING_TAG:
1972
+ case SYM_ITERATOR:
1973
+ return true;
1974
+ default:
1975
+ return false;
1976
+ }
1977
+ }
1978
+
1952
1979
  // src/core/context/deserializer.ts
1953
1980
  var MAX_BASE64_LENGTH = 1e6;
1954
1981
  var MAX_BIGINT_LENGTH = 1e4;
@@ -1968,13 +1995,18 @@ function applyObjectFlag(obj, flag) {
1968
1995
  var DEFAULT_DEPTH_LIMIT = 1e3;
1969
1996
  function createBaseDeserializerContext(mode, options) {
1970
1997
  var _a;
1998
+ const refs = options.refs || /* @__PURE__ */ new Map();
1999
+ if (!("types" in refs)) {
2000
+ Object.assign(refs, {
2001
+ types: /* @__PURE__ */ new Map()
2002
+ });
2003
+ }
1971
2004
  return {
1972
2005
  mode,
1973
2006
  plugins: options.plugins,
1974
- refs: options.refs || /* @__PURE__ */ new Map(),
2007
+ refs,
1975
2008
  features: (_a = options.features) != null ? _a : ALL_ENABLED ^ (options.disabledFeatures || 0),
1976
- depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
1977
- types: /* @__PURE__ */ new Map()
2009
+ depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT
1978
2010
  };
1979
2011
  }
1980
2012
  function createVanillaDeserializerContext(options) {
@@ -2059,31 +2091,6 @@ function deserializeArray(ctx, depth, node) {
2059
2091
  applyObjectFlag(result, node.o);
2060
2092
  return result;
2061
2093
  }
2062
- function isValidKey(key) {
2063
- switch (key) {
2064
- case "constructor":
2065
- case "__proto__":
2066
- case "prototype":
2067
- case "__defineGetter__":
2068
- case "__defineSetter__":
2069
- case "__lookupGetter__":
2070
- case "__lookupSetter__":
2071
- return false;
2072
- default:
2073
- return true;
2074
- }
2075
- }
2076
- function isValidSymbol(symbol) {
2077
- switch (symbol) {
2078
- case SYM_ASYNC_ITERATOR:
2079
- case SYM_IS_CONCAT_SPREADABLE:
2080
- case SYM_TO_STRING_TAG:
2081
- case SYM_ITERATOR:
2082
- return true;
2083
- default:
2084
- return false;
2085
- }
2086
- }
2087
2094
  function assignStringProperty(object, key, value) {
2088
2095
  if (isValidKey(key)) {
2089
2096
  object[key] = value;
@@ -2120,10 +2127,10 @@ function assignProperty(ctx, depth, object, key, value) {
2120
2127
  }
2121
2128
  }
2122
2129
  function assignNodeType(ctx, id, type) {
2123
- ctx.base.types.set(id, type);
2130
+ ctx.base.refs.types.set(id, type);
2124
2131
  }
2125
2132
  function validateNodeType(ctx, node, id, type) {
2126
- if (ctx.base.types.get(id) !== type) {
2133
+ if (ctx.base.refs.types.get(id) !== type) {
2127
2134
  throw new SerovalMalformedNodeError(node);
2128
2135
  }
2129
2136
  }
@@ -2280,12 +2287,13 @@ function deserializePlugin(ctx, depth, node) {
2280
2287
  throw new SerovalMissingPluginError(node.c);
2281
2288
  }
2282
2289
  function deserializePromiseConstructor(ctx, node) {
2283
- assignNodeType(ctx, node.s, 22 /* PromiseConstructor */);
2284
- return assignIndexedValue(
2290
+ const value = assignIndexedValue(
2285
2291
  ctx,
2286
2292
  node.i,
2287
2293
  assignIndexedValue(ctx, node.s, PROMISE_CONSTRUCTOR()).p
2288
2294
  );
2295
+ assignNodeType(ctx, node.s, 22 /* PromiseConstructor */);
2296
+ return value;
2289
2297
  }
2290
2298
  function deserializePromiseResolve(ctx, depth, node) {
2291
2299
  const deferred = ctx.base.refs.get(node.i);
@@ -2316,8 +2324,8 @@ function deserializeAsyncIteratorFactoryInstance(ctx, depth, node) {
2316
2324
  return streamToAsyncIterable(source);
2317
2325
  }
2318
2326
  function deserializeStreamConstructor(ctx, depth, node) {
2319
- assignNodeType(ctx, node.i, 31 /* StreamConstructor */);
2320
2327
  const result = assignIndexedValue(ctx, node.i, createStream());
2328
+ assignNodeType(ctx, node.i, 31 /* StreamConstructor */);
2321
2329
  const items = node.a;
2322
2330
  const len = items.length;
2323
2331
  if (len) {
@@ -2517,6 +2525,8 @@ function getAssignmentExpression(assignment) {
2517
2525
  return assignment.s + ".add(" + assignment.v + ")";
2518
2526
  case 3 /* Delete */:
2519
2527
  return assignment.s + ".delete(" + assignment.k + ")";
2528
+ case 4 /* Define */:
2529
+ return "Object.defineProperty(" + assignment.s + ',"__proto__",{value:' + assignment.k + ",configurable:!0,enumerable:!0,writable:!0})";
2520
2530
  }
2521
2531
  }
2522
2532
  function mergeAssignments(assignments) {
@@ -2713,6 +2723,15 @@ function createArrayAssign(ctx, ref, index, value) {
2713
2723
  createAssignment(ctx.base, getRefParam(ctx, ref) + "[" + index + "]", value);
2714
2724
  }
2715
2725
  function createObjectAssign(ctx, ref, key, value) {
2726
+ if (!isValidKey(key)) {
2727
+ ctx.base.assignments.push({
2728
+ t: 4 /* Define */,
2729
+ s: getRefParam(ctx, ref),
2730
+ k: value,
2731
+ v: NIL
2732
+ });
2733
+ return;
2734
+ }
2716
2735
  createAssignment(ctx.base, getRefParam(ctx, ref) + "." + key, value);
2717
2736
  }
2718
2737
  function createSequenceAssign(ctx, ref, index, value) {
@@ -2799,7 +2818,10 @@ function serializeProperty(ctx, source, key, val) {
2799
2818
  }
2800
2819
  return "";
2801
2820
  }
2802
- return (isIdentifier ? key : '"' + key + '"') + ":" + serialize(ctx, val);
2821
+ if (isValidKey(key)) {
2822
+ return (isIdentifier ? key : '"' + key + '"') + ":" + serialize(ctx, val);
2823
+ }
2824
+ return '["' + key + '"]:' + serialize(ctx, val);
2803
2825
  }
2804
2826
  return "[" + serialize(ctx, key) + "]:" + serialize(ctx, val);
2805
2827
  }
@@ -2927,7 +2949,7 @@ function serializeDate(node) {
2927
2949
  }
2928
2950
  function serializeRegExp(ctx, node) {
2929
2951
  if (ctx.base.features & 32 /* RegExp */) {
2930
- return "/" + node.c + "/" + node.m;
2952
+ return "/" + deserializeString(node.c) + "/" + node.m;
2931
2953
  }
2932
2954
  throw new SerovalUnsupportedNodeError(node);
2933
2955
  }
@@ -3394,6 +3416,9 @@ var StreamParsePluginContext = class {
3394
3416
  onError(error) {
3395
3417
  onError(this._p, error);
3396
3418
  }
3419
+ addCleanup(callback) {
3420
+ this._p.state.cleanups.push(callback);
3421
+ }
3397
3422
  };
3398
3423
  function createStreamParserState(options) {
3399
3424
  return {
@@ -3403,7 +3428,8 @@ function createStreamParserState(options) {
3403
3428
  buffer: [],
3404
3429
  onParse: options.onParse,
3405
3430
  onError: options.onError,
3406
- onDone: options.onDone
3431
+ onDone: options.onDone,
3432
+ cleanups: []
3407
3433
  };
3408
3434
  }
3409
3435
  function createStreamParserContext(options) {
@@ -3887,6 +3913,9 @@ function onDone(ctx) {
3887
3913
  if (ctx.state.onDone) {
3888
3914
  ctx.state.onDone();
3889
3915
  }
3916
+ for (let i = 0, len = ctx.state.cleanups.length; i < len; i++) {
3917
+ ctx.state.cleanups[i]();
3918
+ }
3890
3919
  }
3891
3920
  function onParseInternal(ctx, node, initial) {
3892
3921
  try {