mol_vary 0.0.37 → 0.0.39

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/node.mjs CHANGED
@@ -2347,6 +2347,7 @@ var $;
2347
2347
  let pos = 0;
2348
2348
  let capacity = 9;
2349
2349
  const offsets = new Map();
2350
+ const stack = [];
2350
2351
  const acquire = (size) => {
2351
2352
  if (size < 0)
2352
2353
  return;
@@ -2508,8 +2509,14 @@ var $;
2508
2509
  return dump_unum($mol_vary_tip.link, offset);
2509
2510
  dump_unum($mol_vary_tip.list, val.length);
2510
2511
  acquire(val.length * 9);
2512
+ if (stack.includes(val))
2513
+ $mol_fail(new Error('Cyclic refs', { cause: { stack, val } }));
2514
+ stack.push(val);
2511
2515
  for (const item of val)
2512
2516
  dump(item);
2517
+ if (stack.at(-1) !== val)
2518
+ $mol_fail(new Error('Broken stack', { cause: { stack, val } }));
2519
+ stack.pop();
2513
2520
  offsets.set(val, offsets.size);
2514
2521
  };
2515
2522
  const shapes = new Map();
@@ -2530,8 +2537,14 @@ var $;
2530
2537
  dump_unum($mol_vary_tip.tupl, vals.length);
2531
2538
  acquire((vals.length + 1) * 9);
2532
2539
  dump_list(keys);
2540
+ if (stack.includes(val))
2541
+ $mol_fail(new Error('Cyclic refs', { cause: { stack, val } }));
2542
+ stack.push(val);
2533
2543
  for (const item of vals)
2534
2544
  dump(item);
2545
+ if (stack.at(-1) !== val)
2546
+ $mol_fail(new Error('Broken stack', { cause: { stack, val } }));
2547
+ stack.pop();
2535
2548
  offsets.set(val, offsets.size);
2536
2549
  };
2537
2550
  const dump = (val) => {
package/node.test.js CHANGED
@@ -2338,6 +2338,7 @@ var $;
2338
2338
  let pos = 0;
2339
2339
  let capacity = 9;
2340
2340
  const offsets = new Map();
2341
+ const stack = [];
2341
2342
  const acquire = (size) => {
2342
2343
  if (size < 0)
2343
2344
  return;
@@ -2499,8 +2500,14 @@ var $;
2499
2500
  return dump_unum($mol_vary_tip.link, offset);
2500
2501
  dump_unum($mol_vary_tip.list, val.length);
2501
2502
  acquire(val.length * 9);
2503
+ if (stack.includes(val))
2504
+ $mol_fail(new Error('Cyclic refs', { cause: { stack, val } }));
2505
+ stack.push(val);
2502
2506
  for (const item of val)
2503
2507
  dump(item);
2508
+ if (stack.at(-1) !== val)
2509
+ $mol_fail(new Error('Broken stack', { cause: { stack, val } }));
2510
+ stack.pop();
2504
2511
  offsets.set(val, offsets.size);
2505
2512
  };
2506
2513
  const shapes = new Map();
@@ -2521,8 +2528,14 @@ var $;
2521
2528
  dump_unum($mol_vary_tip.tupl, vals.length);
2522
2529
  acquire((vals.length + 1) * 9);
2523
2530
  dump_list(keys);
2531
+ if (stack.includes(val))
2532
+ $mol_fail(new Error('Cyclic refs', { cause: { stack, val } }));
2533
+ stack.push(val);
2524
2534
  for (const item of vals)
2525
2535
  dump(item);
2536
+ if (stack.at(-1) !== val)
2537
+ $mol_fail(new Error('Broken stack', { cause: { stack, val } }));
2538
+ stack.pop();
2526
2539
  offsets.set(val, offsets.size);
2527
2540
  };
2528
2541
  const dump = (val) => {
@@ -4939,6 +4952,11 @@ var $;
4939
4952
  const box = [seven];
4940
4953
  check([box, box, seven], [list | 3, list | 1, list | 1, 7, link | 1, link | 0]);
4941
4954
  },
4955
+ "vary pack cyclic list"($) {
4956
+ const foo = [];
4957
+ foo.push([foo]);
4958
+ $mol_assert_fail(() => $mol_vary.pack(foo), 'Cyclic refs');
4959
+ },
4942
4960
  "vary pack dedup uint"($) {
4943
4961
  check([28, 28], [list | 2, uint | L1, 28, link | 0]);
4944
4962
  check([2n ** 64n, 2n ** 64n], [list | 2, sint | -LA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, link | 0]);
@@ -4982,6 +5000,11 @@ var $;
4982
5000
  const part = { x: 1, y: 2 };
4983
5001
  check({ x: part, y: part }, [tupl | 2, list | 2, text | 1, ...str('x'), text | 1, ...str('y'), tupl | 2, link | 2, 1, 2, link | 3]);
4984
5002
  },
5003
+ "vary pack cyclic struct"($) {
5004
+ const foo = { bar: null };
5005
+ foo.bar = foo;
5006
+ $mol_assert_fail(() => $mol_vary.pack(foo), 'Cyclic refs');
5007
+ },
4985
5008
  "vary pack Map"($) {
4986
5009
  check(new Map([['foo', 1], [2, 'bar']]), [tupl | 2, list | 2, text | 4, ...str('keys'), text | 4, ...str('vals'), list | 2, text | 3, ...str('foo'), 2, list | 2, 1, text | 3, ...str('bar')]);
4987
5010
  },