@ruby/wasm-wasi 2.3.0-2023-12-03-a → 2.3.0-2023-12-04-a

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
@@ -1,8 +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 |
5
+ This package core API 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 |
6
12
  | ------- | -------------------------------------------------- |
7
13
  | `head` | [`@ruby/head-wasm-wasi`](./../ruby-head-wasm-wasi) |
8
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.
@@ -2969,12 +2969,14 @@
2969
2969
  wrap(value) {
2970
2970
  return this.transport.importJsValue(value, this);
2971
2971
  }
2972
+ /** @private */
2972
2973
  privateObject() {
2973
2974
  return {
2974
2975
  transport: this.transport,
2975
2976
  exceptionFormatter: this.exceptionFormatter,
2976
2977
  };
2977
2978
  }
2979
+ /** @private */
2978
2980
  rbValueOfPointer(pointer) {
2979
2981
  const abiValue = new RbAbiValue(pointer, this.guest);
2980
2982
  return new RbValue(abiValue, this, this.privateObject());
@@ -2927,12 +2927,14 @@
2927
2927
  wrap(value) {
2928
2928
  return this.transport.importJsValue(value, this);
2929
2929
  }
2930
+ /** @private */
2930
2931
  privateObject() {
2931
2932
  return {
2932
2933
  transport: this.transport,
2933
2934
  exceptionFormatter: this.exceptionFormatter,
2934
2935
  };
2935
2936
  }
2937
+ /** @private */
2936
2938
  rbValueOfPointer(pointer) {
2937
2939
  const abiValue = new RbAbiValue(pointer, this.guest);
2938
2940
  return new RbValue(abiValue, this, this.privateObject());
@@ -89,7 +89,9 @@ export declare class RubyVM {
89
89
  * hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
90
90
  */
91
91
  wrap(value: any): RbValue;
92
+ /** @private */
92
93
  private privateObject;
94
+ /** @private */
93
95
  private rbValueOfPointer;
94
96
  }
95
97
  /**
package/dist/cjs/index.js CHANGED
@@ -336,12 +336,14 @@ class RubyVM {
336
336
  wrap(value) {
337
337
  return this.transport.importJsValue(value, this);
338
338
  }
339
+ /** @private */
339
340
  privateObject() {
340
341
  return {
341
342
  transport: this.transport,
342
343
  exceptionFormatter: this.exceptionFormatter,
343
344
  };
344
345
  }
346
+ /** @private */
345
347
  rbValueOfPointer(pointer) {
346
348
  const abiValue = new RbAbi.RbAbiValue(pointer, this.guest);
347
349
  return new RbValue(abiValue, this, this.privateObject());
@@ -89,7 +89,9 @@ export declare class RubyVM {
89
89
  * hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
90
90
  */
91
91
  wrap(value: any): RbValue;
92
+ /** @private */
92
93
  private privateObject;
94
+ /** @private */
93
95
  private rbValueOfPointer;
94
96
  }
95
97
  /**
package/dist/esm/index.js CHANGED
@@ -332,12 +332,14 @@ export class RubyVM {
332
332
  wrap(value) {
333
333
  return this.transport.importJsValue(value, this);
334
334
  }
335
+ /** @private */
335
336
  privateObject() {
336
337
  return {
337
338
  transport: this.transport,
338
339
  exceptionFormatter: this.exceptionFormatter,
339
340
  };
340
341
  }
342
+ /** @private */
341
343
  rbValueOfPointer(pointer) {
342
344
  const abiValue = new RbAbi.RbAbiValue(pointer, this.guest);
343
345
  return new RbValue(abiValue, this, this.privateObject());
package/dist/index.umd.js CHANGED
@@ -933,12 +933,14 @@
933
933
  wrap(value) {
934
934
  return this.transport.importJsValue(value, this);
935
935
  }
936
+ /** @private */
936
937
  privateObject() {
937
938
  return {
938
939
  transport: this.transport,
939
940
  exceptionFormatter: this.exceptionFormatter,
940
941
  };
941
942
  }
943
+ /** @private */
942
944
  rbValueOfPointer(pointer) {
943
945
  const abiValue = new RbAbiValue(pointer, this.guest);
944
946
  return new RbValue(abiValue, this, this.privateObject());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruby/wasm-wasi",
3
- "version": "2.3.0-2023-12-03-a",
3
+ "version": "2.3.0-2023-12-04-a",
4
4
  "description": "WebAssembly port of CRuby with WASI",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",