@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.
- package/README.md +180 -4
- package/dist/browser.script.umd.js +170 -2048
- package/dist/browser.umd.js +170 -2048
- package/dist/cjs/bindgen/intrinsics.d.ts +13 -0
- package/dist/cjs/bindgen/intrinsics.js +81 -0
- package/dist/cjs/bindgen/rb-abi-guest.js +236 -0
- package/dist/cjs/bindgen/rb-js-abi-host.js +283 -0
- package/dist/{browser.d.ts → cjs/browser.d.ts} +2 -2
- package/dist/cjs/browser.js +30 -0
- package/dist/{browser.script.d.ts → cjs/browser.script.d.ts} +1 -1
- package/dist/cjs/browser.script.js +90 -0
- package/dist/cjs/console.d.ts +33 -0
- package/dist/cjs/console.js +104 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +7 -3
- package/dist/cjs/index.js +646 -0
- package/dist/{node.d.ts → cjs/node.d.ts} +1 -1
- package/dist/cjs/node.js +23 -0
- package/dist/esm/bindgen/intrinsics.d.ts +13 -0
- package/dist/esm/bindgen/intrinsics.js +73 -0
- package/dist/esm/bindgen/rb-abi-guest.d.ts +140 -0
- package/dist/esm/bindgen/rb-abi-guest.js +230 -0
- package/dist/esm/bindgen/rb-js-abi-host.d.ts +53 -0
- package/dist/esm/bindgen/rb-js-abi-host.js +279 -0
- package/dist/esm/browser.d.ts +10 -0
- package/dist/esm/browser.js +26 -0
- package/dist/esm/browser.script.d.ts +5 -0
- package/dist/esm/browser.script.js +86 -0
- package/dist/esm/console.d.ts +33 -0
- package/dist/esm/console.js +100 -0
- package/dist/esm/index.d.ts +196 -0
- package/dist/esm/index.js +637 -0
- package/dist/esm/node.d.ts +10 -0
- package/dist/esm/node.js +19 -0
- package/dist/esm/package.json +1 -0
- package/dist/index.umd.js +158 -10
- package/package.json +22 -38
- package/dist/browser.cjs.js +0 -3245
- package/dist/browser.esm.js +0 -3243
- package/dist/browser.script.cjs.js +0 -3372
- package/dist/browser.script.esm.js +0 -3370
- package/dist/index.cjs.js +0 -1192
- package/dist/index.esm.js +0 -1187
- package/dist/node.cjs.js +0 -1209
- package/dist/node.esm.js +0 -1207
- /package/dist/{bindgen → cjs/bindgen}/rb-abi-guest.d.ts +0 -0
- /package/dist/{bindgen → cjs/bindgen}/rb-js-abi-host.d.ts +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
let DATA_VIEW = new DataView(new ArrayBuffer());
|
|
2
|
+
export function data_view(mem) {
|
|
3
|
+
if (DATA_VIEW.buffer !== mem.buffer)
|
|
4
|
+
DATA_VIEW = new DataView(mem.buffer);
|
|
5
|
+
return DATA_VIEW;
|
|
6
|
+
}
|
|
7
|
+
export function to_uint32(val) {
|
|
8
|
+
return val >>> 0;
|
|
9
|
+
}
|
|
10
|
+
export const UTF8_DECODER = new TextDecoder('utf-8');
|
|
11
|
+
const UTF8_ENCODER = new TextEncoder('utf-8');
|
|
12
|
+
export function utf8_encode(s, realloc, memory) {
|
|
13
|
+
if (typeof s !== 'string')
|
|
14
|
+
throw new TypeError('expected a string');
|
|
15
|
+
if (s.length === 0) {
|
|
16
|
+
UTF8_ENCODED_LEN = 0;
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
let alloc_len = 0;
|
|
20
|
+
let ptr = 0;
|
|
21
|
+
let writtenTotal = 0;
|
|
22
|
+
while (s.length > 0) {
|
|
23
|
+
ptr = realloc(ptr, alloc_len, 1, alloc_len + s.length);
|
|
24
|
+
alloc_len += s.length;
|
|
25
|
+
const { read, written } = UTF8_ENCODER.encodeInto(s, new Uint8Array(memory.buffer, ptr + writtenTotal, alloc_len - writtenTotal));
|
|
26
|
+
writtenTotal += written;
|
|
27
|
+
s = s.slice(read);
|
|
28
|
+
}
|
|
29
|
+
if (alloc_len > writtenTotal)
|
|
30
|
+
ptr = realloc(ptr, alloc_len, 1, writtenTotal);
|
|
31
|
+
UTF8_ENCODED_LEN = writtenTotal;
|
|
32
|
+
return ptr;
|
|
33
|
+
}
|
|
34
|
+
export let UTF8_ENCODED_LEN = 0;
|
|
35
|
+
export class Slab {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.list = [];
|
|
38
|
+
this.head = 0;
|
|
39
|
+
}
|
|
40
|
+
insert(val) {
|
|
41
|
+
if (this.head >= this.list.length) {
|
|
42
|
+
this.list.push({
|
|
43
|
+
next: this.list.length + 1,
|
|
44
|
+
val: undefined,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const ret = this.head;
|
|
48
|
+
const slot = this.list[ret];
|
|
49
|
+
this.head = slot.next;
|
|
50
|
+
slot.next = -1;
|
|
51
|
+
slot.val = val;
|
|
52
|
+
return ret;
|
|
53
|
+
}
|
|
54
|
+
get(idx) {
|
|
55
|
+
if (idx >= this.list.length)
|
|
56
|
+
throw new RangeError('handle index not valid');
|
|
57
|
+
const slot = this.list[idx];
|
|
58
|
+
if (slot.next === -1)
|
|
59
|
+
return slot.val;
|
|
60
|
+
throw new RangeError('handle index not valid');
|
|
61
|
+
}
|
|
62
|
+
remove(idx) {
|
|
63
|
+
const ret = this.get(idx); // validate the slot
|
|
64
|
+
const slot = this.list[idx];
|
|
65
|
+
slot.val = undefined;
|
|
66
|
+
slot.next = this.head;
|
|
67
|
+
this.head = idx;
|
|
68
|
+
return ret;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function throw_invalid_bool() {
|
|
72
|
+
throw new RangeError("invalid variant discriminant for bool");
|
|
73
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export type RbErrno = number;
|
|
2
|
+
export type RbId = number;
|
|
3
|
+
export class RbAbiGuest {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The WebAssembly instance that this class is operating with.
|
|
7
|
+
* This is only available after the `instantiate` method has
|
|
8
|
+
* been called.
|
|
9
|
+
*/
|
|
10
|
+
instance: WebAssembly.Instance;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a new instance with internal state necessary to
|
|
14
|
+
* manage a wasm instance.
|
|
15
|
+
*
|
|
16
|
+
* Note that this does not actually instantiate the WebAssembly
|
|
17
|
+
* instance or module, you'll need to call the `instantiate`
|
|
18
|
+
* method below to "activate" this class.
|
|
19
|
+
*/
|
|
20
|
+
constructor();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This is a low-level method which can be used to add any
|
|
24
|
+
* intrinsics necessary for this instance to operate to an
|
|
25
|
+
* import object.
|
|
26
|
+
*
|
|
27
|
+
* The `import` object given here is expected to be used later
|
|
28
|
+
* to actually instantiate the module this class corresponds to.
|
|
29
|
+
* If the `instantiate` method below actually does the
|
|
30
|
+
* instantiation then there's no need to call this method, but
|
|
31
|
+
* if you're instantiating manually elsewhere then this can be
|
|
32
|
+
* used to prepare the import object for external instantiation.
|
|
33
|
+
*/
|
|
34
|
+
addToImports(imports: any): void;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Initializes this object with the provided WebAssembly
|
|
38
|
+
* module/instance.
|
|
39
|
+
*
|
|
40
|
+
* This is intended to be a flexible method of instantiating
|
|
41
|
+
* and completion of the initialization of this class. This
|
|
42
|
+
* method must be called before interacting with the
|
|
43
|
+
* WebAssembly object.
|
|
44
|
+
*
|
|
45
|
+
* The first argument to this method is where to get the
|
|
46
|
+
* wasm from. This can be a whole bunch of different types,
|
|
47
|
+
* for example:
|
|
48
|
+
*
|
|
49
|
+
* * A precompiled `WebAssembly.Module`
|
|
50
|
+
* * A typed array buffer containing the wasm bytecode.
|
|
51
|
+
* * A `Promise` of a `Response` which is used with
|
|
52
|
+
* `instantiateStreaming`
|
|
53
|
+
* * A `Response` itself used with `instantiateStreaming`.
|
|
54
|
+
* * An already instantiated `WebAssembly.Instance`
|
|
55
|
+
*
|
|
56
|
+
* If necessary the module is compiled, and if necessary the
|
|
57
|
+
* module is instantiated. Whether or not it's necessary
|
|
58
|
+
* depends on the type of argument provided to
|
|
59
|
+
* instantiation.
|
|
60
|
+
*
|
|
61
|
+
* If instantiation is performed then the `imports` object
|
|
62
|
+
* passed here is the list of imports used to instantiate
|
|
63
|
+
* the instance. This method may add its own intrinsics to
|
|
64
|
+
* this `imports` object too.
|
|
65
|
+
*/
|
|
66
|
+
instantiate(
|
|
67
|
+
module: WebAssembly.Module | BufferSource | Promise<Response> | Response | WebAssembly.Instance,
|
|
68
|
+
imports?: any,
|
|
69
|
+
): Promise<void>;
|
|
70
|
+
rubyShowVersion(): void;
|
|
71
|
+
rubyInit(): void;
|
|
72
|
+
rubySysinit(args: string[]): void;
|
|
73
|
+
rubyOptions(args: string[]): RbIseq;
|
|
74
|
+
rubyScript(name: string): void;
|
|
75
|
+
rubyInitLoadpath(): void;
|
|
76
|
+
rbEvalStringProtect(str: string): [RbAbiValue, number];
|
|
77
|
+
rbFuncallvProtect(recv: RbAbiValue, mid: RbId, args: RbAbiValue[]): [RbAbiValue, number];
|
|
78
|
+
rbIntern(name: string): RbId;
|
|
79
|
+
rbErrinfo(): RbAbiValue;
|
|
80
|
+
rbClearErrinfo(): void;
|
|
81
|
+
rstringPtr(value: RbAbiValue): string;
|
|
82
|
+
rbVmBugreport(): void;
|
|
83
|
+
rbGcEnable(): boolean;
|
|
84
|
+
rbGcDisable(): boolean;
|
|
85
|
+
rbSetShouldProhibitRewind(newValue: boolean): boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class RbIseq {
|
|
89
|
+
// Creates a new strong reference count as a new
|
|
90
|
+
// object. This is only required if you're also
|
|
91
|
+
// calling `drop` below and want to manually manage
|
|
92
|
+
// the reference count from JS.
|
|
93
|
+
//
|
|
94
|
+
// If you don't call `drop`, you don't need to call
|
|
95
|
+
// this and can simply use the object from JS.
|
|
96
|
+
clone(): RbIseq;
|
|
97
|
+
|
|
98
|
+
// Explicitly indicate that this JS object will no
|
|
99
|
+
// longer be used. If the internal reference count
|
|
100
|
+
// reaches zero then this will deterministically
|
|
101
|
+
// destroy the underlying wasm object.
|
|
102
|
+
//
|
|
103
|
+
// This is not required to be called from JS. Wasm
|
|
104
|
+
// destructors will be automatically called for you
|
|
105
|
+
// if this is not called using the JS
|
|
106
|
+
// `FinalizationRegistry`.
|
|
107
|
+
//
|
|
108
|
+
// Calling this method does not guarantee that the
|
|
109
|
+
// underlying wasm object is deallocated. Something
|
|
110
|
+
// else (including wasm) may be holding onto a
|
|
111
|
+
// strong reference count.
|
|
112
|
+
drop(): void;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export class RbAbiValue {
|
|
116
|
+
// Creates a new strong reference count as a new
|
|
117
|
+
// object. This is only required if you're also
|
|
118
|
+
// calling `drop` below and want to manually manage
|
|
119
|
+
// the reference count from JS.
|
|
120
|
+
//
|
|
121
|
+
// If you don't call `drop`, you don't need to call
|
|
122
|
+
// this and can simply use the object from JS.
|
|
123
|
+
clone(): RbAbiValue;
|
|
124
|
+
|
|
125
|
+
// Explicitly indicate that this JS object will no
|
|
126
|
+
// longer be used. If the internal reference count
|
|
127
|
+
// reaches zero then this will deterministically
|
|
128
|
+
// destroy the underlying wasm object.
|
|
129
|
+
//
|
|
130
|
+
// This is not required to be called from JS. Wasm
|
|
131
|
+
// destructors will be automatically called for you
|
|
132
|
+
// if this is not called using the JS
|
|
133
|
+
// `FinalizationRegistry`.
|
|
134
|
+
//
|
|
135
|
+
// Calling this method does not guarantee that the
|
|
136
|
+
// underlying wasm object is deallocated. Something
|
|
137
|
+
// else (including wasm) may be holding onto a
|
|
138
|
+
// strong reference count.
|
|
139
|
+
drop(): void;
|
|
140
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { data_view, to_uint32, UTF8_DECODER, utf8_encode, UTF8_ENCODED_LEN, Slab, throw_invalid_bool } from './intrinsics.js';
|
|
2
|
+
export class RbAbiGuest {
|
|
3
|
+
constructor() {
|
|
4
|
+
this._resource0_slab = new Slab();
|
|
5
|
+
this._resource1_slab = new Slab();
|
|
6
|
+
}
|
|
7
|
+
addToImports(imports) {
|
|
8
|
+
if (!("canonical_abi" in imports))
|
|
9
|
+
imports["canonical_abi"] = {};
|
|
10
|
+
imports.canonical_abi['resource_drop_rb-iseq'] = i => {
|
|
11
|
+
this._resource0_slab.remove(i).drop();
|
|
12
|
+
};
|
|
13
|
+
imports.canonical_abi['resource_clone_rb-iseq'] = i => {
|
|
14
|
+
const obj = this._resource0_slab.get(i);
|
|
15
|
+
return this._resource0_slab.insert(obj.clone());
|
|
16
|
+
};
|
|
17
|
+
imports.canonical_abi['resource_get_rb-iseq'] = i => {
|
|
18
|
+
return this._resource0_slab.get(i)._wasm_val;
|
|
19
|
+
};
|
|
20
|
+
imports.canonical_abi['resource_new_rb-iseq'] = i => {
|
|
21
|
+
const registry = this._registry0;
|
|
22
|
+
return this._resource0_slab.insert(new RbIseq(i, this));
|
|
23
|
+
};
|
|
24
|
+
imports.canonical_abi['resource_drop_rb-abi-value'] = i => {
|
|
25
|
+
this._resource1_slab.remove(i).drop();
|
|
26
|
+
};
|
|
27
|
+
imports.canonical_abi['resource_clone_rb-abi-value'] = i => {
|
|
28
|
+
const obj = this._resource1_slab.get(i);
|
|
29
|
+
return this._resource1_slab.insert(obj.clone());
|
|
30
|
+
};
|
|
31
|
+
imports.canonical_abi['resource_get_rb-abi-value'] = i => {
|
|
32
|
+
return this._resource1_slab.get(i)._wasm_val;
|
|
33
|
+
};
|
|
34
|
+
imports.canonical_abi['resource_new_rb-abi-value'] = i => {
|
|
35
|
+
const registry = this._registry1;
|
|
36
|
+
return this._resource1_slab.insert(new RbAbiValue(i, this));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async instantiate(module, imports) {
|
|
40
|
+
imports = imports || {};
|
|
41
|
+
this.addToImports(imports);
|
|
42
|
+
if (module instanceof WebAssembly.Instance) {
|
|
43
|
+
this.instance = module;
|
|
44
|
+
}
|
|
45
|
+
else if (module instanceof WebAssembly.Module) {
|
|
46
|
+
this.instance = await WebAssembly.instantiate(module, imports);
|
|
47
|
+
}
|
|
48
|
+
else if (module instanceof ArrayBuffer || module instanceof Uint8Array) {
|
|
49
|
+
const { instance } = await WebAssembly.instantiate(module, imports);
|
|
50
|
+
this.instance = instance;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const { instance } = await WebAssembly.instantiateStreaming(module, imports);
|
|
54
|
+
this.instance = instance;
|
|
55
|
+
}
|
|
56
|
+
this._exports = this.instance.exports;
|
|
57
|
+
this._registry0 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-iseq']);
|
|
58
|
+
this._registry1 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-abi-value']);
|
|
59
|
+
}
|
|
60
|
+
rubyShowVersion() {
|
|
61
|
+
this._exports['ruby-show-version: func() -> ()']();
|
|
62
|
+
}
|
|
63
|
+
rubyInit() {
|
|
64
|
+
this._exports['ruby-init: func() -> ()']();
|
|
65
|
+
}
|
|
66
|
+
rubySysinit(arg0) {
|
|
67
|
+
const memory = this._exports.memory;
|
|
68
|
+
const realloc = this._exports["cabi_realloc"];
|
|
69
|
+
const vec1 = arg0;
|
|
70
|
+
const len1 = vec1.length;
|
|
71
|
+
const result1 = realloc(0, 0, 4, len1 * 8);
|
|
72
|
+
for (let i = 0; i < vec1.length; i++) {
|
|
73
|
+
const e = vec1[i];
|
|
74
|
+
const base = result1 + i * 8;
|
|
75
|
+
const ptr0 = utf8_encode(e, realloc, memory);
|
|
76
|
+
const len0 = UTF8_ENCODED_LEN;
|
|
77
|
+
data_view(memory).setInt32(base + 4, len0, true);
|
|
78
|
+
data_view(memory).setInt32(base + 0, ptr0, true);
|
|
79
|
+
}
|
|
80
|
+
this._exports['ruby-sysinit: func(args: list<string>) -> ()'](result1, len1);
|
|
81
|
+
}
|
|
82
|
+
rubyOptions(arg0) {
|
|
83
|
+
const memory = this._exports.memory;
|
|
84
|
+
const realloc = this._exports["cabi_realloc"];
|
|
85
|
+
const vec1 = arg0;
|
|
86
|
+
const len1 = vec1.length;
|
|
87
|
+
const result1 = realloc(0, 0, 4, len1 * 8);
|
|
88
|
+
for (let i = 0; i < vec1.length; i++) {
|
|
89
|
+
const e = vec1[i];
|
|
90
|
+
const base = result1 + i * 8;
|
|
91
|
+
const ptr0 = utf8_encode(e, realloc, memory);
|
|
92
|
+
const len0 = UTF8_ENCODED_LEN;
|
|
93
|
+
data_view(memory).setInt32(base + 4, len0, true);
|
|
94
|
+
data_view(memory).setInt32(base + 0, ptr0, true);
|
|
95
|
+
}
|
|
96
|
+
const ret = this._exports['ruby-options: func(args: list<string>) -> handle<rb-iseq>'](result1, len1);
|
|
97
|
+
return this._resource0_slab.remove(ret);
|
|
98
|
+
}
|
|
99
|
+
rubyScript(arg0) {
|
|
100
|
+
const memory = this._exports.memory;
|
|
101
|
+
const realloc = this._exports["cabi_realloc"];
|
|
102
|
+
const ptr0 = utf8_encode(arg0, realloc, memory);
|
|
103
|
+
const len0 = UTF8_ENCODED_LEN;
|
|
104
|
+
this._exports['ruby-script: func(name: string) -> ()'](ptr0, len0);
|
|
105
|
+
}
|
|
106
|
+
rubyInitLoadpath() {
|
|
107
|
+
this._exports['ruby-init-loadpath: func() -> ()']();
|
|
108
|
+
}
|
|
109
|
+
rbEvalStringProtect(arg0) {
|
|
110
|
+
const memory = this._exports.memory;
|
|
111
|
+
const realloc = this._exports["cabi_realloc"];
|
|
112
|
+
const ptr0 = utf8_encode(arg0, realloc, memory);
|
|
113
|
+
const len0 = UTF8_ENCODED_LEN;
|
|
114
|
+
const ret = this._exports['rb-eval-string-protect: func(str: string) -> tuple<handle<rb-abi-value>, s32>'](ptr0, len0);
|
|
115
|
+
return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
|
|
116
|
+
}
|
|
117
|
+
rbFuncallvProtect(arg0, arg1, arg2) {
|
|
118
|
+
const memory = this._exports.memory;
|
|
119
|
+
const realloc = this._exports["cabi_realloc"];
|
|
120
|
+
const obj0 = arg0;
|
|
121
|
+
if (!(obj0 instanceof RbAbiValue))
|
|
122
|
+
throw new TypeError('expected instance of RbAbiValue');
|
|
123
|
+
const vec2 = arg2;
|
|
124
|
+
const len2 = vec2.length;
|
|
125
|
+
const result2 = realloc(0, 0, 4, len2 * 4);
|
|
126
|
+
for (let i = 0; i < vec2.length; i++) {
|
|
127
|
+
const e = vec2[i];
|
|
128
|
+
const base = result2 + i * 4;
|
|
129
|
+
const obj1 = e;
|
|
130
|
+
if (!(obj1 instanceof RbAbiValue))
|
|
131
|
+
throw new TypeError('expected instance of RbAbiValue');
|
|
132
|
+
data_view(memory).setInt32(base + 0, this._resource1_slab.insert(obj1.clone()), true);
|
|
133
|
+
}
|
|
134
|
+
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()), to_uint32(arg1), result2, len2);
|
|
135
|
+
return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
|
|
136
|
+
}
|
|
137
|
+
rbIntern(arg0) {
|
|
138
|
+
const memory = this._exports.memory;
|
|
139
|
+
const realloc = this._exports["cabi_realloc"];
|
|
140
|
+
const ptr0 = utf8_encode(arg0, realloc, memory);
|
|
141
|
+
const len0 = UTF8_ENCODED_LEN;
|
|
142
|
+
const ret = this._exports['rb-intern: func(name: string) -> u32'](ptr0, len0);
|
|
143
|
+
return ret >>> 0;
|
|
144
|
+
}
|
|
145
|
+
rbErrinfo() {
|
|
146
|
+
const ret = this._exports['rb-errinfo: func() -> handle<rb-abi-value>']();
|
|
147
|
+
return this._resource1_slab.remove(ret);
|
|
148
|
+
}
|
|
149
|
+
rbClearErrinfo() {
|
|
150
|
+
this._exports['rb-clear-errinfo: func() -> ()']();
|
|
151
|
+
}
|
|
152
|
+
rstringPtr(arg0) {
|
|
153
|
+
const memory = this._exports.memory;
|
|
154
|
+
const obj0 = arg0;
|
|
155
|
+
if (!(obj0 instanceof RbAbiValue))
|
|
156
|
+
throw new TypeError('expected instance of RbAbiValue');
|
|
157
|
+
const ret = this._exports['rstring-ptr: func(value: handle<rb-abi-value>) -> string'](this._resource1_slab.insert(obj0.clone()));
|
|
158
|
+
const ptr1 = data_view(memory).getInt32(ret + 0, true);
|
|
159
|
+
const len1 = data_view(memory).getInt32(ret + 4, true);
|
|
160
|
+
const result1 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1));
|
|
161
|
+
this._exports["cabi_post_rstring-ptr"](ret);
|
|
162
|
+
return result1;
|
|
163
|
+
}
|
|
164
|
+
rbVmBugreport() {
|
|
165
|
+
this._exports['rb-vm-bugreport: func() -> ()']();
|
|
166
|
+
}
|
|
167
|
+
rbGcEnable() {
|
|
168
|
+
const ret = this._exports['rb-gc-enable: func() -> bool']();
|
|
169
|
+
const bool0 = ret;
|
|
170
|
+
return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
|
|
171
|
+
}
|
|
172
|
+
rbGcDisable() {
|
|
173
|
+
const ret = this._exports['rb-gc-disable: func() -> bool']();
|
|
174
|
+
const bool0 = ret;
|
|
175
|
+
return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
|
|
176
|
+
}
|
|
177
|
+
rbSetShouldProhibitRewind(arg0) {
|
|
178
|
+
const ret = this._exports['rb-set-should-prohibit-rewind: func(new-value: bool) -> bool'](arg0 ? 1 : 0);
|
|
179
|
+
const bool0 = ret;
|
|
180
|
+
return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export class RbIseq {
|
|
184
|
+
constructor(wasm_val, obj) {
|
|
185
|
+
this._wasm_val = wasm_val;
|
|
186
|
+
this._obj = obj;
|
|
187
|
+
this._refcnt = 1;
|
|
188
|
+
obj._registry0.register(this, wasm_val, this);
|
|
189
|
+
}
|
|
190
|
+
clone() {
|
|
191
|
+
this._refcnt += 1;
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
drop() {
|
|
195
|
+
this._refcnt -= 1;
|
|
196
|
+
if (this._refcnt !== 0)
|
|
197
|
+
return;
|
|
198
|
+
this._obj._registry0.unregister(this);
|
|
199
|
+
const dtor = this._obj._exports['canonical_abi_drop_rb-iseq'];
|
|
200
|
+
const wasm_val = this._wasm_val;
|
|
201
|
+
delete this._obj;
|
|
202
|
+
delete this._refcnt;
|
|
203
|
+
delete this._wasm_val;
|
|
204
|
+
dtor(wasm_val);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
export class RbAbiValue {
|
|
208
|
+
constructor(wasm_val, obj) {
|
|
209
|
+
this._wasm_val = wasm_val;
|
|
210
|
+
this._obj = obj;
|
|
211
|
+
this._refcnt = 1;
|
|
212
|
+
obj._registry1.register(this, wasm_val, this);
|
|
213
|
+
}
|
|
214
|
+
clone() {
|
|
215
|
+
this._refcnt += 1;
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
drop() {
|
|
219
|
+
this._refcnt -= 1;
|
|
220
|
+
if (this._refcnt !== 0)
|
|
221
|
+
return;
|
|
222
|
+
this._obj._registry1.unregister(this);
|
|
223
|
+
const dtor = this._obj._exports['canonical_abi_drop_rb-abi-value'];
|
|
224
|
+
const wasm_val = this._wasm_val;
|
|
225
|
+
delete this._obj;
|
|
226
|
+
delete this._refcnt;
|
|
227
|
+
delete this._wasm_val;
|
|
228
|
+
dtor(wasm_val);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type JsAbiResult = JsAbiResultSuccess | JsAbiResultFailure;
|
|
2
|
+
export interface JsAbiResultSuccess {
|
|
3
|
+
tag: "success",
|
|
4
|
+
val: JsAbiValue,
|
|
5
|
+
}
|
|
6
|
+
export interface JsAbiResultFailure {
|
|
7
|
+
tag: "failure",
|
|
8
|
+
val: JsAbiValue,
|
|
9
|
+
}
|
|
10
|
+
export type RawInteger = RawIntegerF64 | RawIntegerBignum;
|
|
11
|
+
export interface RawIntegerF64 {
|
|
12
|
+
tag: "f64",
|
|
13
|
+
val: number,
|
|
14
|
+
}
|
|
15
|
+
export interface RawIntegerBignum {
|
|
16
|
+
tag: "bignum",
|
|
17
|
+
val: string,
|
|
18
|
+
}
|
|
19
|
+
export function addRbJsAbiHostToImports(imports: any, obj: RbJsAbiHost, get_export: (name: string) => WebAssembly.ExportValue): void;
|
|
20
|
+
export interface RbJsAbiHost {
|
|
21
|
+
evalJs(code: string): JsAbiResult;
|
|
22
|
+
isJs(value: JsAbiValue): boolean;
|
|
23
|
+
instanceOf(value: JsAbiValue, klass: JsAbiValue): boolean;
|
|
24
|
+
globalThis(): JsAbiValue;
|
|
25
|
+
intToJsNumber(value: number): JsAbiValue;
|
|
26
|
+
floatToJsNumber(value: number): JsAbiValue;
|
|
27
|
+
stringToJsString(value: string): JsAbiValue;
|
|
28
|
+
boolToJsBool(value: boolean): JsAbiValue;
|
|
29
|
+
procToJsFunction(value: number): JsAbiValue;
|
|
30
|
+
rbObjectToJsRbValue(rawRbAbiValue: number): JsAbiValue;
|
|
31
|
+
jsValueToString(value: JsAbiValue): string;
|
|
32
|
+
jsValueToInteger(value: JsAbiValue): RawInteger;
|
|
33
|
+
exportJsValueToHost(value: JsAbiValue): void;
|
|
34
|
+
importJsValueFromHost(): JsAbiValue;
|
|
35
|
+
jsValueTypeof(value: JsAbiValue): string;
|
|
36
|
+
jsValueEqual(lhs: JsAbiValue, rhs: JsAbiValue): boolean;
|
|
37
|
+
jsValueStrictlyEqual(lhs: JsAbiValue, rhs: JsAbiValue): boolean;
|
|
38
|
+
reflectApply(target: JsAbiValue, thisArgument: JsAbiValue, arguments: JsAbiValue[]): JsAbiResult;
|
|
39
|
+
reflectConstruct(target: JsAbiValue, arguments: JsAbiValue[]): JsAbiValue;
|
|
40
|
+
reflectDeleteProperty(target: JsAbiValue, propertyKey: string): boolean;
|
|
41
|
+
reflectGet(target: JsAbiValue, propertyKey: string): JsAbiResult;
|
|
42
|
+
reflectGetOwnPropertyDescriptor(target: JsAbiValue, propertyKey: string): JsAbiValue;
|
|
43
|
+
reflectGetPrototypeOf(target: JsAbiValue): JsAbiValue;
|
|
44
|
+
reflectHas(target: JsAbiValue, propertyKey: string): boolean;
|
|
45
|
+
reflectIsExtensible(target: JsAbiValue): boolean;
|
|
46
|
+
reflectOwnKeys(target: JsAbiValue): JsAbiValue[];
|
|
47
|
+
reflectPreventExtensions(target: JsAbiValue): boolean;
|
|
48
|
+
reflectSet(target: JsAbiValue, propertyKey: string, value: JsAbiValue): JsAbiResult;
|
|
49
|
+
reflectSetPrototypeOf(target: JsAbiValue, prototype: JsAbiValue): boolean;
|
|
50
|
+
dropJsAbiValue?: (val: JsAbiValue) => void;
|
|
51
|
+
}
|
|
52
|
+
export interface JsAbiValue {
|
|
53
|
+
}
|