@ruby/wasm-wasi 2.3.0 → 2.4.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 (46) hide show
  1. package/README.md +180 -4
  2. package/dist/browser.script.umd.js +170 -2048
  3. package/dist/browser.umd.js +170 -2048
  4. package/dist/cjs/bindgen/intrinsics.d.ts +13 -0
  5. package/dist/cjs/bindgen/intrinsics.js +81 -0
  6. package/dist/cjs/bindgen/rb-abi-guest.js +236 -0
  7. package/dist/cjs/bindgen/rb-js-abi-host.js +283 -0
  8. package/dist/{browser.d.ts → cjs/browser.d.ts} +2 -2
  9. package/dist/cjs/browser.js +30 -0
  10. package/dist/{browser.script.d.ts → cjs/browser.script.d.ts} +1 -1
  11. package/dist/cjs/browser.script.js +90 -0
  12. package/dist/cjs/console.d.ts +33 -0
  13. package/dist/cjs/console.js +104 -0
  14. package/dist/{index.d.ts → cjs/index.d.ts} +7 -3
  15. package/dist/cjs/index.js +646 -0
  16. package/dist/{node.d.ts → cjs/node.d.ts} +1 -1
  17. package/dist/cjs/node.js +23 -0
  18. package/dist/esm/bindgen/intrinsics.d.ts +13 -0
  19. package/dist/esm/bindgen/intrinsics.js +73 -0
  20. package/dist/esm/bindgen/rb-abi-guest.d.ts +140 -0
  21. package/dist/esm/bindgen/rb-abi-guest.js +230 -0
  22. package/dist/esm/bindgen/rb-js-abi-host.d.ts +53 -0
  23. package/dist/esm/bindgen/rb-js-abi-host.js +279 -0
  24. package/dist/esm/browser.d.ts +10 -0
  25. package/dist/esm/browser.js +26 -0
  26. package/dist/esm/browser.script.d.ts +5 -0
  27. package/dist/esm/browser.script.js +86 -0
  28. package/dist/esm/console.d.ts +33 -0
  29. package/dist/esm/console.js +100 -0
  30. package/dist/esm/index.d.ts +196 -0
  31. package/dist/esm/index.js +637 -0
  32. package/dist/esm/node.d.ts +10 -0
  33. package/dist/esm/node.js +19 -0
  34. package/dist/esm/package.json +1 -0
  35. package/dist/index.umd.js +158 -10
  36. package/package.json +22 -38
  37. package/dist/browser.cjs.js +0 -3245
  38. package/dist/browser.esm.js +0 -3243
  39. package/dist/browser.script.cjs.js +0 -3372
  40. package/dist/browser.script.esm.js +0 -3370
  41. package/dist/index.cjs.js +0 -1192
  42. package/dist/index.esm.js +0 -1187
  43. package/dist/node.cjs.js +0 -1209
  44. package/dist/node.esm.js +0 -1207
  45. /package/dist/{bindgen → cjs/bindgen}/rb-abi-guest.d.ts +0 -0
  46. /package/dist/{bindgen → cjs/bindgen}/rb-js-abi-host.d.ts +0 -0
package/README.md CHANGED
@@ -1,7 +1,183 @@
1
1
  # @ruby/wasm-wasi
2
2
 
