-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathbinding.ts
91 lines (82 loc) · 2.69 KB
/
binding.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { RubyJsRubyRuntime } from "./bindgen/interfaces/ruby-js-ruby-runtime.js";
import * as RbAbi from "./bindgen/legacy/rb-abi-guest.js";
/**
* This interface bridges between the Ruby runtime and the JavaScript runtime
* and defines how to interact with underlying import/export functions.
*/
export interface Binding {
rubyShowVersion(): void;
rubyInit(args: string[]): void;
rubyInitLoadpath(): void;
rbEvalStringProtect(str: string): [RbAbiValue, number];
rbFuncallvProtect(recv: RbAbiValue, mid: RbAbi.RbId, args: RbAbiValue[]): [RbAbiValue, number];
rbIntern(name: string): RbAbi.RbId;
rbErrinfo(): RbAbiValue;
rbClearErrinfo(): void;
rstringPtr(value: RbAbiValue): string;
rbVmBugreport(): void;
rbGcEnable(): boolean;
rbGcDisable(): boolean;
rbSetShouldProhibitRewind(newValue: boolean): boolean;
setInstance(instance: WebAssembly.Instance): Promise<void>;
addToImports(imports: WebAssembly.Imports): void;
}
// Low-level opaque representation of a Ruby value.
export interface RbAbiValue {}
export class LegacyBinding extends RbAbi.RbAbiGuest implements Binding {
async setInstance(instance: WebAssembly.Instance): Promise<void> {
await this.instantiate(instance);
}
}
export class ComponentBinding implements Binding {
underlying: typeof RubyJsRubyRuntime;
constructor() {}
setUnderlying(underlying: typeof RubyJsRubyRuntime): void {
this.underlying = underlying;
}
rubyShowVersion(): void {
this.underlying.rubyShowVersion();
}
rubyInit(args: string[]): void {
this.underlying.rubyInit(args);
}
rubyInitLoadpath(): void {
this.underlying.rubyInitLoadpath();
}
rbEvalStringProtect(str: string): [RbAbiValue, number] {
return this.underlying.rbEvalStringProtect(str);
}
rbFuncallvProtect(recv: RbAbiValue, mid: number, args: RbAbiValue[]): [RbAbiValue, number] {
return this.underlying.rbFuncallvProtect(recv, mid, args);
}
rbIntern(name: string): number {
return this.underlying.rbIntern(name);
}
rbErrinfo(): RbAbiValue {
return this.underlying.rbErrinfo();
}
rbClearErrinfo(): void {
return this.underlying.rbClearErrinfo();
}
rstringPtr(value: RbAbiValue): string {
return this.underlying.rstringPtr(value);
}
rbVmBugreport(): void {
this.underlying.rbVmBugreport();
}
rbGcEnable(): boolean {
return this.underlying.rbGcEnable();
}
rbGcDisable(): boolean {
return this.underlying.rbGcDisable();
}
rbSetShouldProhibitRewind(newValue: boolean): boolean {
return this.underlying.rbSetShouldProhibitRewind(newValue);
}
async setInstance(instance: WebAssembly.Instance): Promise<void> {
// No-op
}
addToImports(imports: WebAssembly.Imports): void {
// No-op
}
}