@ruby/head-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.
- package/README.md +3 -332
- package/dist/browser.script.iife.js +774 -2685
- package/dist/browser.script.umd.js +172 -2050
- package/dist/browser.umd.js +170 -2048
- package/dist/cjs/browser.js +4 -0
- package/dist/cjs/browser.script.js +4 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/node.js +4 -0
- package/dist/esm/browser.js +1 -0
- package/dist/esm/browser.script.js +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/node.js +4 -0
- package/dist/esm/package.json +1 -0
- package/dist/index.umd.js +160 -12
- package/dist/ruby+stdlib.wasm +0 -0
- package/dist/ruby.debug+stdlib.wasm +0 -0
- package/dist/ruby.wasm +0 -0
- package/package.json +14 -31
- package/dist/bindgen/rb-abi-guest.d.ts +0 -140
- package/dist/bindgen/rb-js-abi-host.d.ts +0 -53
- package/dist/browser.cjs.js +0 -3248
- package/dist/browser.d.ts +0 -10
- package/dist/browser.esm.js +0 -3243
- package/dist/browser.script.cjs.js +0 -3375
- package/dist/browser.script.d.ts +0 -5
- package/dist/browser.script.esm.js +0 -3373
- package/dist/index.cjs.js +0 -1195
- package/dist/index.d.ts +0 -192
- package/dist/index.esm.js +0 -1190
- package/dist/node.cjs.js +0 -1212
- package/dist/node.d.ts +0 -10
- package/dist/node.esm.js +0 -1210
package/dist/index.d.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import * as RbAbi from "./bindgen/rb-abi-guest";
|
|
2
|
-
import { JsAbiValue } from "./bindgen/rb-js-abi-host";
|
|
3
|
-
/**
|
|
4
|
-
* A Ruby VM instance
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* const wasi = new WASI();
|
|
9
|
-
* const vm = new RubyVM();
|
|
10
|
-
* const imports = {
|
|
11
|
-
* wasi_snapshot_preview1: wasi.wasiImport,
|
|
12
|
-
* };
|
|
13
|
-
*
|
|
14
|
-
* vm.addToImports(imports);
|
|
15
|
-
*
|
|
16
|
-
* const instance = await WebAssembly.instantiate(rubyModule, imports);
|
|
17
|
-
* await vm.setInstance(instance);
|
|
18
|
-
* wasi.initialize(instance);
|
|
19
|
-
* vm.initialize();
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
export declare class RubyVM {
|
|
23
|
-
guest: RbAbi.RbAbiGuest;
|
|
24
|
-
private instance;
|
|
25
|
-
private transport;
|
|
26
|
-
private exceptionFormatter;
|
|
27
|
-
private interfaceState;
|
|
28
|
-
constructor();
|
|
29
|
-
/**
|
|
30
|
-
* Initialize the Ruby VM with the given command line arguments
|
|
31
|
-
* @param args The command line arguments to pass to Ruby. Must be
|
|
32
|
-
* an array of strings starting with the Ruby program name.
|
|
33
|
-
*/
|
|
34
|
-
initialize(args?: string[]): void;
|
|
35
|
-
/**
|
|
36
|
-
* Set a given instance to interact JavaScript and Ruby's
|
|
37
|
-
* WebAssembly instance. This method must be called before calling
|
|
38
|
-
* Ruby API.
|
|
39
|
-
*
|
|
40
|
-
* @param instance The WebAssembly instance to interact with. Must
|
|
41
|
-
* be instantiated from a Ruby built with JS extension, and built
|
|
42
|
-
* with Reactor ABI instead of command line.
|
|
43
|
-
*/
|
|
44
|
-
setInstance(instance: WebAssembly.Instance): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Add intrinsic import entries, which is necessary to interact JavaScript
|
|
47
|
-
* and Ruby's WebAssembly instance.
|
|
48
|
-
* @param imports The import object to add to the WebAssembly instance
|
|
49
|
-
*/
|
|
50
|
-
addToImports(imports: WebAssembly.Imports): void;
|
|
51
|
-
/**
|
|
52
|
-
* Print the Ruby version to stdout
|
|
53
|
-
*/
|
|
54
|
-
printVersion(): void;
|
|
55
|
-
/**
|
|
56
|
-
* Runs a string of Ruby code from JavaScript
|
|
57
|
-
* @param code The Ruby code to run
|
|
58
|
-
* @returns the result of the last expression
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* vm.eval("puts 'hello world'");
|
|
62
|
-
* const result = vm.eval("1 + 2");
|
|
63
|
-
* console.log(result.toString()); // 3
|
|
64
|
-
*
|
|
65
|
-
*/
|
|
66
|
-
eval(code: string): RbValue;
|
|
67
|
-
/**
|
|
68
|
-
* Runs a string of Ruby code with top-level `JS::Object#await`
|
|
69
|
-
* Returns a promise that resolves when execution completes.
|
|
70
|
-
* @param code The Ruby code to run
|
|
71
|
-
* @returns a promise that resolves to the result of the last expression
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* const text = await vm.evalAsync(`
|
|
75
|
-
* require 'js'
|
|
76
|
-
* response = JS.global.fetch('https://example.com').await
|
|
77
|
-
* response.text.await
|
|
78
|
-
* `);
|
|
79
|
-
* console.log(text.toString()); // <html>...</html>
|
|
80
|
-
*/
|
|
81
|
-
evalAsync(code: string): Promise<RbValue>;
|
|
82
|
-
/**
|
|
83
|
-
* Wrap a JavaScript value into a Ruby JS::Object
|
|
84
|
-
* @param value The value to convert to RbValue
|
|
85
|
-
* @returns the RbValue object representing the given JS value
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* const hash = vm.eval(`Hash.new`)
|
|
89
|
-
* hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
|
|
90
|
-
*/
|
|
91
|
-
wrap(value: any): RbValue;
|
|
92
|
-
private privateObject;
|
|
93
|
-
private rbValueOfPointer;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Export a JS value held by the Ruby VM to the JS environment.
|
|
97
|
-
* This is implemented in a dirty way since wit cannot reference resources
|
|
98
|
-
* defined in other interfaces.
|
|
99
|
-
* In our case, we can't express `function(v: rb-abi-value) -> js-abi-value`
|
|
100
|
-
* because `rb-js-abi-host.wit`, that defines `js-abi-value`, is implemented
|
|
101
|
-
* by embedder side (JS) but `rb-abi-guest.wit`, that defines `rb-abi-value`
|
|
102
|
-
* is implemented by guest side (Wasm).
|
|
103
|
-
*
|
|
104
|
-
* This class is a helper to export by:
|
|
105
|
-
* 1. Call `function __export_to_js(v: rb-abi-value)` defined in guest from embedder side.
|
|
106
|
-
* 2. Call `function takeJsValue(v: js-abi-value)` defined in embedder from guest side with
|
|
107
|
-
* underlying JS value of given `rb-abi-value`.
|
|
108
|
-
* 3. Then `takeJsValue` implementation escapes the given JS value to the `_takenJsValues`
|
|
109
|
-
* stored in embedder side.
|
|
110
|
-
* 4. Finally, embedder side can take `_takenJsValues`.
|
|
111
|
-
*
|
|
112
|
-
* Note that `exportJsValue` is not reentrant.
|
|
113
|
-
*
|
|
114
|
-
* @private
|
|
115
|
-
*/
|
|
116
|
-
declare class JsValueTransport {
|
|
117
|
-
private _takenJsValue;
|
|
118
|
-
takeJsValue(value: JsAbiValue): void;
|
|
119
|
-
consumeJsValue(): JsAbiValue;
|
|
120
|
-
exportJsValue(value: RbValue): JsAbiValue;
|
|
121
|
-
importJsValue(value: JsAbiValue, vm: RubyVM): RbValue;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* A RbValue is an object that represents a value in Ruby
|
|
125
|
-
*/
|
|
126
|
-
export declare class RbValue {
|
|
127
|
-
private inner;
|
|
128
|
-
private vm;
|
|
129
|
-
private privateObject;
|
|
130
|
-
/**
|
|
131
|
-
* @hideconstructor
|
|
132
|
-
*/
|
|
133
|
-
constructor(inner: RbAbi.RbAbiValue, vm: RubyVM, privateObject: RubyVMPrivate);
|
|
134
|
-
/**
|
|
135
|
-
* Call a given method with given arguments
|
|
136
|
-
*
|
|
137
|
-
* @param callee name of the Ruby method to call
|
|
138
|
-
* @param args arguments to pass to the method. Must be an array of RbValue
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* const ary = vm.eval("[1, 2, 3]");
|
|
142
|
-
* ary.call("push", 4);
|
|
143
|
-
* console.log(ary.call("sample").toString());
|
|
144
|
-
*
|
|
145
|
-
*/
|
|
146
|
-
call(callee: string, ...args: RbValue[]): RbValue;
|
|
147
|
-
/**
|
|
148
|
-
* @see {@link https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive}
|
|
149
|
-
* @param hint Preferred type of the result primitive value. `"number"`, `"string"`, or `"default"`.
|
|
150
|
-
*/
|
|
151
|
-
[Symbol.toPrimitive](hint: string): string;
|
|
152
|
-
/**
|
|
153
|
-
* Returns a string representation of the value by calling `to_s`
|
|
154
|
-
*/
|
|
155
|
-
toString(): string;
|
|
156
|
-
/**
|
|
157
|
-
* Returns a JavaScript object representation of the value
|
|
158
|
-
* by calling `to_js`.
|
|
159
|
-
*
|
|
160
|
-
* Returns null if the value is not convertible to a JavaScript object.
|
|
161
|
-
*/
|
|
162
|
-
toJS(): any;
|
|
163
|
-
}
|
|
164
|
-
type RubyVMPrivate = {
|
|
165
|
-
transport: JsValueTransport;
|
|
166
|
-
exceptionFormatter: RbExceptionFormatter;
|
|
167
|
-
};
|
|
168
|
-
declare class RbExceptionFormatter {
|
|
169
|
-
private literalsCache;
|
|
170
|
-
format(error: RbValue, vm: RubyVM, privateObject: RubyVMPrivate): string;
|
|
171
|
-
formatString(klass: string, message: string, backtrace?: [string, string]): string;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Error class thrown by Ruby execution
|
|
175
|
-
*/
|
|
176
|
-
export declare class RbError extends Error {
|
|
177
|
-
/**
|
|
178
|
-
* @hideconstructor
|
|
179
|
-
*/
|
|
180
|
-
constructor(message: string);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Error class thrown by Ruby execution when it is not possible to recover.
|
|
184
|
-
* This is usually caused when Ruby VM is in an inconsistent state.
|
|
185
|
-
*/
|
|
186
|
-
export declare class RbFatalError extends RbError {
|
|
187
|
-
/**
|
|
188
|
-
* @hideconstructor
|
|
189
|
-
*/
|
|
190
|
-
constructor(message: string);
|
|
191
|
-
}
|
|
192
|
-
export {};
|