@@ -18,6 +18,41 @@ See [Cheat Sheet](https://github.com/ruby/ruby.wasm/blob/main/docs/cheat_sheet.m
18
18
19
19
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
20
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 `   ;
47
+ - ` $0.stderr `   ;
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
+
21
56
### RubyVM
22
57
23
58
A Ruby VM instance
@@ -46,7 +81,7 @@ Initialize the Ruby VM with the given command line arguments
46
81
##### Parameters
47
82
48
83
- ` args ` The command line arguments to pass to Ruby. Must be
49
- an array of strings starting with the Ruby program name. (optional, default ` ["ruby.wasm","--disable-gems","- EUTF-8","-e_=0"] ` )
84
+ an array of strings starting with the Ruby program name. (optional, default ` ["ruby.wasm","-EUTF-8","-e_=0"] ` )
50
85
51
86
#### setInstance
52
87
@@ -151,6 +186,37 @@ ary.call("push", 4);
151
186
console .log (ary .call (" sample" ).toString ());
152
187
```
153
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
+
154
220
#### toPrimitive
155
221
156
222
- ** See** : < https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive >
0 commit comments