3
- This package is a template for each channel-specific package.
3
+ [![npm version](https://badge.fury.io/js/@ruby%2Fwasm-wasi.svg)](https://www.npmjs.com/package/@ruby/wasm-wasi)
4
4
 
5
- | Channel | Package |
6
- | ------- | ------------------------------------------------- |
7
- | `head` | [`ruby-head-wasm-wasi`](./../ruby-head-wasm-wasi) |
5
+ This package provides core APIs for Ruby on WebAssembly targeting WASI-compatible environments. WebAssembly binaries are distributed in version-specific packages.
6
+
7
+ See [Cheat Sheet](https://github.com/ruby/ruby.wasm/blob/main/docs/cheat_sheet.md) for how to use this package.
8
+
9
+ ## Ruby Version Support
10
+
11
+ | Version | Package |
12
+ | ------- | -------------------------------------------------- |
13
+ | `head` | [`@ruby/head-wasm-wasi`](./../ruby-head-wasm-wasi) |
14
+ | `3.2` | [`@ruby/3.2-wasm-wasi`](./../ruby-3.2-wasm-wasi) |
15
+
16
+ ## API
17
+
18
+ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
19
+
20
+ ### RubyVM
21
+
22
+ A Ruby VM instance
23
+
24
+ #### Examples
25
+
26
+ ```javascript
27
+ const wasi = new WASI();
28
+ const vm = new RubyVM();
29
+ const imports = {
30
+ wasi_snapshot_preview1: wasi.wasiImport,
31
+ };
32
+
33
+ vm.addToImports(imports);
34
+
35
+ const instance = await WebAssembly.instantiate(rubyModule, imports);
36
+ await vm.setInstance(instance);
37
+ wasi.initialize(instance);
38
+ vm.initialize();
39
+ ```
40
+
41
+ #### initialize
42
+
43
+ Initialize the Ruby VM with the given command line arguments
44
+
45
+ ##### Parameters
46
+
47
+ - `args` The command line arguments to pass to Ruby. Must be
48
+ an array of strings starting with the Ruby program name. (optional, default `["ruby.wasm","--disable-gems","-EUTF-8","-e_=0"]`)
49
+
50
+ #### setInstance
51
+
52
+ Set a given instance to interact JavaScript and Ruby's
53
+ WebAssembly instance. This method must be called before calling
54
+ Ruby API.
55
+
56
+ ##### Parameters
57
+
58
+ - `instance` The WebAssembly instance to interact with. Must
59
+ be instantiated from a Ruby built with JS extension, and built
60
+ with Reactor ABI instead of command line.
61
+
62
+ #### addToImports
63
+
64
+ Add intrinsic import entries, which is necessary to interact JavaScript
65
+ and Ruby's WebAssembly instance.
66
+
67
+ ##### Parameters
68
+
69
+ - `imports` The import object to add to the WebAssembly instance
70
+
71
+ #### printVersion
72
+
73
+ Print the Ruby version to stdout
74
+
75
+ #### eval
76
+
77
+ Runs a string of Ruby code from JavaScript
78
+
79
+ ##### Parameters
80
+
81
+ - `code` The Ruby code to run
82
+
83
+ ##### Examples
84
+
85
+ ```javascript
86
+ vm.eval("puts 'hello world'");
87
+ const result = vm.eval("1 + 2");
88
+ console.log(result.toString()); // 3
89
+ ```
90
+
91
+ Returns **any** the result of the last expression
92
+
93
+ #### evalAsync
94
+
95
+ Runs a string of Ruby code with top-level `JS::Object#await`
96
+ Returns a promise that resolves when execution completes.
97
+
98
+ ##### Parameters
99
+
100
+ - `code` The Ruby code to run
101
+
102
+ ##### Examples
103
+
104
+ ```javascript
105
+ const text = await vm.evalAsync(`
106
+ require 'js'
107
+ response = JS.global.fetch('https://example.com').await
108
+ response.text.await
109
+ `);
110
+ console.log(text.toString()); // <html>...</html>
111
+ ```
112
+
113
+ Returns **any** a promise that resolves to the result of the last expression
114
+
115
+ #### wrap
116
+
117
+ Wrap a JavaScript value into a Ruby JS::Object
118
+
119
+ ##### Parameters
120
+
121
+ - `value` The value to convert to RbValue
122
+
123
+ ##### Examples
124
+
125
+ ```javascript
126
+ const hash = vm.eval(`Hash.new`);
127
+ hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
128
+ ```
129
+
130
+ Returns **any** the RbValue object representing the given JS value
131
+
132
+ ### RbValue
133
+
134
+ A RbValue is an object that represents a value in Ruby
135
+
136
+ #### call
137
+
138
+ Call a given method with given arguments
139
+
140
+ ##### Parameters
141
+
142
+ - `callee` name of the Ruby method to call
143
+ - `args` **...any** arguments to pass to the method. Must be an array of RbValue
144
+
145
+ ##### Examples
146
+
147
+ ```javascript
148
+ const ary = vm.eval("[1, 2, 3]");
149
+ ary.call("push", 4);
150
+ console.log(ary.call("sample").toString());
151
+ ```
152
+
153
+ #### toPrimitive
154
+
155
+ - **See**: <https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive>
156
+
157
+ ##### Parameters
158
+
159
+ - `hint` Preferred type of the result primitive value. `"number"`, `"string"`, or `"default"`.
160
+
161
+ #### toString
162
+
163
+ Returns a string representation of the value by calling `to_s`
164
+
165
+ #### toJS
166
+
167
+ Returns a JavaScript object representation of the value
168
+ by calling `to_js`.
169
+
170
+ Returns null if the value is not convertible to a JavaScript object.
171
+
172
+ ### RbError
173
+
174
+ **Extends Error**
175
+
176
+ Error class thrown by Ruby execution
177
+
178
+ ### RbFatalError
179
+
180
+ **Extends RbError**
181
+
182
+ Error class thrown by Ruby execution when it is not possible to recover.
183
+ This is usually caused when Ruby VM is in an inconsistent state.