@ruby/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.
package/README.md CHANGED
@@ -16,235 +16,4 @@ See [Cheat Sheet](https://github.com/ruby/ruby.wasm/blob/main/docs/cheat_sheet.m
16
16
 
17
17
  ## API
18
18
 
19
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
20
-
21
- ### consolePrinter
22
-
23
- Create a console printer that can be used as an overlay of WASI imports.
24
- See the example below for how to use it.
25
-
26
- ```javascript
27
- const imports = {
28
- wasi_snapshot_preview1: wasi.wasiImport,
29
- };
30
- const printer = consolePrinter();
31
- printer.addToImports(imports);
32
-
33
- const instance = await WebAssembly.instantiate(module, imports);
34
- printer.setMemory(instance.exports.memory);
35
- ```
36
-
37
- Note that the `stdout` and `stderr` functions are called with text, not
38
- bytes. This means that bytes written to stdout/stderr will be decoded as
39
- UTF-8 and then passed to the `stdout`/`stderr` functions every time a write
40
- occurs without buffering.
41
-
42
- #### Parameters
43
-
44
- - `$0` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{stdout:console.log,stderr:console.warn}`)
45
-
46
- - `$0.stdout` &#x20;
47
- - `$0.stderr` &#x20;
48
-
49
- - `stdout` A function that will be called when stdout is written to.
50
- Defaults to `console.log`.
51
- - `stderr` A function that will be called when stderr is written to.
52
- Defaults to `console.warn`.
53
-
54
- Returns **any** An object that can be used as an overlay of WASI imports.
55
-
56
- ### RubyVM
57
-
58
- A Ruby VM instance
59
-
60
- #### Examples
61
-
62
- ```javascript
63
- const wasi = new WASI();
64
- const vm = new RubyVM();
65
- const imports = {
66
- wasi_snapshot_preview1: wasi.wasiImport,
67
- };
68
-
69
- vm.addToImports(imports);
70
-
71
- const instance = await WebAssembly.instantiate(rubyModule, imports);
72
- await vm.setInstance(instance);
73
- wasi.initialize(instance);
74
- vm.initialize();
75
- ```
76
-
77
- #### initialize
78
-
79
- Initialize the Ruby VM with the given command line arguments
80
-
81
- ##### Parameters
82
-
83
- - `args` The command line arguments to pass to Ruby. Must be
84
- an array of strings starting with the Ruby program name. (optional, default `["ruby.wasm","-EUTF-8","-e_=0"]`)
85
-
86
- #### setInstance
87
-
88
- Set a given instance to interact JavaScript and Ruby's
89
- WebAssembly instance. This method must be called before calling
90
- Ruby API.
91
-
92
- ##### Parameters
93
-
94
- - `instance` The WebAssembly instance to interact with. Must
95
- be instantiated from a Ruby built with JS extension, and built
96
- with Reactor ABI instead of command line.
97
-
98
- #### addToImports
99
-
100
- Add intrinsic import entries, which is necessary to interact JavaScript
101
- and Ruby's WebAssembly instance.
102
-
103
- ##### Parameters
104
-
105
- - `imports` The import object to add to the WebAssembly instance
106
-
107
- #### printVersion
108
-
109
- Print the Ruby version to stdout
110
-
111
- #### eval
112
-
113
- Runs a string of Ruby code from JavaScript
114
-
115
- ##### Parameters
116
-
117
- - `code` The Ruby code to run
118
-
119
- ##### Examples
120
-
121
- ```javascript
122
- vm.eval("puts 'hello world'");
123
- const result = vm.eval("1 + 2");
124
- console.log(result.toString()); // 3
125
- ```
126
-
127
- Returns **any** the result of the last expression
128
-
129
- #### evalAsync
130
-
131
- Runs a string of Ruby code with top-level `JS::Object#await`
132
- Returns a promise that resolves when execution completes.
133
-
134
- ##### Parameters
135
-
136
- - `code` The Ruby code to run
137
-
138
- ##### Examples
139
-
140
- ```javascript
141
- const text = await vm.evalAsync(`
142
- require 'js'
143
- response = JS.global.fetch('https://example.com').await
144
- response.text.await
145
- `);
146
- console.log(text.toString()); // <html>...</html>
147
- ```
148
-
149
- Returns **any** a promise that resolves to the result of the last expression
150
-
151
- #### wrap
152
-
153
- Wrap a JavaScript value into a Ruby JS::Object
154
-
155
- ##### Parameters
156
-
157
- - `value` The value to convert to RbValue
158
-
159
- ##### Examples
160
-
161
- ```javascript
162
- const hash = vm.eval(`Hash.new`);
163
- hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
164
- ```
165
-
166
- Returns **any** the RbValue object representing the given JS value
167
-
168
- ### RbValue
169
-
170
- A RbValue is an object that represents a value in Ruby
171
-
172
- #### call
173
-
174
- Call a given method with given arguments
175
-
176
- ##### Parameters
177
-
178
- - `callee` name of the Ruby method to call
179
- - `args` **...any** arguments to pass to the method. Must be an array of RbValue
180
-
181
- ##### Examples
182
-
183
- ```javascript
184
- const ary = vm.eval("[1, 2, 3]");
185
- ary.call("push", vm.wrap(4));
186
- console.log(ary.call("sample").toString());
187
- ```
188
-
189
- Returns **any** The result of the method call as a new RbValue.
190
-
191
- #### callAsync
192
-
193
- Call a given method that may call `JS::Object#await` with given arguments
194
-
195
- ##### Parameters
196
-
197
- - `callee` name of the Ruby method to call
198
- - `args` **...any** arguments to pass to the method. Must be an array of RbValue
199
-
200
- ##### Examples
201
-
202
- ```javascript
203
- const client = vm.eval(`
204
- require 'js'
205
- class HttpClient
206
- def get(url)
207
- JS.global.fetch(url).await
208
- end
209
- end
210
- HttpClient.new
211
- `);
212
- const response = await client.callAsync(
213
- "get",
214
- vm.eval(`"https://example.com"`),
215
- );
216
- ```
217
-
218
- Returns **any** A Promise that resolves to the result of the method call as a new RbValue.
219
-
220
- #### toPrimitive
221
-
222
- - **See**: <https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive>
223
-
224
- ##### Parameters
225
-
226
- - `hint` Preferred type of the result primitive value. `"number"`, `"string"`, or `"default"`.
227
-
228
- #### toString
229
-
230
- Returns a string representation of the value by calling `to_s`
231
-
232
- #### toJS
233
-
234
- Returns a JavaScript object representation of the value
235
- by calling `to_js`.
236
-
237
- Returns null if the value is not convertible to a JavaScript object.
238
-
239
- ### RbError
240
-
241
- **Extends Error**
242
-
243
- Error class thrown by Ruby execution
244
-
245
- ### RbFatalError
246
-
247
- **Extends RbError**
248
-
249
- Error class thrown by Ruby execution when it is not possible to recover.
250
- This is usually caused when Ruby VM is in an inconsistent state.
19
+ See [API Documentation](https://ruby.github.io/ruby.wasm/npm/@ruby/wasm-wasi/) for details.