mol_dump_lib 0.0.868 → 0.0.870

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/web.mjs CHANGED
@@ -449,7 +449,7 @@ var $;
449
449
  if (this[$mol_ambient_ref])
450
450
  return this[$mol_ambient_ref];
451
451
  const owner = $mol_owning_get(this);
452
- return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
452
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
453
453
  }
454
454
  set $(next) {
455
455
  if (this[$mol_ambient_ref])
@@ -5527,12 +5527,41 @@ var $;
5527
5527
  "use strict";
5528
5528
  var $;
5529
5529
  (function ($) {
5530
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
5531
- const encoder = new TextEncoder();
5532
- function $mol_charset_encode(value) {
5533
- return encoder.encode(value);
5530
+ let buf = new Uint8Array(2 ** 12);
5531
+ function $mol_charset_encode(str) {
5532
+ const capacity = str.length * 3;
5533
+ if (buf.byteLength < capacity)
5534
+ buf = new Uint8Array(capacity);
5535
+ return buf.slice(0, $mol_charset_encode_to(str, buf));
5534
5536
  }
5535
5537
  $.$mol_charset_encode = $mol_charset_encode;
5538
+ function $mol_charset_encode_to(str, buf, from = 0) {
5539
+ let pos = from;
5540
+ for (let i = 0; i < str.length; i++) {
5541
+ let code = str.charCodeAt(i);
5542
+ if (code < 0x80) {
5543
+ buf[pos++] = code;
5544
+ }
5545
+ else if (code < 0x800) {
5546
+ buf[pos++] = 0xc0 | (code >> 6);
5547
+ buf[pos++] = 0x80 | (code & 0x3f);
5548
+ }
5549
+ else if (code < 0xd800 || code >= 0xe000) {
5550
+ buf[pos++] = 0xe0 | (code >> 12);
5551
+ buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
5552
+ buf[pos++] = 0x80 | (code & 0x3f);
5553
+ }
5554
+ else {
5555
+ const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
5556
+ buf[pos++] = 0xf0 | (point >> 18);
5557
+ buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
5558
+ buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
5559
+ buf[pos++] = 0x80 | (point & 0x3f);
5560
+ }
5561
+ }
5562
+ return pos - from;
5563
+ }
5564
+ $.$mol_charset_encode_to = $mol_charset_encode_to;
5536
5565
  })($ || ($ = {}));
5537
5566
 
5538
5567
  ;
package/web.test.js CHANGED
@@ -841,7 +841,7 @@ var $;
841
841
  ;
842
842
  "use strict";
843
843
  var $;
844
- (function ($) {
844
+ (function ($_1) {
845
845
  $mol_test({
846
846
  'init with overload'() {
847
847
  class X extends $mol_object {
@@ -854,6 +854,13 @@ var $;
854
854
  });
855
855
  $mol_assert_equal(x.foo(), 2);
856
856
  },
857
+ 'Context in instance inherits from class'($) {
858
+ const custom = $.$mol_ambient({});
859
+ class X extends $.$mol_object {
860
+ static $ = custom;
861
+ }
862
+ $mol_assert_equal(new X().$, custom);
863
+ },
857
864
  });
858
865
  })($ || ($ = {}));
859
866
 
@@ -3141,10 +3148,23 @@ var $;
3141
3148
  var $;
3142
3149
  (function ($) {
3143
3150
  $mol_test({
3144
- 'encode utf8 string'() {
3145
- const str = 'Hello, ΧΨΩЫ';
3146
- const encoded = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 206, 167, 206, 168, 206, 169, 208, 171]);
3147
- $mol_assert_like($mol_charset_encode(str), encoded);
3151
+ 'encode empty'() {
3152
+ $mol_assert_equal($mol_charset_encode(''), new Uint8Array([]));
3153
+ },
3154
+ 'encode 1 octet'() {
3155
+ $mol_assert_equal($mol_charset_encode('F'), new Uint8Array([0x46]));
3156
+ },
3157
+ 'encode 2 octet'() {
3158
+ $mol_assert_equal($mol_charset_encode('Б'), new Uint8Array([0xd0, 0x91]));
3159
+ },
3160
+ 'encode 3 octet'() {
3161
+ $mol_assert_equal($mol_charset_encode('ह'), new Uint8Array([0xe0, 0xa4, 0xb9]));
3162
+ },
3163
+ 'encode 4 octet'() {
3164
+ $mol_assert_equal($mol_charset_encode('𐍈'), new Uint8Array([0xf0, 0x90, 0x8d, 0x88]));
3165
+ },
3166
+ 'encode surrogate pair'() {
3167
+ $mol_assert_equal($mol_charset_encode('😀'), new Uint8Array([0xf0, 0x9f, 0x98, 0x80]));
3148
3168
  },
3149
3169
  });
3150
3170
  })($ || ($ = {}));