@ruby/head-wasm-wasi 2.6.2 → 2.7.0

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.
Files changed (138) hide show
  1. package/README.md +1 -1
  2. package/dist/NOTICE +1 -2
  3. package/dist/browser.script.iife.js +156 -130
  4. package/dist/browser.script.umd.js +166 -130
  5. package/dist/browser.umd.js +146 -129
  6. package/dist/index.umd.js +137 -118
  7. package/dist/ruby+stdlib.wasm +0 -0
  8. package/dist/ruby.debug+stdlib.wasm +0 -0
  9. package/dist/ruby.wasm +0 -0
  10. package/package.json +2 -2
  11. package/dist/component/interfaces/ruby-js-js-runtime.d.ts +0 -45
  12. package/dist/component/interfaces/ruby-js-ruby-runtime.d.ts +0 -31
  13. package/dist/component/interfaces/wasi-cli-environment.d.ts +0 -5
  14. package/dist/component/interfaces/wasi-cli-exit.d.ts +0 -4
  15. package/dist/component/interfaces/wasi-cli-stderr.d.ts +0 -5
  16. package/dist/component/interfaces/wasi-cli-stdin.d.ts +0 -5
  17. package/dist/component/interfaces/wasi-cli-stdout.d.ts +0 -5
  18. package/dist/component/interfaces/wasi-cli-terminal-input.d.ts +0 -6
  19. package/dist/component/interfaces/wasi-cli-terminal-output.d.ts +0 -6
  20. package/dist/component/interfaces/wasi-cli-terminal-stderr.d.ts +0 -5
  21. package/dist/component/interfaces/wasi-cli-terminal-stdin.d.ts +0 -5
  22. package/dist/component/interfaces/wasi-cli-terminal-stdout.d.ts +0 -5
  23. package/dist/component/interfaces/wasi-clocks-monotonic-clock.d.ts +0 -10
  24. package/dist/component/interfaces/wasi-clocks-wall-clock.d.ts +0 -8
  25. package/dist/component/interfaces/wasi-filesystem-preopens.d.ts +0 -5
  26. package/dist/component/interfaces/wasi-filesystem-types.d.ts +0 -158
  27. package/dist/component/interfaces/wasi-http-outgoing-handler.d.ts +0 -11
  28. package/dist/component/interfaces/wasi-http-types.d.ts +0 -311
  29. package/dist/component/interfaces/wasi-io-error.d.ts +0 -6
  30. package/dist/component/interfaces/wasi-io-poll.d.ts +0 -9
  31. package/dist/component/interfaces/wasi-io-streams.d.ts +0 -37
  32. package/dist/component/interfaces/wasi-random-random.d.ts +0 -3
  33. package/dist/component/package.json +0 -1
  34. package/dist/component/ruby.component.core.wasm +0 -0
  35. package/dist/component/ruby.component.core10.wasm +0 -0
  36. package/dist/component/ruby.component.core100.wasm +0 -0
  37. package/dist/component/ruby.component.core101.wasm +0 -0
  38. package/dist/component/ruby.component.core102.wasm +0 -0
  39. package/dist/component/ruby.component.core103.wasm +0 -0
  40. package/dist/component/ruby.component.core11.wasm +0 -0
  41. package/dist/component/ruby.component.core12.wasm +0 -0
  42. package/dist/component/ruby.component.core13.wasm +0 -0
  43. package/dist/component/ruby.component.core14.wasm +0 -0
  44. package/dist/component/ruby.component.core15.wasm +0 -0
  45. package/dist/component/ruby.component.core16.wasm +0 -0
  46. package/dist/component/ruby.component.core17.wasm +0 -0
  47. package/dist/component/ruby.component.core18.wasm +0 -0
  48. package/dist/component/ruby.component.core19.wasm +0 -0
  49. package/dist/component/ruby.component.core2.wasm +0 -0
  50. package/dist/component/ruby.component.core20.wasm +0 -0
  51. package/dist/component/ruby.component.core21.wasm +0 -0
  52. package/dist/component/ruby.component.core22.wasm +0 -0
  53. package/dist/component/ruby.component.core23.wasm +0 -0
  54. package/dist/component/ruby.component.core24.wasm +0 -0
  55. package/dist/component/ruby.component.core25.wasm +0 -0
  56. package/dist/component/ruby.component.core26.wasm +0 -0
  57. package/dist/component/ruby.component.core27.wasm +0 -0
  58. package/dist/component/ruby.component.core28.wasm +0 -0
  59. package/dist/component/ruby.component.core29.wasm +0 -0
  60. package/dist/component/ruby.component.core3.wasm +0 -0
  61. package/dist/component/ruby.component.core30.wasm +0 -0
  62. package/dist/component/ruby.component.core31.wasm +0 -0
  63. package/dist/component/ruby.component.core32.wasm +0 -0
  64. package/dist/component/ruby.component.core33.wasm +0 -0
  65. package/dist/component/ruby.component.core34.wasm +0 -0
  66. package/dist/component/ruby.component.core35.wasm +0 -0
  67. package/dist/component/ruby.component.core36.wasm +0 -0
  68. package/dist/component/ruby.component.core37.wasm +0 -0
  69. package/dist/component/ruby.component.core38.wasm +0 -0
  70. package/dist/component/ruby.component.core39.wasm +0 -0
  71. package/dist/component/ruby.component.core4.wasm +0 -0
  72. package/dist/component/ruby.component.core40.wasm +0 -0
  73. package/dist/component/ruby.component.core41.wasm +0 -0
  74. package/dist/component/ruby.component.core42.wasm +0 -0
  75. package/dist/component/ruby.component.core43.wasm +0 -0
  76. package/dist/component/ruby.component.core44.wasm +0 -0
  77. package/dist/component/ruby.component.core45.wasm +0 -0
  78. package/dist/component/ruby.component.core46.wasm +0 -0
  79. package/dist/component/ruby.component.core47.wasm +0 -0
  80. package/dist/component/ruby.component.core48.wasm +0 -0
  81. package/dist/component/ruby.component.core49.wasm +0 -0
  82. package/dist/component/ruby.component.core5.wasm +0 -0
  83. package/dist/component/ruby.component.core50.wasm +0 -0
  84. package/dist/component/ruby.component.core51.wasm +0 -0
  85. package/dist/component/ruby.component.core52.wasm +0 -0
  86. package/dist/component/ruby.component.core53.wasm +0 -0
  87. package/dist/component/ruby.component.core54.wasm +0 -0
  88. package/dist/component/ruby.component.core55.wasm +0 -0
  89. package/dist/component/ruby.component.core56.wasm +0 -0
  90. package/dist/component/ruby.component.core57.wasm +0 -0
  91. package/dist/component/ruby.component.core58.wasm +0 -0
  92. package/dist/component/ruby.component.core59.wasm +0 -0
  93. package/dist/component/ruby.component.core6.wasm +0 -0
  94. package/dist/component/ruby.component.core60.wasm +0 -0
  95. package/dist/component/ruby.component.core61.wasm +0 -0
  96. package/dist/component/ruby.component.core62.wasm +0 -0
  97. package/dist/component/ruby.component.core63.wasm +0 -0
  98. package/dist/component/ruby.component.core64.wasm +0 -0
  99. package/dist/component/ruby.component.core65.wasm +0 -0
  100. package/dist/component/ruby.component.core66.wasm +0 -0
  101. package/dist/component/ruby.component.core67.wasm +0 -0
  102. package/dist/component/ruby.component.core68.wasm +0 -0
  103. package/dist/component/ruby.component.core69.wasm +0 -0
  104. package/dist/component/ruby.component.core7.wasm +0 -0
  105. package/dist/component/ruby.component.core70.wasm +0 -0
  106. package/dist/component/ruby.component.core71.wasm +0 -0
  107. package/dist/component/ruby.component.core72.wasm +0 -0
  108. package/dist/component/ruby.component.core73.wasm +0 -0
  109. package/dist/component/ruby.component.core74.wasm +0 -0
  110. package/dist/component/ruby.component.core75.wasm +0 -0
  111. package/dist/component/ruby.component.core76.wasm +0 -0
  112. package/dist/component/ruby.component.core77.wasm +0 -0
  113. package/dist/component/ruby.component.core78.wasm +0 -0
  114. package/dist/component/ruby.component.core79.wasm +0 -0
  115. package/dist/component/ruby.component.core8.wasm +0 -0
  116. package/dist/component/ruby.component.core80.wasm +0 -0
  117. package/dist/component/ruby.component.core81.wasm +0 -0
  118. package/dist/component/ruby.component.core82.wasm +0 -0
  119. package/dist/component/ruby.component.core83.wasm +0 -0
  120. package/dist/component/ruby.component.core84.wasm +0 -0
  121. package/dist/component/ruby.component.core85.wasm +0 -0
  122. package/dist/component/ruby.component.core86.wasm +0 -0
  123. package/dist/component/ruby.component.core87.wasm +0 -0
  124. package/dist/component/ruby.component.core88.wasm +0 -0
  125. package/dist/component/ruby.component.core89.wasm +0 -0
  126. package/dist/component/ruby.component.core9.wasm +0 -0
  127. package/dist/component/ruby.component.core90.wasm +0 -0
  128. package/dist/component/ruby.component.core91.wasm +0 -0
  129. package/dist/component/ruby.component.core92.wasm +0 -0
  130. package/dist/component/ruby.component.core93.wasm +0 -0
  131. package/dist/component/ruby.component.core94.wasm +0 -0
  132. package/dist/component/ruby.component.core95.wasm +0 -0
  133. package/dist/component/ruby.component.core96.wasm +0 -0
  134. package/dist/component/ruby.component.core97.wasm +0 -0
  135. package/dist/component/ruby.component.core98.wasm +0 -0
  136. package/dist/component/ruby.component.core99.wasm +0 -0
  137. package/dist/component/ruby.component.d.ts +0 -80
  138. package/dist/component/ruby.component.js +0 -17118
