This repository was archived by the owner on Dec 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.mjs
More file actions
103 lines (96 loc) · 2.13 KB
/
Copy pathinterface.mjs
File metadata and controls
103 lines (96 loc) · 2.13 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
/** @enum {string} @readonly */
const T = Object.freeze({
VOID: "void",
JBYTE: "jbyte",
JSHORT: "jshort",
JINT: "jint",
JLONG: "jlong",
JFLOAT: "jfloat",
JDOUBLE: "jdouble",
JBOOLEAN: "jboolean",
JCHAR: "jchar",
STRING: "const char*",
INSTANCE: "JvmInstanceHandle",
});
/**
* @typedef {Object} KIFunctionArgument
* @property {string} name
* @property {T} type
*/
/**
* @typedef {Object} KIFuncDef
* @property {string} name
* @property {T} returnType
* @property {KIFunctionArgument[]} args
* @property {boolean?} isEmscriptenOnly
*/
/**
* @readonly
* @satisfies {Object.<string, function(string): KIFunctionArgument>}
*/
const Arg = Object.freeze({
void(name) {
return { name, type: T.VOID };
},
jbyte(name) {
return { name, type: T.JBYTE };
},
jshort(name) {
return { name, type: T.JSHORT };
},
jint(name) {
return { name, type: T.JINT };
},
jlong(name) {
return { name, type: T.JLONG };
},
jfloat(name) {
return { name, type: T.JFLOAT };
},
jdouble(name) {
return { name, type: T.JDOUBLE };
},
jboolean(name) {
return { name, type: T.JBOOLEAN };
},
jchar(name) {
return { name, type: T.JCHAR };
},
string(name) {
return { name, type: T.STRING };
},
instance(name) {
return { name, type: T.INSTANCE };
},
});
/**
* @param {string} name
* @param {T} returnType
* @param {KIFunctionArgument[]} args
* @returns {KIFuncDef}
*/
function hostImport(name, returnType, args) {
return { name, returnType, args };
}
/**
* @param {string} name
* @param {T} returnType
* @param {KIFunctionArgument[]} args
* @returns {KIFuncDef}
*/
function hostImportEmscriptenOnly(name, returnType, args) {
return { name, returnType, args, isEmscriptenOnly: true };
}
export const hostImports = [
hostImport("koe_cryptor_create", T.INSTANCE, [
Arg.jbyte("keyData"),
Arg.jint("keyDataLength"),
]),
hostImport("koe_cryptor_destroy", T.VOID, [Arg.instance("handle")]),
// Emscripten/WASM-specific imports
hostImportEmscriptenOnly("koe_dave_on_error", T.VOID, [
Arg.instance("session"),
Arg.string("source"),
Arg.string("reason"),
]),
];