@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
@@ -0,0 +1,13 @@
1
+ export function data_view(mem: any): DataView;
2
+ export function to_uint32(val: any): number;
3
+ export function utf8_encode(s: any, realloc: any, memory: any): number;
4
+ export function throw_invalid_bool(): void;
5
+ export const UTF8_DECODER: TextDecoder;
6
+ export let UTF8_ENCODED_LEN: number;
7
+ export class Slab {
8
+ list: any[];
9
+ head: number;
10
+ insert(val: any): number;
11
+ get(idx: any): any;
12
+ remove(idx: any): any;
13
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throw_invalid_bool = exports.Slab = exports.UTF8_ENCODED_LEN = exports.utf8_encode = exports.UTF8_DECODER = exports.to_uint32 = exports.data_view = void 0;
4
+ let DATA_VIEW = new DataView(new ArrayBuffer());
5
+ function data_view(mem) {
6
+ if (DATA_VIEW.buffer !== mem.buffer)
7
+ DATA_VIEW = new DataView(mem.buffer);
8
+ return DATA_VIEW;
9
+ }
10
+ exports.data_view = data_view;
11
+ function to_uint32(val) {
12
+ return val >>> 0;
13
+ }
14
+ exports.to_uint32 = to_uint32;
15
+ exports.UTF8_DECODER = new TextDecoder('utf-8');
16
+ const UTF8_ENCODER = new TextEncoder('utf-8');
17
+ function utf8_encode(s, realloc, memory) {
18
+ if (typeof s !== 'string')
19
+ throw new TypeError('expected a string');
20
+ if (s.length === 0) {
21
+ exports.UTF8_ENCODED_LEN = 0;
22
+ return 1;
23
+ }
24
+ let alloc_len = 0;
25
+ let ptr = 0;
26
+ let writtenTotal = 0;
27
+ while (s.length > 0) {
28
+ ptr = realloc(ptr, alloc_len, 1, alloc_len + s.length);
29
+ alloc_len += s.length;
30
+ const { read, written } = UTF8_ENCODER.encodeInto(s, new Uint8Array(memory.buffer, ptr + writtenTotal, alloc_len - writtenTotal));
31
+ writtenTotal += written;
32
+ s = s.slice(read);
33
+ }
34
+ if (alloc_len > writtenTotal)
35
+ ptr = realloc(ptr, alloc_len, 1, writtenTotal);
36
+ exports.UTF8_ENCODED_LEN = writtenTotal;
37
+ return ptr;
38
+ }
39
+ exports.utf8_encode = utf8_encode;
40
+ exports.UTF8_ENCODED_LEN = 0;
41
+ class Slab {
42
+ constructor() {
43
+ this.list = [];
44
+ this.head = 0;
45
+ }
46
+ insert(val) {
47
+ if (this.head >= this.list.length) {
48
+ this.list.push({
49
+ next: this.list.length + 1,
50
+ val: undefined,
51
+ });
52
+ }
53
+ const ret = this.head;
54
+ const slot = this.list[ret];
55
+ this.head = slot.next;
56
+ slot.next = -1;
57
+ slot.val = val;
58
+ return ret;
59
+ }
60
+ get(idx) {
61
+ if (idx >= this.list.length)
62
+ throw new RangeError('handle index not valid');
63
+ const slot = this.list[idx];
64
+ if (slot.next === -1)
65
+ return slot.val;
66
+ throw new RangeError('handle index not valid');
67
+ }
68
+ remove(idx) {
69
+ const ret = this.get(idx); // validate the slot
70
+ const slot = this.list[idx];
71
+ slot.val = undefined;
72
+ slot.next = this.head;
73
+ this.head = idx;
74
+ return ret;
75
+ }
76
+ }
77
+ exports.Slab = Slab;
78
+ function throw_invalid_bool() {
79
+ throw new RangeError("invalid variant discriminant for bool");
80
+ }
81
+ exports.throw_invalid_bool = throw_invalid_bool;
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RbAbiValue = exports.RbIseq = exports.RbAbiGuest = void 0;
4
+ const intrinsics_js_1 = require("./intrinsics.js");
5
+ class RbAbiGuest {
6
+ constructor() {
7
+ this._resource0_slab = new intrinsics_js_1.Slab();
8
+ this._resource1_slab = new intrinsics_js_1.Slab();
9
+ }
10
+ addToImports(imports) {
11
+ if (!("canonical_abi" in imports))
12
+ imports["canonical_abi"] = {};
13
+ imports.canonical_abi['resource_drop_rb-iseq'] = i => {
14
+ this._resource0_slab.remove(i).drop();
15
+ };
16
+ imports.canonical_abi['resource_clone_rb-iseq'] = i => {
17
+ const obj = this._resource0_slab.get(i);
18
+ return this._resource0_slab.insert(obj.clone());
19
+ };
20
+ imports.canonical_abi['resource_get_rb-iseq'] = i => {
21
+ return this._resource0_slab.get(i)._wasm_val;
22
+ };
23
+ imports.canonical_abi['resource_new_rb-iseq'] = i => {
24
+ const registry = this._registry0;
25
+ return this._resource0_slab.insert(new RbIseq(i, this));
26
+ };
27
+ imports.canonical_abi['resource_drop_rb-abi-value'] = i => {
28
+ this._resource1_slab.remove(i).drop();
29
+ };
30
+ imports.canonical_abi['resource_clone_rb-abi-value'] = i => {
31
+ const obj = this._resource1_slab.get(i);
32
+ return this._resource1_slab.insert(obj.clone());
33
+ };
34
+ imports.canonical_abi['resource_get_rb-abi-value'] = i => {
35
+ return this._resource1_slab.get(i)._wasm_val;
36
+ };
37
+ imports.canonical_abi['resource_new_rb-abi-value'] = i => {
38
+ const registry = this._registry1;
39
+ return this._resource1_slab.insert(new RbAbiValue(i, this));
40
+ };
41
+ }
42
+ async instantiate(module, imports) {
43
+ imports = imports || {};
44
+ this.addToImports(imports);
45
+ if (module instanceof WebAssembly.Instance) {
46
+ this.instance = module;
47
+ }
48
+ else if (module instanceof WebAssembly.Module) {
49
+ this.instance = await WebAssembly.instantiate(module, imports);
50
+ }
51
+ else if (module instanceof ArrayBuffer || module instanceof Uint8Array) {
52
+ const { instance } = await WebAssembly.instantiate(module, imports);
53
+ this.instance = instance;
54
+ }
55
+ else {
56
+ const { instance } = await WebAssembly.instantiateStreaming(module, imports);
57
+ this.instance = instance;
58
+ }
59
+ this._exports = this.instance.exports;
60
+ this._registry0 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-iseq']);
61
+ this._registry1 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-abi-value']);
62
+ }
63
+ rubyShowVersion() {
64
+ this._exports['ruby-show-version: func() -> ()']();
65
+ }
66
+ rubyInit() {
67
+ this._exports['ruby-init: func() -> ()']();
68
+ }
69
+ rubySysinit(arg0) {
70
+ const memory = this._exports.memory;
71
+ const realloc = this._exports["cabi_realloc"];
72
+ const vec1 = arg0;
73
+ const len1 = vec1.length;
74
+ const result1 = realloc(0, 0, 4, len1 * 8);
75
+ for (let i = 0; i < vec1.length; i++) {
76
+ const e = vec1[i];
77
+ const base = result1 + i * 8;
78
+ const ptr0 = (0, intrinsics_js_1.utf8_encode)(e, realloc, memory);
79
+ const len0 = intrinsics_js_1.UTF8_ENCODED_LEN;
80
+ (0, intrinsics_js_1.data_view)(memory).setInt32(base + 4, len0, true);
81
+ (0, intrinsics_js_1.data_view)(memory).setInt32(base + 0, ptr0, true);
82
+ }
83
+ this._exports['ruby-sysinit: func(args: list<string>) -> ()'](result1, len1);
84
+ }
85
+ rubyOptions(arg0) {
86
+ const memory = this._exports.memory;
87
+ const realloc = this._exports["cabi_realloc"];
88
+ const vec1 = arg0;
89
+ const len1 = vec1.length;
90
+ const result1 = realloc(0, 0, 4, len1 * 8);
91
+ for (let i = 0; i < vec1.length; i++) {
92
+ const e = vec1[i];
93
+ const base = result1 + i * 8;
94
+ const ptr0 = (0, intrinsics_js_1.utf8_encode)(e, realloc, memory);
95
+ const len0 = intrinsics_js_1.UTF8_ENCODED_LEN;
96
+ (0, intrinsics_js_1.data_view)(memory).setInt32(base + 4, len0, true);
97
+ (0, intrinsics_js_1.data_view)(memory).setInt32(base + 0, ptr0, true);
98
+ }
99
+ const ret = this._exports['ruby-options: func(args: list<string>) -> handle<rb-iseq>'](result1, len1);
100
+ return this._resource0_slab.remove(ret);
101
+ }
102
+ rubyScript(arg0) {
103
+ const memory = this._exports.memory;
104
+ const realloc = this._exports["cabi_realloc"];
105
+ const ptr0 = (0, intrinsics_js_1.utf8_encode)(arg0, realloc, memory);
106
+ const len0 = intrinsics_js_1.UTF8_ENCODED_LEN;
107
+ this._exports['ruby-script: func(name: string) -> ()'](ptr0, len0);
108
+ }
109
+ rubyInitLoadpath() {
110
+ this._exports['ruby-init-loadpath: func() -> ()']();
111
+ }
112
+ rbEvalStringProtect(arg0) {
113
+ const memory = this._exports.memory;
114
+ const realloc = this._exports["cabi_realloc"];
115
+ const ptr0 = (0, intrinsics_js_1.utf8_encode)(arg0, realloc, memory);
116
+ const len0 = intrinsics_js_1.UTF8_ENCODED_LEN;
117
+ const ret = this._exports['rb-eval-string-protect: func(str: string) -> tuple<handle<rb-abi-value>, s32>'](ptr0, len0);
118
+ return [this._resource1_slab.remove((0, intrinsics_js_1.data_view)(memory).getInt32(ret + 0, true)), (0, intrinsics_js_1.data_view)(memory).getInt32(ret + 4, true)];
119
+ }
120
+ rbFuncallvProtect(arg0, arg1, arg2) {
121
+ const memory = this._exports.memory;
122
+ const realloc = this._exports["cabi_realloc"];
123
+ const obj0 = arg0;
124
+ if (!(obj0 instanceof RbAbiValue))
125
+ throw new TypeError('expected instance of RbAbiValue');
126
+ const vec2 = arg2;
127
+ const len2 = vec2.length;
128
+ const result2 = realloc(0, 0, 4, len2 * 4);
129
+ for (let i = 0; i < vec2.length; i++) {
130
+ const e = vec2[i];
131
+ const base = result2 + i * 4;
132
+ const obj1 = e;
133
+ if (!(obj1 instanceof RbAbiValue))
134
+ throw new TypeError('expected instance of RbAbiValue');
135
+ (0, intrinsics_js_1.data_view)(memory).setInt32(base + 0, this._resource1_slab.insert(obj1.clone()), true);
136
+ }
137
+ const ret = this._exports['rb-funcallv-protect: func(recv: handle<rb-abi-value>, mid: u32, args: list<handle<rb-abi-value>>) -> tuple<handle<rb-abi-value>, s32>'](this._resource1_slab.insert(obj0.clone()), (0, intrinsics_js_1.to_uint32)(arg1), result2, len2);
138
+ return [this._resource1_slab.remove((0, intrinsics_js_1.data_view)(memory).getInt32(ret + 0, true)), (0, intrinsics_js_1.data_view)(memory).getInt32(ret + 4, true)];
139
+ }
140
+ rbIntern(arg0) {
141
+ const memory = this._exports.memory;
142
+ const realloc = this._exports["cabi_realloc"];
143
+ const ptr0 = (0, intrinsics_js_1.utf8_encode)(arg0, realloc, memory);
144
+ const len0 = intrinsics_js_1.UTF8_ENCODED_LEN;
145
+ const ret = this._exports['rb-intern: func(name: string) -> u32'](ptr0, len0);
146
+ return ret >>> 0;
147
+ }
148
+ rbErrinfo() {
149
+ const ret = this._exports['rb-errinfo: func() -> handle<rb-abi-value>']();
150
+ return this._resource1_slab.remove(ret);
151
+ }
152
+ rbClearErrinfo() {
153
+ this._exports['rb-clear-errinfo: func() -> ()']();
154
+ }
155
+ rstringPtr(arg0) {
156
+ const memory = this._exports.memory;
157
+ const obj0 = arg0;
158
+ if (!(obj0 instanceof RbAbiValue))
159
+ throw new TypeError('expected instance of RbAbiValue');
160
+ const ret = this._exports['rstring-ptr: func(value: handle<rb-abi-value>) -> string'](this._resource1_slab.insert(obj0.clone()));
161
+ const ptr1 = (0, intrinsics_js_1.data_view)(memory).getInt32(ret + 0, true);
162
+ const len1 = (0, intrinsics_js_1.data_view)(memory).getInt32(ret + 4, true);
163
+ const result1 = intrinsics_js_1.UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1));
164
+ this._exports["cabi_post_rstring-ptr"](ret);
165
+ return result1;
166
+ }
167
+ rbVmBugreport() {
168
+ this._exports['rb-vm-bugreport: func() -> ()']();
169
+ }
170
+ rbGcEnable() {
171
+ const ret = this._exports['rb-gc-enable: func() -> bool']();
172
+ const bool0 = ret;
173
+ return bool0 == 0 ? false : (bool0 == 1 ? true : (0, intrinsics_js_1.throw_invalid_bool)());
174
+ }
175
+ rbGcDisable() {
176
+ const ret = this._exports['rb-gc-disable: func() -> bool']();
177
+ const bool0 = ret;
178
+ return bool0 == 0 ? false : (bool0 == 1 ? true : (0, intrinsics_js_1.throw_invalid_bool)());
179
+ }
180
+ rbSetShouldProhibitRewind(arg0) {
181
+ const ret = this._exports['rb-set-should-prohibit-rewind: func(new-value: bool) -> bool'](arg0 ? 1 : 0);
182
+ const bool0 = ret;
183
+ return bool0 == 0 ? false : (bool0 == 1 ? true : (0, intrinsics_js_1.throw_invalid_bool)());
184
+ }
185
+ }
186
+ exports.RbAbiGuest = RbAbiGuest;
187
+ class RbIseq {
188
+ constructor(wasm_val, obj) {
189
+ this._wasm_val = wasm_val;
190
+ this._obj = obj;
191
+ this._refcnt = 1;
192
+ obj._registry0.register(this, wasm_val, this);
193
+ }
194
+ clone() {
195
+ this._refcnt += 1;
196
+ return this;
197
+ }
198
+ drop() {
199
+ this._refcnt -= 1;
200
+ if (this._refcnt !== 0)
201
+ return;
202
+ this._obj._registry0.unregister(this);
203
+ const dtor = this._obj._exports['canonical_abi_drop_rb-iseq'];
204
+ const wasm_val = this._wasm_val;
205
+ delete this._obj;
206
+ delete this._refcnt;
207
+ delete this._wasm_val;
208
+ dtor(wasm_val);
209
+ }
210
+ }
211
+ exports.RbIseq = RbIseq;
212
+ class RbAbiValue {
213
+ constructor(wasm_val, obj) {
214
+ this._wasm_val = wasm_val;
215
+ this._obj = obj;
216
+ this._refcnt = 1;
217
+ obj._registry1.register(this, wasm_val, this);
218
+ }
219
+ clone() {
220
+ this._refcnt += 1;
221
+ return this;
222
+ }
223
+ drop() {
224
+ this._refcnt -= 1;
225
+ if (this._refcnt !== 0)
226
+ return;
227
+ this._obj._registry1.unregister(this);
228
+ const dtor = this._obj._exports['canonical_abi_drop_rb-abi-value'];
229
+ const wasm_val = this._wasm_val;
230
+ delete this._obj;
231
+ delete this._refcnt;
232
+ delete this._wasm_val;
233
+ dtor(wasm_val);
234
+ }
235
+ }
236
+ exports.RbAbiValue = RbAbiValue;
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addRbJsAbiHostToImports = void 0;
4
+ const intrinsics_js_1 = require("./intrinsics.js");
5
+ function addRbJsAbiHostToImports(imports, obj, get_export) {
6
+ if (!("rb-js-abi-host" in imports))
7
+ imports["rb-js-abi-host"] = {};
8
+ imports["rb-js-abi-host"]["eval-js: func(code: string) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }"] = function (arg0, arg1, arg2) {
9
+ const memory = get_export("memory");
10
+ const ptr0 = arg0;
11
+ const len0 = arg1;
12
+ const result0 = intrinsics_js_1.UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
13
+ const ret0 = obj.evalJs(result0);
14
+ const variant1 = ret0;
15
+ switch (variant1.tag) {
16
+ case "success": {
17
+ const e = variant1.val;
18
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg2 + 0, 0, true);
19
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg2 + 4, resources0.insert(e), true);
20
+ break;
21
+ }
22
+ case "failure": {
23
+ const e = variant1.val;
24
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg2 + 0, 1, true);
25
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg2 + 4, resources0.insert(e), true);
26
+ break;
27
+ }
28
+ default:
29
+ throw new RangeError("invalid variant specified for JsAbiResult");
30
+ }
31
+ };
32
+ imports["rb-js-abi-host"]["is-js: func(value: handle<js-abi-value>) -> bool"] = function (arg0) {
33
+ const ret0 = obj.isJs(resources0.get(arg0));
34
+ return ret0 ? 1 : 0;
35
+ };
36
+ imports["rb-js-abi-host"]["instance-of: func(value: handle<js-abi-value>, klass: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
37
+ const ret0 = obj.instanceOf(resources0.get(arg0), resources0.get(arg1));
38
+ return ret0 ? 1 : 0;
39
+ };
40
+ imports["rb-js-abi-host"]["global-this: func() -> handle<js-abi-value>"] = function () {
41
+ const ret0 = obj.globalThis();
42
+ return resources0.insert(ret0);
43
+ };
44
+ imports["rb-js-abi-host"]["int-to-js-number: func(value: s32) -> handle<js-abi-value>"] = function (arg0) {
45
+ const ret0 = obj.intToJsNumber(arg0);
46
+ return resources0.insert(ret0);
47
+ };
48
+ imports["rb-js-abi-host"]["float-to-js-number: func(value: float64) -> handle<js-abi-value>"] = function (arg0) {
49
+ const ret0 = obj.floatToJsNumber(arg0);
50
+ return resources0.insert(ret0);
51
+ };
52
+ imports["rb-js-abi-host"]["string-to-js-string: func(value: string) -> handle<js-abi-value>"] = function (arg0, arg1) {
53
+ const memory = get_export("memory");
54
+ const ptr0 = arg0;
55
+ const len0 = arg1;
56
+ const result0 = intrinsics_js_1.UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
57
+ const ret0 = obj.stringToJsString(result0);
58
+ return resources0.insert(ret0);
59
+ };
60
+ imports["rb-js-abi-host"]["bool-to-js-bool: func(value: bool) -> handle<js-abi-value>"] = function (arg0) {
61
+ const bool0 = arg0;
62
+ const ret0 = obj.boolToJsBool(bool0 == 0 ? false : (bool0 == 1 ? true : (0, intrinsics_js_1.throw_invalid_bool)()));
63
+ return resources0.insert(ret0);
64
+ };
65
+ imports["rb-js-abi-host"]["proc-to-js-function: func(value: u32) -> handle<js-abi-value>"] = function (arg0) {
66
+ const ret0 = obj.procToJsFunction(arg0 >>> 0);
67
+ return resources0.insert(ret0);
68
+ };
69
+ imports["rb-js-abi-host"]["rb-object-to-js-rb-value: func(raw-rb-abi-value: u32) -> handle<js-abi-value>"] = function (arg0) {
70
+ const ret0 = obj.rbObjectToJsRbValue(arg0 >>> 0);
71
+ return resources0.insert(ret0);
72
+ };
73
+ imports["rb-js-abi-host"]["js-value-to-string: func(value: handle<js-abi-value>) -> string"] = function (arg0, arg1) {
74
+ const memory = get_export("memory");
75
+ const realloc = get_export("cabi_realloc");
76
+ const ret0 = obj.jsValueToString(resources0.get(arg0));
77
+ const ptr0 = (0, intrinsics_js_1.utf8_encode)(ret0, realloc, memory);
78
+ const len0 = intrinsics_js_1.UTF8_ENCODED_LEN;
79
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg1 + 4, len0, true);
80
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg1 + 0, ptr0, true);
81
+ };
82
+ imports["rb-js-abi-host"]["js-value-to-integer: func(value: handle<js-abi-value>) -> variant { f64(float64), bignum(string) }"] = function (arg0, arg1) {
83
+ const memory = get_export("memory");
84
+ const realloc = get_export("cabi_realloc");
85
+ const ret0 = obj.jsValueToInteger(resources0.get(arg0));
86
+ const variant1 = ret0;
87
+ switch (variant1.tag) {
88
+ case "f64": {
89
+ const e = variant1.val;
90
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg1 + 0, 0, true);
91
+ (0, intrinsics_js_1.data_view)(memory).setFloat64(arg1 + 8, +e, true);
92
+ break;
93
+ }
94
+ case "bignum": {
95
+ const e = variant1.val;
96
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg1 + 0, 1, true);
97
+ const ptr0 = (0, intrinsics_js_1.utf8_encode)(e, realloc, memory);
98
+ const len0 = intrinsics_js_1.UTF8_ENCODED_LEN;
99
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg1 + 12, len0, true);
100
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg1 + 8, ptr0, true);
101
+ break;
102
+ }
103
+ default:
104
+ throw new RangeError("invalid variant specified for RawInteger");
105
+ }
106
+ };
107
+ imports["rb-js-abi-host"]["export-js-value-to-host: func(value: handle<js-abi-value>) -> ()"] = function (arg0) {
108
+ obj.exportJsValueToHost(resources0.get(arg0));
109
+ };
110
+ imports["rb-js-abi-host"]["import-js-value-from-host: func() -> handle<js-abi-value>"] = function () {
111
+ const ret0 = obj.importJsValueFromHost();
112
+ return resources0.insert(ret0);
113
+ };
114
+ imports["rb-js-abi-host"]["js-value-typeof: func(value: handle<js-abi-value>) -> string"] = function (arg0, arg1) {
115
+ const memory = get_export("memory");
116
+ const realloc = get_export("cabi_realloc");
117
+ const ret0 = obj.jsValueTypeof(resources0.get(arg0));
118
+ const ptr0 = (0, intrinsics_js_1.utf8_encode)(ret0, realloc, memory);
119
+ const len0 = intrinsics_js_1.UTF8_ENCODED_LEN;
120
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg1 + 4, len0, true);
121
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg1 + 0, ptr0, true);
122
+ };
123
+ imports["rb-js-abi-host"]["js-value-equal: func(lhs: handle<js-abi-value>, rhs: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
124
+ const ret0 = obj.jsValueEqual(resources0.get(arg0), resources0.get(arg1));
125
+ return ret0 ? 1 : 0;
126
+ };
127
+ imports["rb-js-abi-host"]["js-value-strictly-equal: func(lhs: handle<js-abi-value>, rhs: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
128
+ const ret0 = obj.jsValueStrictlyEqual(resources0.get(arg0), resources0.get(arg1));
129
+ return ret0 ? 1 : 0;
130
+ };
131
+ imports["rb-js-abi-host"]["reflect-apply: func(target: handle<js-abi-value>, this-argument: handle<js-abi-value>, arguments: list<handle<js-abi-value>>) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }"] = function (arg0, arg1, arg2, arg3, arg4) {
132
+ const memory = get_export("memory");
133
+ const len0 = arg3;
134
+ const base0 = arg2;
135
+ const result0 = [];
136
+ for (let i = 0; i < len0; i++) {
137
+ const base = base0 + i * 4;
138
+ result0.push(resources0.get((0, intrinsics_js_1.data_view)(memory).getInt32(base + 0, true)));
139
+ }
140
+ const ret0 = obj.reflectApply(resources0.get(arg0), resources0.get(arg1), result0);
141
+ const variant1 = ret0;
142
+ switch (variant1.tag) {
143
+ case "success": {
144
+ const e = variant1.val;
145
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg4 + 0, 0, true);
146
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg4 + 4, resources0.insert(e), true);
147
+ break;
148
+ }
149
+ case "failure": {
150
+ const e = variant1.val;
151
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg4 + 0, 1, true);
152
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg4 + 4, resources0.insert(e), true);
153
+ break;
154
+ }
155
+ default:
156
+ throw new RangeError("invalid variant specified for JsAbiResult");
157
+ }
158
+ };
159
+ imports["rb-js-abi-host"]["reflect-construct: func(target: handle<js-abi-value>, arguments: list<handle<js-abi-value>>) -> handle<js-abi-value>"] = function (arg0, arg1, arg2) {
160
+ const memory = get_export("memory");
161
+ const len0 = arg2;
162
+ const base0 = arg1;
163
+ const result0 = [];
164
+ for (let i = 0; i < len0; i++) {
165
+ const base = base0 + i * 4;
166
+ result0.push(resources0.get((0, intrinsics_js_1.data_view)(memory).getInt32(base + 0, true)));
167
+ }
168
+ const ret0 = obj.reflectConstruct(resources0.get(arg0), result0);
169
+ return resources0.insert(ret0);
170
+ };
171
+ imports["rb-js-abi-host"]["reflect-delete-property: func(target: handle<js-abi-value>, property-key: string) -> bool"] = function (arg0, arg1, arg2) {
172
+ const memory = get_export("memory");
173
+ const ptr0 = arg1;
174
+ const len0 = arg2;
175
+ const result0 = intrinsics_js_1.UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
176
+ const ret0 = obj.reflectDeleteProperty(resources0.get(arg0), result0);
177
+ return ret0 ? 1 : 0;
178
+ };
179
+ imports["rb-js-abi-host"]["reflect-get: func(target: handle<js-abi-value>, property-key: string) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }"] = function (arg0, arg1, arg2, arg3) {
180
+ const memory = get_export("memory");
181
+ const ptr0 = arg1;
182
+ const len0 = arg2;
183
+ const result0 = intrinsics_js_1.UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
184
+ const ret0 = obj.reflectGet(resources0.get(arg0), result0);
185
+ const variant1 = ret0;
186
+ switch (variant1.tag) {
187
+ case "success": {
188
+ const e = variant1.val;
189
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg3 + 0, 0, true);
190
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg3 + 4, resources0.insert(e), true);
191
+ break;
192
+ }
193
+ case "failure": {
194
+ const e = variant1.val;
195
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg3 + 0, 1, true);
196
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg3 + 4, resources0.insert(e), true);
197
+ break;
198
+ }
199
+ default:
200
+ throw new RangeError("invalid variant specified for JsAbiResult");
201
+ }
202
+ };
203
+ imports["rb-js-abi-host"]["reflect-get-own-property-descriptor: func(target: handle<js-abi-value>, property-key: string) -> handle<js-abi-value>"] = function (arg0, arg1, arg2) {
204
+ const memory = get_export("memory");
205
+ const ptr0 = arg1;
206
+ const len0 = arg2;
207
+ const result0 = intrinsics_js_1.UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
208
+ const ret0 = obj.reflectGetOwnPropertyDescriptor(resources0.get(arg0), result0);
209
+ return resources0.insert(ret0);
210
+ };
211
+ imports["rb-js-abi-host"]["reflect-get-prototype-of: func(target: handle<js-abi-value>) -> handle<js-abi-value>"] = function (arg0) {
212
+ const ret0 = obj.reflectGetPrototypeOf(resources0.get(arg0));
213
+ return resources0.insert(ret0);
214
+ };
215
+ imports["rb-js-abi-host"]["reflect-has: func(target: handle<js-abi-value>, property-key: string) -> bool"] = function (arg0, arg1, arg2) {
216
+ const memory = get_export("memory");
217
+ const ptr0 = arg1;
218
+ const len0 = arg2;
219
+ const result0 = intrinsics_js_1.UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
220
+ const ret0 = obj.reflectHas(resources0.get(arg0), result0);
221
+ return ret0 ? 1 : 0;
222
+ };
223
+ imports["rb-js-abi-host"]["reflect-is-extensible: func(target: handle<js-abi-value>) -> bool"] = function (arg0) {
224
+ const ret0 = obj.reflectIsExtensible(resources0.get(arg0));
225
+ return ret0 ? 1 : 0;
226
+ };
227
+ imports["rb-js-abi-host"]["reflect-own-keys: func(target: handle<js-abi-value>) -> list<handle<js-abi-value>>"] = function (arg0, arg1) {
228
+ const memory = get_export("memory");
229
+ const realloc = get_export("cabi_realloc");
230
+ const ret0 = obj.reflectOwnKeys(resources0.get(arg0));
231
+ const vec0 = ret0;
232
+ const len0 = vec0.length;
233
+ const result0 = realloc(0, 0, 4, len0 * 4);
234
+ for (let i = 0; i < vec0.length; i++) {
235
+ const e = vec0[i];
236
+ const base = result0 + i * 4;
237
+ (0, intrinsics_js_1.data_view)(memory).setInt32(base + 0, resources0.insert(e), true);
238
+ }
239
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg1 + 4, len0, true);
240
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg1 + 0, result0, true);
241
+ };
242
+ imports["rb-js-abi-host"]["reflect-prevent-extensions: func(target: handle<js-abi-value>) -> bool"] = function (arg0) {
243
+ const ret0 = obj.reflectPreventExtensions(resources0.get(arg0));
244
+ return ret0 ? 1 : 0;
245
+ };
246
+ imports["rb-js-abi-host"]["reflect-set: func(target: handle<js-abi-value>, property-key: string, value: handle<js-abi-value>) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }"] = function (arg0, arg1, arg2, arg3, arg4) {
247
+ const memory = get_export("memory");
248
+ const ptr0 = arg1;
249
+ const len0 = arg2;
250
+ const result0 = intrinsics_js_1.UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
251
+ const ret0 = obj.reflectSet(resources0.get(arg0), result0, resources0.get(arg3));
252
+ const variant1 = ret0;
253
+ switch (variant1.tag) {
254
+ case "success": {
255
+ const e = variant1.val;
256
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg4 + 0, 0, true);
257
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg4 + 4, resources0.insert(e), true);
258
+ break;
259
+ }
260
+ case "failure": {
261
+ const e = variant1.val;
262
+ (0, intrinsics_js_1.data_view)(memory).setInt8(arg4 + 0, 1, true);
263
+ (0, intrinsics_js_1.data_view)(memory).setInt32(arg4 + 4, resources0.insert(e), true);
264
+ break;
265
+ }
266
+ default:
267
+ throw new RangeError("invalid variant specified for JsAbiResult");
268
+ }
269
+ };
270
+ imports["rb-js-abi-host"]["reflect-set-prototype-of: func(target: handle<js-abi-value>, prototype: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
271
+ const ret0 = obj.reflectSetPrototypeOf(resources0.get(arg0), resources0.get(arg1));
272
+ return ret0 ? 1 : 0;
273
+ };
274
+ if (!("canonical_abi" in imports))
275
+ imports["canonical_abi"] = {};
276
+ const resources0 = new intrinsics_js_1.Slab();
277
+ imports.canonical_abi["resource_drop_js-abi-value"] = (i) => {
278
+ const val = resources0.remove(i);
279
+ if (obj.dropJsAbiValue)
280
+ obj.dropJsAbiValue(val);
281
+ };
282
+ }
283
+ exports.addRbJsAbiHostToImports = addRbJsAbiHostToImports;
@@ -1,5 +1,5 @@
1
- import { WASI } from "@wasmer/wasi";
2
- import { RubyVM } from "./index";
1
+ import { WASI } from "@bjorn3/browser_wasi_shim";
2
+ import { RubyVM } from "./index.js";
3
3
  export declare const DefaultRubyVM: (rubyModule: WebAssembly.Module, options?: {
4
4
  consolePrint?: boolean;
5
5
  env?: Record<string, string> | undefined;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultRubyVM = void 0;
4
+ const browser_wasi_shim_1 = require("@bjorn3/browser_wasi_shim");
5
+ const index_js_1 = require("./index.js");
6
+ const DefaultRubyVM = async (rubyModule, options = {}) => {
7
+ var _a, _b;
8
+ const args = [];
9
+ const env = Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}).map(([k, v]) => `${k}=${v}`);
10
+ const fds = [];
11
+ const wasi = new browser_wasi_shim_1.WASI(args, env, fds, { debug: false });
12
+ const vm = new index_js_1.RubyVM();
13
+ const imports = {
14
+ wasi_snapshot_preview1: wasi.wasiImport,
15
+ };
16
+ vm.addToImports(imports);
17
+ const printer = ((_b = options.consolePrint) !== null && _b !== void 0 ? _b : true) ? (0, index_js_1.consolePrinter)() : undefined;
18
+ printer === null || printer === void 0 ? void 0 : printer.addToImports(imports);
19
+ const instance = await WebAssembly.instantiate(rubyModule, imports);
20
+ await vm.setInstance(instance);
21
+ printer === null || printer === void 0 ? void 0 : printer.setMemory(instance.exports.memory);
22
+ wasi.initialize(instance);
23
+ vm.initialize();
24
+ return {
25
+ vm,
26
+ wasi,
27
+ instance,
28
+ };
29
+ };
30
+ exports.DefaultRubyVM = DefaultRubyVM;
@@ -1,4 +1,4 @@
1
- import { DefaultRubyVM } from "./browser";
1
+ import { DefaultRubyVM } from "./browser.js";
2
2
  export declare const main: (pkg: {
3
3
  name: string;
4
4
  version: string;