package/README.md CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/@ruby%2Fhead-wasm-wasi.svg)](https://www.npmjs.com/package/@ruby/head-wasm-wasi)
4
4
 
5
- This package provides WebAssembly binaries of CRuby built from the latest `HEAD` source code targeting WASI-compatible environments.
5
+ This package provides WebAssembly binaries of CRuby built from the latest `HEAD` source code targeting environments compatible with WASI Preview1.
6
6
 
7
7
  See [`@ruby/wasm-wasi`](https://github.com/ruby/ruby.wasm/blob/main/packages/npm-packages/ruby-wasm-wasi/README.md) for how to use this package.
package/dist/NOTICE CHANGED
@@ -1264,8 +1264,7 @@ Licensed under the Apache License 2.0 https://www.openssl.org/source/license.htm
1264
1264
  https://github.com/kateinoigakukun/wasi-vfs
1265
1265
 
1266
1266
  ```
1267
- Copyright (c) 2022 Yuta Saito. All rights reserved.
1268
- Licensed under the MIT License
1267
+ Licensed under the Apache License v2.0 with LLVM Exceptions
1269
1268
  ```
1270
1269
 
1271
1270
  ---
@@ -1264,8 +1264,7 @@ Licensed under the Apache License 2.0 https://www.openssl.org/source/license.htm
1264
1264
  https://github.com/kateinoigakukun/wasi-vfs
1265
1265
 
1266
1266
  ```
1267
- Copyright (c) 2022 Yuta Saito. All rights reserved.
1268
- Licensed under the MIT License
1267
+ Licensed under the Apache License v2.0 with LLVM Exceptions
1269
1268
  ```
1270
1269
 
1271
1270
  ---
@@ -1309,7 +1308,7 @@ SOFTWARE.
1309
1308
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1310
1309
  PERFORMANCE OF THIS SOFTWARE.
1311
1310
  ***************************************************************************** */
1312
- /* global Reflect, Promise, SuppressedError, Symbol */
1311
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1313
1312
 
1314
1313
 
1315
1314
  function __values(o) {
@@ -1527,38 +1526,23 @@ SOFTWARE.
1527
1526
  class RbAbiGuest {
1528
1527
  constructor() {
1529
1528
  this._resource0_slab = new Slab();
1530
- this._resource1_slab = new Slab();
1531
1529
  }
1532
1530
  addToImports(imports) {
1533
1531
  if (!("canonical_abi" in imports))
1534
1532
  imports["canonical_abi"] = {};
1535
- imports.canonical_abi['resource_drop_rb-iseq'] = i => {
1533
+ imports.canonical_abi['resource_drop_rb-abi-value'] = i => {
1536
1534
  this._resource0_slab.remove(i).drop();
1537
1535
  };
1538
- imports.canonical_abi['resource_clone_rb-iseq'] = i => {
1536
+ imports.canonical_abi['resource_clone_rb-abi-value'] = i => {
1539
1537
  const obj = this._resource0_slab.get(i);
1540
1538
  return this._resource0_slab.insert(obj.clone());
1541
1539
  };
1542
- imports.canonical_abi['resource_get_rb-iseq'] = i => {
1543
- return this._resource0_slab.get(i)._wasm_val;
1544
- };
1545
- imports.canonical_abi['resource_new_rb-iseq'] = i => {
1546
- this._registry0;
1547
- return this._resource0_slab.insert(new RbIseq(i, this));
1548
- };
1549
- imports.canonical_abi['resource_drop_rb-abi-value'] = i => {
1550
- this._resource1_slab.remove(i).drop();
1551
- };
1552
- imports.canonical_abi['resource_clone_rb-abi-value'] = i => {
1553
- const obj = this._resource1_slab.get(i);
1554
- return this._resource1_slab.insert(obj.clone());
1555
- };
1556
1540
  imports.canonical_abi['resource_get_rb-abi-value'] = i => {
1557
- return this._resource1_slab.get(i)._wasm_val;
1541
+ return this._resource0_slab.get(i)._wasm_val;
1558
1542
  };
1559
1543
  imports.canonical_abi['resource_new_rb-abi-value'] = i => {
1560
- this._registry1;
1561
- return this._resource1_slab.insert(new RbAbiValue(i, this));
1544
+ this._registry0;
1545
+ return this._resource0_slab.insert(new RbAbiValue(i, this));
1562
1546
  };
1563
1547
  }
1564
1548
  async instantiate(module, imports) {
@@ -1579,16 +1563,12 @@ SOFTWARE.
1579
1563
  this.instance = instance;
1580
1564
  }
1581
1565
  this._exports = this.instance.exports;
1582
- this._registry0 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-iseq']);
1583
- this._registry1 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-abi-value']);
1566
+ this._registry0 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-abi-value']);
1584
1567
  }
1585
1568
  rubyShowVersion() {
1586
1569
  this._exports['ruby-show-version: func() -> ()']();
1587
1570
  }
1588
- rubyInit() {
1589
- this._exports['ruby-init: func() -> ()']();
1590
- }
1591
- rubySysinit(arg0) {
1571
+ rubyInit(arg0) {
1592
1572
  const memory = this._exports.memory;
1593
1573
  const realloc = this._exports["cabi_realloc"];
1594
1574
  const vec1 = arg0;
@@ -1602,31 +1582,7 @@ SOFTWARE.
1602
1582
  data_view(memory).setInt32(base + 4, len0, true);
1603
1583
  data_view(memory).setInt32(base + 0, ptr0, true);
1604
1584
  }
1605
- this._exports['ruby-sysinit: func(args: list<string>) -> ()'](result1, len1);
1606
- }
1607
- rubyOptions(arg0) {
1608
- const memory = this._exports.memory;
1609
- const realloc = this._exports["cabi_realloc"];
1610
- const vec1 = arg0;
1611
- const len1 = vec1.length;
1612
- const result1 = realloc(0, 0, 4, len1 * 8);
1613
- for (let i = 0; i < vec1.length; i++) {
1614
- const e = vec1[i];
1615
- const base = result1 + i * 8;
1616
- const ptr0 = utf8_encode(e, realloc, memory);
1617
- const len0 = UTF8_ENCODED_LEN;
1618
- data_view(memory).setInt32(base + 4, len0, true);
1619
- data_view(memory).setInt32(base + 0, ptr0, true);
1620
- }
1621
- const ret = this._exports['ruby-options: func(args: list<string>) -> handle<rb-iseq>'](result1, len1);
1622
- return this._resource0_slab.remove(ret);
1623
- }
1624
- rubyScript(arg0) {
1625
- const memory = this._exports.memory;
1626
- const realloc = this._exports["cabi_realloc"];
1627
- const ptr0 = utf8_encode(arg0, realloc, memory);
1628
- const len0 = UTF8_ENCODED_LEN;
1629
- this._exports['ruby-script: func(name: string) -> ()'](ptr0, len0);
1585
+ this._exports['ruby-init: func(args: list<string>) -> ()'](result1, len1);
1630
1586
  }
1631
1587
  rubyInitLoadpath() {
1632
1588
  this._exports['ruby-init-loadpath: func() -> ()']();
@@ -1637,7 +1593,7 @@ SOFTWARE.
1637
1593
  const ptr0 = utf8_encode(arg0, realloc, memory);
1638
1594
  const len0 = UTF8_ENCODED_LEN;
1639
1595
  const ret = this._exports['rb-eval-string-protect: func(str: string) -> tuple<handle<rb-abi-value>, s32>'](ptr0, len0);
1640
- return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
1596
+ return [this._resource0_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
1641
1597
  }
1642
1598
  rbFuncallvProtect(arg0, arg1, arg2) {
1643
1599
  const memory = this._exports.memory;
@@ -1654,10 +1610,10 @@ SOFTWARE.
1654
1610
  const obj1 = e;
1655
1611
  if (!(obj1 instanceof RbAbiValue))
1656
1612
  throw new TypeError('expected instance of RbAbiValue');
1657
- data_view(memory).setInt32(base + 0, this._resource1_slab.insert(obj1.clone()), true);
1613
+ data_view(memory).setInt32(base + 0, this._resource0_slab.insert(obj1.clone()), true);
1658
1614
  }
1659
- const ret = this._exports['rb-funcallv-protect: func(recv: handle<rb-abi-value>, mid: u32, args: list<handle<rb-abi-value>>) -> tuple<handle<rb-abi-value>, s32>'](this._resource1_slab.insert(obj0.clone()), to_uint32(arg1), result2, len2);
1660
- return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
1615
+ const ret = this._exports['rb-funcallv-protect: func(recv: handle<rb-abi-value>, mid: u32, args: list<handle<rb-abi-value>>) -> tuple<handle<rb-abi-value>, s32>'](this._resource0_slab.insert(obj0.clone()), to_uint32(arg1), result2, len2);
1616
+ return [this._resource0_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
1661
1617
  }
1662
1618
  rbIntern(arg0) {
1663
1619
  const memory = this._exports.memory;
@@ -1669,7 +1625,7 @@ SOFTWARE.
1669
1625
  }
1670
1626
  rbErrinfo() {
1671
1627
  const ret = this._exports['rb-errinfo: func() -> handle<rb-abi-value>']();
1672
- return this._resource1_slab.remove(ret);
1628
+ return this._resource0_slab.remove(ret);
1673
1629
  }
1674
1630
  rbClearErrinfo() {
1675
1631
  this._exports['rb-clear-errinfo: func() -> ()']();
@@ -1679,7 +1635,7 @@ SOFTWARE.
1679
1635
  const obj0 = arg0;
1680
1636
  if (!(obj0 instanceof RbAbiValue))
1681
1637
  throw new TypeError('expected instance of RbAbiValue');
1682
- const ret = this._exports['rstring-ptr: func(value: handle<rb-abi-value>) -> string'](this._resource1_slab.insert(obj0.clone()));
1638
+ const ret = this._exports['rstring-ptr: func(value: handle<rb-abi-value>) -> string'](this._resource0_slab.insert(obj0.clone()));
1683
1639
  const ptr1 = data_view(memory).getInt32(ret + 0, true);
1684
1640
  const len1 = data_view(memory).getInt32(ret + 4, true);
1685
1641
  const result1 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1));
@@ -1705,7 +1661,7 @@ SOFTWARE.
1705
1661
  return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
1706
1662
  }
1707
1663
  }
1708
- class RbIseq {
1664
+ class RbAbiValue {
1709
1665
  constructor(wasm_val, obj) {
1710
1666
  this._wasm_val = wasm_val;
1711
1667
  this._obj = obj;
@@ -1721,30 +1677,6 @@ SOFTWARE.
1721
1677
  if (this._refcnt !== 0)
1722
1678
  return;
1723
1679
  this._obj._registry0.unregister(this);
1724
- const dtor = this._obj._exports['canonical_abi_drop_rb-iseq'];
1725
- const wasm_val = this._wasm_val;
1726
- delete this._obj;
1727
- delete this._refcnt;
1728
- delete this._wasm_val;
1729
- dtor(wasm_val);
1730
- }
1731
- }
1732
- class RbAbiValue {
1733
- constructor(wasm_val, obj) {
1734
- this._wasm_val = wasm_val;
1735
- this._obj = obj;
1736
- this._refcnt = 1;
1737
- obj._registry1.register(this, wasm_val, this);
1738
- }
1739
- clone() {
1740
- this._refcnt += 1;
1741
- return this;
1742
- }
1743
- drop() {
1744
- this._refcnt -= 1;
1745
- if (this._refcnt !== 0)
1746
- return;
1747
- this._obj._registry1.unregister(this);
1748
1680
  const dtor = this._obj._exports['canonical_abi_drop_rb-abi-value'];
1749
1681
  const wasm_val = this._wasm_val;
1750
1682
  delete this._obj;
@@ -2046,17 +1978,8 @@ SOFTWARE.
2046
1978
  rubyShowVersion() {
2047
1979
  this.underlying.rubyShowVersion();
2048
1980
  }
2049
- rubyInit() {
2050
- this.underlying.rubyInit();
2051
- }
2052
- rubySysinit(args) {
2053
- this.underlying.rubySysinit(args);
2054
- }
2055
- rubyOptions(args) {
2056
- this.underlying.rubyOptions(args);
2057
- }
2058
- rubyScript(name) {
2059
- this.underlying.rubyScript(name);
1981
+ rubyInit(args) {
1982
+ this.underlying.rubyInit(args);
2060
1983
  }
2061
1984
  rubyInitLoadpath() {
2062
1985
  this.underlying.rubyInitLoadpath();
@@ -2101,24 +2024,111 @@ SOFTWARE.
2101
2024
 
2102
2025
  /**
2103
2026
  * A Ruby VM instance
2104
- *
2105
- * @example
2106
- *
2107
- * const wasi = new WASI();
2108
- * const vm = new RubyVM();
2109
- * const imports = {
2110
- * wasi_snapshot_preview1: wasi.wasiImport,
2111
- * };
2112
- *
2113
- * vm.addToImports(imports);
2114
- *
2115
- * const instance = await WebAssembly.instantiate(rubyModule, imports);
2116
- * await vm.setInstance(instance);
2117
- * wasi.initialize(instance);
2118
- * vm.initialize();
2119
- *
2027
+ * @see {@link RubyVM.instantiateComponent} and {@link RubyVM.instantiateModule} to create a new instance
2028
+ * @category Essentials
2120
2029
  */
2121
2030
  class RubyVM {
2031
+ /**
2032
+ * Instantiate a Ruby VM with the given WebAssembly Core module with WASI Preview 1 implementation.
2033
+ *
2034
+ * @param options The options to instantiate the Ruby VM
2035
+ * @returns A promise that resolves to the Ruby VM instance and the WebAssembly instance
2036
+ * @category Essentials
2037
+ *
2038
+ * @example
2039
+ *
2040
+ * import { WASI } from "@bjorn3/browser_wasi_shim";
2041
+ * const wasip1 = new WASI([], [], []);
2042
+ * const module = await WebAssembly.compile("./path/to/ruby.wasm");
2043
+ * const { vm } = await RubyVM.instantiateModule({ module, wasip1 });
2044
+ *
2045
+ */
2046
+ static async instantiateModule(options) {
2047
+ var _a, _b;
2048
+ const { module, wasip1 } = options;
2049
+ const vm = new RubyVM();
2050
+ const imports = {
2051
+ wasi_snapshot_preview1: wasip1.wasiImport,
2052
+ };
2053
+ vm.addToImports(imports);
2054
+ (_a = options.addToImports) === null || _a === void 0 ? void 0 : _a.call(options, imports);
2055
+ const instance = await WebAssembly.instantiate(module, imports);
2056
+ await vm.setInstance(instance);
2057
+ (_b = options.setMemory) === null || _b === void 0 ? void 0 : _b.call(options, instance.exports.memory);
2058
+ wasip1.initialize(instance);
2059
+ vm.initialize(options.args);
2060
+ return { vm, instance };
2061
+ }
2062
+ /**
2063
+ * Instantiate a Ruby VM with the given WebAssembly component with WASI Preview 2 implementation.
2064
+ *
2065
+ * @param options The options to instantiate the Ruby VM
2066
+ * @returns A promise that resolves to the Ruby VM instance
2067
+ * @category Essentials
2068
+ *
2069
+ * @example
2070
+ *
2071
+ * // First, you need to transpile the Ruby component to a JavaScript module using jco.
2072
+ * // $ jco transpile --no-wasi-shim --instantiation --valid-lifting-optimization ./ruby.component.wasm -o ./component
2073
+ * // Then, you can instantiate the Ruby VM with the component:
2074
+ *
2075
+ * import * as wasip2 from "@bytecodealliance/preview2-shim"
2076
+ * import fs from "fs/promises";
2077
+ * import path from "path";
2078
+ *
2079
+ * const { instantiate } = await import("./component/ruby.component.js");
2080
+ * const getCoreModule = async (relativePath) => {
2081
+ * const buffer = await fs.readFile(path.join("./component", relativePath));
2082
+ * return WebAssembly.compile(buffer);
2083
+ * }
2084
+ *
2085
+ * const { vm } = await RubyVM.instantiateComponent({
2086
+ * instantiate, getCoreModule, wasip2,
2087
+ * });
2088
+ *
2089
+ */
2090
+ static async instantiateComponent(options) {
2091
+ let initComponent;
2092
+ if ("getCoreModule" in options) {
2093
+ // A convenience overload to instantiate with "instantiate" function generated by jco
2094
+ initComponent = async (jsRuntime) => {
2095
+ const { instantiate, getCoreModule, wasip2 } = options;
2096
+ const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
2097
+ const importObject = {
2098
+ "ruby:js/js-runtime": jsRuntime,
2099
+ "wasi:cli/environment": cli.environment,
2100
+ "wasi:cli/exit": cli.exit,
2101
+ "wasi:cli/stderr": cli.stderr,
2102
+ "wasi:cli/stdin": cli.stdin,
2103
+ "wasi:cli/stdout": cli.stdout,
2104
+ "wasi:cli/terminal-input": cli.terminalInput,
2105
+ "wasi:cli/terminal-output": cli.terminalOutput,
2106
+ "wasi:cli/terminal-stderr": cli.terminalStderr,
2107
+ "wasi:cli/terminal-stdin": cli.terminalStdin,
2108
+ "wasi:cli/terminal-stdout": cli.terminalStdout,
2109
+ "wasi:clocks/monotonic-clock": clocks.monotonicClock,
2110
+ "wasi:clocks/wall-clock": clocks.wallClock,
2111
+ "wasi:filesystem/preopens": filesystem.preopens,
2112
+ "wasi:filesystem/types": filesystem.types,
2113
+ "wasi:io/error": io.error,
2114
+ "wasi:io/poll": io.poll,
2115
+ "wasi:io/streams": io.streams,
2116
+ "wasi:random/random": random.random,
2117
+ "wasi:sockets/tcp": sockets.tcp,
2118
+ "wasi:http/types": http.types,
2119
+ "wasi:http/incoming-handler": http.incomingHandler,
2120
+ "wasi:http/outgoing-handler": http.outgoingHandler,
2121
+ };
2122
+ const component = await instantiate(getCoreModule, importObject, options.instantiateCore);
2123
+ return component.rubyRuntime;
2124
+ };
2125
+ }
2126
+ else {
2127
+ initComponent = options.instantiate;
2128
+ }
2129
+ const vm = await this._instantiate({}, initComponent);
2130
+ return { vm };
2131
+ }
2122
2132
  constructor(binding) {
2123
2133
  this.instance = null;
2124
2134
  this.interfaceState = {
@@ -2167,7 +2177,7 @@ SOFTWARE.
2167
2177
  this.transport = new JsValueTransport();
2168
2178
  this.exceptionFormatter = new RbExceptionFormatter();
2169
2179
  }
2170
- static async _instantiate(initComponent, options) {
2180
+ static async _instantiate(options, initComponent) {
2171
2181
  const binding = new ComponentBinding();
2172
2182
  const vm = new RubyVM(binding);
2173
2183
  class JsAbiValue {
@@ -2195,14 +2205,21 @@ SOFTWARE.
2195
2205
  * Initialize the Ruby VM with the given command line arguments
2196
2206
  * @param args The command line arguments to pass to Ruby. Must be
2197
2207
  * an array of strings starting with the Ruby program name.
2208
+ * @category Low-level initialization
2198
2209
  */
2199
2210
  initialize(args = ["ruby.wasm", "-EUTF-8", "-e_=0"]) {
2200
2211
  const c_args = args.map((arg) => arg + "\0");
2201
- this.guest.rubyInit();
2202
- this.guest.rubySysinit(c_args);
2203
- this.guest.rubyOptions(c_args);
2212
+ this.guest.rubyInit(c_args);
2204
2213
  try {
2205
- this.eval(`require "/bundle/setup"`);
2214
+ this.eval(`
2215
+ # Require Bundler standalone setup
2216
+ if File.exist?("/bundle/bundler/setup.rb")
2217
+ require "/bundle/bundler/setup.rb"
2218
+ elsif File.exist?("/bundle/setup.rb")
2219
+ # For non-CM builds, which doesn't use Bundler's standalone mode
2220
+ require "/bundle/setup.rb"
2221
+ end
2222
+ `);
2206
2223
  }
2207
2224
  catch (e) {
2208
2225
  console.warn("Failed to load /bundle/setup", e);
@@ -2216,6 +2233,7 @@ SOFTWARE.
2216
2233
  * @param instance The WebAssembly instance to interact with. Must
2217
2234
  * be instantiated from a Ruby built with JS extension, and built
2218
2235
  * with Reactor ABI instead of command line.
2236
+ * @category Low-level initialization
2219
2237
  */
2220
2238
  async setInstance(instance) {
2221
2239
  this.instance = instance;
@@ -2225,6 +2243,7 @@ SOFTWARE.
2225
2243
  * Add intrinsic import entries, which is necessary to interact JavaScript
2226
2244
  * and Ruby's WebAssembly instance.
2227
2245
  * @param imports The import object to add to the WebAssembly instance
2246
+ * @category Low-level initialization
2228
2247
  */
2229
2248
  addToImports(imports) {
2230
2249
  this.guest.addToImports(imports);
@@ -2430,6 +2449,7 @@ SOFTWARE.
2430
2449
  * Runs a string of Ruby code from JavaScript
2431
2450
  * @param code The Ruby code to run
2432
2451
  * @returns the result of the last expression
2452
+ * @category Essentials
2433
2453
  *
2434
2454
  * @example
2435
2455
  * vm.eval("puts 'hello world'");
@@ -2445,6 +2465,7 @@ SOFTWARE.
2445
2465
  * Returns a promise that resolves when execution completes.
2446
2466
  * @param code The Ruby code to run
2447
2467
  * @returns a promise that resolves to the result of the last expression
2468
+ * @category Essentials
2448
2469
  *
2449
2470
  * @example
2450
2471
  * const text = await vm.evalAsync(`
@@ -2527,6 +2548,7 @@ SOFTWARE.
2527
2548
  }
2528
2549
  /**
2529
2550
  * A RbValue is an object that represents a value in Ruby
2551
+ * @category Essentials
2530
2552
  */
2531
2553
  class RbValue {
2532
2554
  /**
@@ -2828,18 +2850,16 @@ SOFTWARE.
2828
2850
  new PreopenDirectory("/", new Map()),
2829
2851
  ];
2830
2852
  const wasi = new WASI(args, env, fds, { debug: false });
2831
- const vm = new RubyVM();
2832
- const imports = {
2833
- wasi_snapshot_preview1: wasi.wasiImport,
2834
- };
2835
- vm.addToImports(imports);
2836
2853
  const printer = ((_b = options.consolePrint) !== null && _b !== void 0 ? _b : true) ? consolePrinter() : undefined;
2837
- printer === null || printer === void 0 ? void 0 : printer.addToImports(imports);
2838
- const instance = await WebAssembly.instantiate(rubyModule, imports);
2839
- await vm.setInstance(instance);
2840
- printer === null || printer === void 0 ? void 0 : printer.setMemory(instance.exports.memory);
2841
- wasi.initialize(instance);
2842
- vm.initialize();
2854
+ const { vm, instance } = await RubyVM.instantiateModule({
2855
+ module: rubyModule, wasip1: wasi,
2856
+ addToImports: (imports) => {
2857
+ printer === null || printer === void 0 ? void 0 : printer.addToImports(imports);
2858
+ },
2859
+ setMemory: (memory) => {
2860
+ printer === null || printer === void 0 ? void 0 : printer.setMemory(memory);
2861
+ }
2862
+ });
2843
2863
  return {
2844
2864
  vm,
2845
2865
  wasi,
@@ -2847,10 +2867,16 @@ SOFTWARE.
2847
2867
  };
2848
2868
  };
2849
2869
 
2870
+ /**
2871
+ * The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Core Module.
2872
+ */
2850
2873
  const main$1 = async (pkg, options) => {
2851
2874
  const response = fetch(`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`);
2852
2875
  const module = await compileWebAssemblyModule(response);
2853
2876
  const { vm } = await DefaultRubyVM(module, options);
2877
+ await mainWithRubyVM(vm);
2878
+ };
2879
+ const mainWithRubyVM = async (vm) => {
2854
2880
  vm.printVersion();
2855
2881
  globalThis.rubyVM = vm;
2856
2882
  // Wait for the text/ruby script tag to be read.
@@ -2933,7 +2959,7 @@ SOFTWARE.
2933
2959
  };
2934
2960
 
2935
2961
  var name = "@ruby/head-wasm-wasi";
2936
- var version = "2.6.2";
2962
+ var version = "2.7.0";
2937
2963
  var description = "Ruby head built on WASI";
2938
2964
  var main = "./dist/cjs/index.js";
2939
2965
  var module = "./dist/esm/index.js";
@@ -2962,7 +2988,7 @@ SOFTWARE.
2962
2988
  "README.md"
2963
2989
  ];
2964
2990
  var scripts = {
2965
- test: "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi npm -C ../ruby-wasm-wasi run test:run:all",
2991
+ test: "RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi npm -C ../ruby-wasm-wasi run test:run",
2966
2992
  "build:deps": "cd ../ruby-wasm-wasi && npm run build",
2967
2993
  "build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
2968
2994
  "build:static:compat": "../ruby-wasm-wasi/tools/pack-compat-shim.mjs --dist=./dist --pkg=ruby-head-wasm-wasi",