mol_vary 0.0.36 → 0.0.38

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) => {
@@ -2794,6 +2807,8 @@ var $;
2794
2807
  }
2795
2808
  return el;
2796
2809
  });
2810
+ $mol_vary.type($mol_dom.Comment, ['#comment'], node => [node.nodeValue], text => $mol_dom.document.createComment(text));
2811
+ $mol_vary.type($mol_dom.ProcessingInstruction, ['target', 'text'], node => [node.nodeName, node.nodeValue], (target, text) => $mol_dom.document.createProcessingInstruction(target, text));
2797
2812
  })($ || ($ = {}));
2798
2813
 
2799
2814
 
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) => {
@@ -2785,6 +2798,8 @@ var $;
2785
2798
  }
2786
2799
  return el;
2787
2800
  });
2801
+ $mol_vary.type($mol_dom.Comment, ['#comment'], node => [node.nodeValue], text => $mol_dom.document.createComment(text));
2802
+ $mol_vary.type($mol_dom.ProcessingInstruction, ['target', 'text'], node => [node.nodeName, node.nodeValue], (target, text) => $mol_dom.document.createProcessingInstruction(target, text));
2788
2803
  })($ || ($ = {}));
2789
2804
 
2790
2805
  ;
@@ -4937,6 +4952,11 @@ var $;
4937
4952
  const box = [seven];
4938
4953
  check([box, box, seven], [list | 3, list | 1, list | 1, 7, link | 1, link | 0]);
4939
4954
  },
4955
+ "vary pack cyclic list"($) {
4956
+ const foo = [];
4957
+ foo.push([foo]);
4958
+ $mol_assert_fail(() => $mol_vary.pack(foo), 'Cyclic refs');
4959
+ },
4940
4960
  "vary pack dedup uint"($) {
4941
4961
  check([28, 28], [list | 2, uint | L1, 28, link | 0]);
4942
4962
  check([2n ** 64n, 2n ** 64n], [list | 2, sint | -LA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, link | 0]);
@@ -4980,6 +5000,11 @@ var $;
4980
5000
  const part = { x: 1, y: 2 };
4981
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]);
4982
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
+ },
4983
5008
  "vary pack Map"($) {
4984
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')]);
4985
5010
  },
@@ -4992,15 +5017,11 @@ var $;
4992
5017
  const date2 = new Date('2025-01-02T03:04:05.678');
4993
5018
  check(date2, [tupl | 1, list | 1, text | 9, ...str('unix_time'), fp64, ...new Uint8Array(new Float64Array([date2.valueOf() / 1000]).buffer)]);
4994
5019
  },
4995
- "vary pack Node"($) {
5020
+ "vary pack DOM Node"($) {
4996
5021
  check($mol_jsx("span", null), [
4997
5022
  tupl | 4, list | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
4998
5023
  text | 4, ...str('SPAN'), list | 0, list | 0, list | 0
4999
5024
  ]);
5000
- check($mol_jsx("svg", null), [
5001
- tupl | 4, list | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
5002
- text | 3, ...str('SVG'), list | 0, list | 0, list | 0
5003
- ]);
5004
5025
  check($mol_jsx("span", { tabIndex: "0" }), [
5005
5026
  tupl | 4, list | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
5006
5027
  text | 4, ...str('SPAN'), list | 1, text | 8, ...str('tabindex'), list | 1, text | 1, ...str('0'), list | 0
@@ -5019,6 +5040,20 @@ var $;
5019
5040
  text | 1, ...str(' '),
5020
5041
  ]);
5021
5042
  },
5043
+ "vary pack DOM Comment"($) {
5044
+ check($mol_jsx("div", null, $mol_dom.document.createComment('foo')), [
5045
+ tupl | 4, list | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
5046
+ text | 3, ...str('DIV'), list | 0, list | 0, list | 1,
5047
+ tupl | 1, list | 1, text | 8, ...str('#comment'), text | 3, ...str('foo'),
5048
+ ]);
5049
+ },
5050
+ "vary pack DOM PI"($) {
5051
+ check($mol_jsx("div", null, $mol_dom.document.createProcessingInstruction('foo', 'bar')), [
5052
+ tupl | 4, list | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
5053
+ text | 3, ...str('DIV'), list | 0, list | 0, list | 1,
5054
+ tupl | 2, list | 2, text | 6, ...str('target'), text | 4, ...str('text'), text | 3, ...str('foo'), text | 3, ...str('bar'),
5055
+ ]);
5056
+ },
5022
5057
  "vary pack custom class"($) {
5023
5058
  class Foo {
5024
5059
  a;