seroval 1.5.2 → 1.5.4
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.
- package/dist/cjs/development/index.cjs +27 -5
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +27 -5
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/context/deserializer.d.ts +4 -1
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/context/deserializer.ts +40 -7
|
@@ -1968,10 +1968,16 @@ function applyObjectFlag(obj, flag) {
|
|
|
1968
1968
|
var DEFAULT_DEPTH_LIMIT = 1e3;
|
|
1969
1969
|
function createBaseDeserializerContext(mode, options) {
|
|
1970
1970
|
var _a;
|
|
1971
|
+
const refs = options.refs || /* @__PURE__ */ new Map();
|
|
1972
|
+
if (!("types" in refs)) {
|
|
1973
|
+
Object.assign(refs, {
|
|
1974
|
+
types: /* @__PURE__ */ new Map()
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1971
1977
|
return {
|
|
1972
1978
|
mode,
|
|
1973
1979
|
plugins: options.plugins,
|
|
1974
|
-
refs
|
|
1980
|
+
refs,
|
|
1975
1981
|
features: (_a = options.features) != null ? _a : ALL_ENABLED ^ (options.disabledFeatures || 0),
|
|
1976
1982
|
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT
|
|
1977
1983
|
};
|
|
@@ -2118,6 +2124,14 @@ function assignProperty(ctx, depth, object, key, value) {
|
|
|
2118
2124
|
}
|
|
2119
2125
|
}
|
|
2120
2126
|
}
|
|
2127
|
+
function assignNodeType(ctx, id, type) {
|
|
2128
|
+
ctx.base.refs.types.set(id, type);
|
|
2129
|
+
}
|
|
2130
|
+
function validateNodeType(ctx, node, id, type) {
|
|
2131
|
+
if (ctx.base.refs.types.get(id) !== type) {
|
|
2132
|
+
throw new SerovalMalformedNodeError(node);
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2121
2135
|
function deserializeProperties(ctx, depth, node, result) {
|
|
2122
2136
|
const keys = node.k;
|
|
2123
2137
|
const len = keys.length;
|
|
@@ -2271,15 +2285,18 @@ function deserializePlugin(ctx, depth, node) {
|
|
|
2271
2285
|
throw new SerovalMissingPluginError(node.c);
|
|
2272
2286
|
}
|
|
2273
2287
|
function deserializePromiseConstructor(ctx, node) {
|
|
2274
|
-
|
|
2288
|
+
const value = assignIndexedValue(
|
|
2275
2289
|
ctx,
|
|
2276
2290
|
node.i,
|
|
2277
2291
|
assignIndexedValue(ctx, node.s, PROMISE_CONSTRUCTOR()).p
|
|
2278
2292
|
);
|
|
2293
|
+
assignNodeType(ctx, node.s, 22 /* PromiseConstructor */);
|
|
2294
|
+
return value;
|
|
2279
2295
|
}
|
|
2280
2296
|
function deserializePromiseResolve(ctx, depth, node) {
|
|
2281
2297
|
const deferred = ctx.base.refs.get(node.i);
|
|
2282
2298
|
if (deferred) {
|
|
2299
|
+
validateNodeType(ctx, node, node.i, 22 /* PromiseConstructor */);
|
|
2283
2300
|
deferred.s(deserialize(ctx, depth, node.a[1]));
|
|
2284
2301
|
return NIL;
|
|
2285
2302
|
}
|
|
@@ -2288,6 +2305,7 @@ function deserializePromiseResolve(ctx, depth, node) {
|
|
|
2288
2305
|
function deserializePromiseReject(ctx, depth, node) {
|
|
2289
2306
|
const deferred = ctx.base.refs.get(node.i);
|
|
2290
2307
|
if (deferred) {
|
|
2308
|
+
validateNodeType(ctx, node, node.i, 22 /* PromiseConstructor */);
|
|
2291
2309
|
deferred.f(deserialize(ctx, depth, node.a[1]));
|
|
2292
2310
|
return NIL;
|
|
2293
2311
|
}
|
|
@@ -2305,6 +2323,7 @@ function deserializeAsyncIteratorFactoryInstance(ctx, depth, node) {
|
|
|
2305
2323
|
}
|
|
2306
2324
|
function deserializeStreamConstructor(ctx, depth, node) {
|
|
2307
2325
|
const result = assignIndexedValue(ctx, node.i, createStream());
|
|
2326
|
+
assignNodeType(ctx, node.i, 31 /* StreamConstructor */);
|
|
2308
2327
|
const items = node.a;
|
|
2309
2328
|
const len = items.length;
|
|
2310
2329
|
if (len) {
|
|
@@ -2316,7 +2335,8 @@ function deserializeStreamConstructor(ctx, depth, node) {
|
|
|
2316
2335
|
}
|
|
2317
2336
|
function deserializeStreamNext(ctx, depth, node) {
|
|
2318
2337
|
const deferred = ctx.base.refs.get(node.i);
|
|
2319
|
-
if (deferred
|
|
2338
|
+
if (deferred) {
|
|
2339
|
+
validateNodeType(ctx, node, node.i, 31 /* StreamConstructor */);
|
|
2320
2340
|
deferred.next(deserialize(ctx, depth, node.f));
|
|
2321
2341
|
return NIL;
|
|
2322
2342
|
}
|
|
@@ -2324,7 +2344,8 @@ function deserializeStreamNext(ctx, depth, node) {
|
|
|
2324
2344
|
}
|
|
2325
2345
|
function deserializeStreamThrow(ctx, depth, node) {
|
|
2326
2346
|
const deferred = ctx.base.refs.get(node.i);
|
|
2327
|
-
if (deferred
|
|
2347
|
+
if (deferred) {
|
|
2348
|
+
validateNodeType(ctx, node, node.i, 31 /* StreamConstructor */);
|
|
2328
2349
|
deferred.throw(deserialize(ctx, depth, node.f));
|
|
2329
2350
|
return NIL;
|
|
2330
2351
|
}
|
|
@@ -2332,7 +2353,8 @@ function deserializeStreamThrow(ctx, depth, node) {
|
|
|
2332
2353
|
}
|
|
2333
2354
|
function deserializeStreamReturn(ctx, depth, node) {
|
|
2334
2355
|
const deferred = ctx.base.refs.get(node.i);
|
|
2335
|
-
if (deferred
|
|
2356
|
+
if (deferred) {
|
|
2357
|
+
validateNodeType(ctx, node, node.i, 31 /* StreamConstructor */);
|
|
2336
2358
|
deferred.return(deserialize(ctx, depth, node.f));
|
|
2337
2359
|
return NIL;
|
|
2338
2360
|
}
|