jseption 0.0.0-stage → 0.0.2
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/LICENSE +26 -0
- package/README.md +191 -2
- package/dist/atoms.d.ts +255 -0
- package/dist/atoms.js +445 -0
- package/dist/atoms.js.map +1 -0
- package/dist/builtins/array.d.ts +3 -0
- package/dist/builtins/array.js +116 -0
- package/dist/builtins/array.js.map +1 -0
- package/dist/builtins/bigint.d.ts +3 -0
- package/dist/builtins/bigint.js +122 -0
- package/dist/builtins/bigint.js.map +1 -0
- package/dist/builtins/boolean.d.ts +2 -0
- package/dist/builtins/boolean.js +26 -0
- package/dist/builtins/boolean.js.map +1 -0
- package/dist/builtins/date.d.ts +3 -0
- package/dist/builtins/date.js +1046 -0
- package/dist/builtins/date.js.map +1 -0
- package/dist/builtins/error.d.ts +2 -0
- package/dist/builtins/error.js +154 -0
- package/dist/builtins/error.js.map +1 -0
- package/dist/builtins/function.d.ts +5 -0
- package/dist/builtins/function.js +164 -0
- package/dist/builtins/function.js.map +1 -0
- package/dist/builtins/global.d.ts +2 -0
- package/dist/builtins/global.js +29 -0
- package/dist/builtins/global.js.map +1 -0
- package/dist/builtins/index.d.ts +3 -0
- package/dist/builtins/index.js +139 -0
- package/dist/builtins/index.js.map +1 -0
- package/dist/builtins/json.d.ts +6 -0
- package/dist/builtins/json.js +984 -0
- package/dist/builtins/json.js.map +1 -0
- package/dist/builtins/mapset.d.ts +4 -0
- package/dist/builtins/mapset.js +234 -0
- package/dist/builtins/mapset.js.map +1 -0
- package/dist/builtins/math.d.ts +2 -0
- package/dist/builtins/math.js +62 -0
- package/dist/builtins/math.js.map +1 -0
- package/dist/builtins/native.d.ts +22 -0
- package/dist/builtins/native.js +250 -0
- package/dist/builtins/native.js.map +1 -0
- package/dist/builtins/number.d.ts +4 -0
- package/dist/builtins/number.js +76 -0
- package/dist/builtins/number.js.map +1 -0
- package/dist/builtins/object.d.ts +12 -0
- package/dist/builtins/object.js +575 -0
- package/dist/builtins/object.js.map +1 -0
- package/dist/builtins/promise.d.ts +13 -0
- package/dist/builtins/promise.js +582 -0
- package/dist/builtins/promise.js.map +1 -0
- package/dist/builtins/proxy.d.ts +3 -0
- package/dist/builtins/proxy.js +226 -0
- package/dist/builtins/proxy.js.map +1 -0
- package/dist/builtins/reflect.d.ts +2 -0
- package/dist/builtins/reflect.js +109 -0
- package/dist/builtins/reflect.js.map +1 -0
- package/dist/builtins/regexp.d.ts +2 -0
- package/dist/builtins/regexp.js +203 -0
- package/dist/builtins/regexp.js.map +1 -0
- package/dist/builtins/string.d.ts +4 -0
- package/dist/builtins/string.js +135 -0
- package/dist/builtins/string.js.map +1 -0
- package/dist/builtins/symbol.d.ts +3 -0
- package/dist/builtins/symbol.js +98 -0
- package/dist/builtins/symbol.js.map +1 -0
- package/dist/builtins/typedarray.d.ts +15 -0
- package/dist/builtins/typedarray.js +1838 -0
- package/dist/builtins/typedarray.js.map +1 -0
- package/dist/builtins/weakref.d.ts +18 -0
- package/dist/builtins/weakref.js +130 -0
- package/dist/builtins/weakref.js.map +1 -0
- package/dist/dump.d.ts +2 -0
- package/dist/dump.js +124 -0
- package/dist/dump.js.map +1 -0
- package/dist/embed.d.ts +18 -0
- package/dist/embed.js +286 -0
- package/dist/embed.js.map +1 -0
- package/dist/interpreter.d.ts +81 -0
- package/dist/interpreter.js +3768 -0
- package/dist/interpreter.js.map +1 -0
- package/dist/jit.d.ts +59 -0
- package/dist/jit.js +3440 -0
- package/dist/jit.js.map +1 -0
- package/dist/jit_hook.d.ts +21 -0
- package/dist/jit_hook.js +4 -0
- package/dist/jit_hook.js.map +1 -0
- package/dist/jit_runtime.d.ts +104 -0
- package/dist/jit_runtime.js +721 -0
- package/dist/jit_runtime.js.map +1 -0
- package/dist/jit_stack.d.ts +24 -0
- package/dist/jit_stack.js +227 -0
- package/dist/jit_stack.js.map +1 -0
- package/dist/jseption.d.ts +15 -0
- package/dist/jseption.js +61 -0
- package/dist/jseption.js.map +1 -0
- package/dist/opcodes.d.ts +347 -0
- package/dist/opcodes.js +322 -0
- package/dist/opcodes.js.map +1 -0
- package/dist/parser.d.ts +283 -0
- package/dist/parser.js +9752 -0
- package/dist/parser.js.map +1 -0
- package/dist/qjs.d.ts +2 -0
- package/dist/qjs.js +122 -0
- package/dist/qjs.js.map +1 -0
- package/dist/quickjs.d.ts +460 -0
- package/dist/quickjs.js +3408 -0
- package/dist/quickjs.js.map +1 -0
- package/dist/std.d.ts +4 -0
- package/dist/std.js +273 -0
- package/dist/std.js.map +1 -0
- package/dist/values.d.ts +447 -0
- package/dist/values.js +461 -0
- package/dist/values.js.map +1 -0
- package/package.json +59 -4
package/dist/dump.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Bytecode disassembler (port of dump_byte_code in quickjs.c), used for
|
|
3
|
+
* debugging and by the `qjs -d` option.
|
|
4
|
+
*/
|
|
5
|
+
import { JSFunctionBytecode, JS_AtomGetStr } from "./quickjs.js";
|
|
6
|
+
import { short_opcode_info, get_u8, get_i8, get_u16, get_i16, get_u32, get_i32 } from "./opcodes.js";
|
|
7
|
+
export function dump_byte_code(ctx, b) {
|
|
8
|
+
const buf = b.byte_code_buf;
|
|
9
|
+
const len = b.byte_code_len;
|
|
10
|
+
let out = '';
|
|
11
|
+
const name = b.func_name ? JS_AtomGetStr(ctx, b.func_name) : '<anonymous>';
|
|
12
|
+
out += `function ${name}: args=${b.arg_count} vars=${b.var_count} stack=${b.stack_size} closure_vars=${b.closure_var.length} cpool=${b.cpool.length}\n`;
|
|
13
|
+
for (let i = 0; i < b.closure_var.length; i++) {
|
|
14
|
+
const cv = b.closure_var[i];
|
|
15
|
+
out += ` closure_var[${i}]: ${JS_AtomGetStr(ctx, cv.var_name)} ${cv.is_local ? 'local' : 'parent'} ${cv.is_arg ? 'arg' : 'var'} idx=${cv.var_idx}\n`;
|
|
16
|
+
}
|
|
17
|
+
for (let i = 0; i < b.vardefs.length; i++) {
|
|
18
|
+
const vd = b.vardefs[i];
|
|
19
|
+
out += ` ${i < b.arg_count ? 'arg' : 'var'}[${i < b.arg_count ? i : i - b.arg_count}]: ${JS_AtomGetStr(ctx, vd.var_name)} scope=${vd.scope_level}${vd.is_lexical ? ' lexical' : ''}${vd.is_const ? ' const' : ''}\n`;
|
|
20
|
+
}
|
|
21
|
+
let pos = 0;
|
|
22
|
+
while (pos < len) {
|
|
23
|
+
const op = buf[pos];
|
|
24
|
+
const oi = short_opcode_info(op);
|
|
25
|
+
if (!oi) {
|
|
26
|
+
out += `${pos}: invalid opcode ${op}\n`;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
let line = `${String(pos).padStart(5)}: ${oi.name}`;
|
|
30
|
+
const p = pos + 1;
|
|
31
|
+
switch (oi.fmt) {
|
|
32
|
+
case 1 /* OpFmt.none_int */:
|
|
33
|
+
line += ` ${op - 183 /* OP.push_0 */}`;
|
|
34
|
+
break;
|
|
35
|
+
case 2 /* OpFmt.none_loc */:
|
|
36
|
+
line += ` ${(op - 199 /* OP.get_loc0 */) % 4}`;
|
|
37
|
+
break;
|
|
38
|
+
case 3 /* OpFmt.none_arg */:
|
|
39
|
+
line += ` ${(op - 211 /* OP.get_arg0 */) % 4}`;
|
|
40
|
+
break;
|
|
41
|
+
case 4 /* OpFmt.none_var_ref */:
|
|
42
|
+
line += ` ${(op - 223 /* OP.get_var_ref0 */) % 4}`;
|
|
43
|
+
break;
|
|
44
|
+
case 5 /* OpFmt.u8 */:
|
|
45
|
+
case 7 /* OpFmt.loc8 */:
|
|
46
|
+
case 8 /* OpFmt.const8 */:
|
|
47
|
+
line += ` ${get_u8(buf, p)}`;
|
|
48
|
+
break;
|
|
49
|
+
case 6 /* OpFmt.i8 */:
|
|
50
|
+
line += ` ${get_i8(buf, p)}`;
|
|
51
|
+
break;
|
|
52
|
+
case 9 /* OpFmt.label8 */:
|
|
53
|
+
line += ` ${pos + 1 + get_i8(buf, p)}`;
|
|
54
|
+
break;
|
|
55
|
+
case 10 /* OpFmt.u16 */:
|
|
56
|
+
case 13 /* OpFmt.npop */:
|
|
57
|
+
case 16 /* OpFmt.loc */:
|
|
58
|
+
case 17 /* OpFmt.arg */:
|
|
59
|
+
case 18 /* OpFmt.var_ref */:
|
|
60
|
+
line += ` ${get_u16(buf, p)}`;
|
|
61
|
+
break;
|
|
62
|
+
case 14 /* OpFmt.npopx */:
|
|
63
|
+
line += ` ${op - 240 /* OP.call0 */}`;
|
|
64
|
+
break;
|
|
65
|
+
case 11 /* OpFmt.i16 */:
|
|
66
|
+
line += ` ${get_i16(buf, p)}`;
|
|
67
|
+
break;
|
|
68
|
+
case 12 /* OpFmt.label16 */:
|
|
69
|
+
line += ` ${pos + 1 + get_i16(buf, p)}`;
|
|
70
|
+
break;
|
|
71
|
+
case 15 /* OpFmt.npop_u16 */:
|
|
72
|
+
line += ` ${get_u16(buf, p)},${get_u16(buf, p + 2)}`;
|
|
73
|
+
break;
|
|
74
|
+
case 19 /* OpFmt.u32 */:
|
|
75
|
+
line += ` ${get_u32(buf, p)}`;
|
|
76
|
+
break;
|
|
77
|
+
case 20 /* OpFmt.i32 */:
|
|
78
|
+
line += ` ${get_i32(buf, p)}`;
|
|
79
|
+
break;
|
|
80
|
+
case 21 /* OpFmt.const */: {
|
|
81
|
+
const c = b.cpool[get_u32(buf, p)];
|
|
82
|
+
line += ` ${get_u32(buf, p)} (${fmt_const(ctx, c)})`;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case 22 /* OpFmt.label */:
|
|
86
|
+
line += ` ${pos + 1 + get_i32(buf, p)}`;
|
|
87
|
+
break;
|
|
88
|
+
case 23 /* OpFmt.atom */:
|
|
89
|
+
line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))}`;
|
|
90
|
+
break;
|
|
91
|
+
case 24 /* OpFmt.atom_u8 */:
|
|
92
|
+
line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))},${get_u8(buf, p + 4)}`;
|
|
93
|
+
break;
|
|
94
|
+
case 25 /* OpFmt.atom_u16 */:
|
|
95
|
+
line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))},${get_u16(buf, p + 4)}`;
|
|
96
|
+
break;
|
|
97
|
+
case 26 /* OpFmt.atom_label_u8 */:
|
|
98
|
+
line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))},${pos + 5 + get_i32(buf, p + 4)},${get_u8(buf, p + 8)}`;
|
|
99
|
+
break;
|
|
100
|
+
case 27 /* OpFmt.atom_label_u16 */:
|
|
101
|
+
line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))},${pos + 5 + get_i32(buf, p + 4)},${get_u16(buf, p + 8)}`;
|
|
102
|
+
break;
|
|
103
|
+
case 28 /* OpFmt.label_u16 */:
|
|
104
|
+
line += ` ${pos + 1 + get_i32(buf, p)},${get_u16(buf, p + 4)}`;
|
|
105
|
+
break;
|
|
106
|
+
default: break;
|
|
107
|
+
}
|
|
108
|
+
out += line + '\n';
|
|
109
|
+
pos += oi.size;
|
|
110
|
+
}
|
|
111
|
+
for (const c of b.cpool) {
|
|
112
|
+
if (c instanceof JSFunctionBytecode)
|
|
113
|
+
out += '\n' + dump_byte_code(ctx, c);
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
function fmt_const(ctx, c) {
|
|
118
|
+
if (c instanceof JSFunctionBytecode)
|
|
119
|
+
return 'function ' + (c.func_name ? JS_AtomGetStr(ctx, c.func_name) : '');
|
|
120
|
+
if (typeof c === 'string')
|
|
121
|
+
return JSON.stringify(c);
|
|
122
|
+
return String(c);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=dump.js.map
|
package/dist/dump.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dump.js","sourceRoot":"","sources":["../src/dump.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAa,kBAAkB,EAAE,aAAa,EAAW,MAAM,cAAc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,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAAC,MAAM;YAC5I;gBAAsB,IAAI,IAAI,IAAI,GAAG,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAAC,MAAM;YAC5F,OAAO,CAAC,CAAC,MAAM;QACjB,CAAC;QACD,GAAG,IAAI,IAAI,GAAG,IAAI,CAAC;QACnB,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC;IACjB,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,YAAY,kBAAkB;YAAE,GAAG,IAAI,IAAI,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,SAAS,CAAC,GAAc,EAAE,CAA+B;IAChE,IAAI,CAAC,YAAY,kBAAkB;QAAE,OAAO,WAAW,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/G,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC","sourcesContent":["/*\n * Bytecode disassembler (port of dump_byte_code in quickjs.c), used for\n * debugging and by the `qjs -d` option.\n */\nimport { JSContext, JSFunctionBytecode, JS_AtomGetStr, JSValue } from './quickjs.ts';\nimport { OP, OpFmt, short_opcode_info, get_u8, get_i8, get_u16, get_i16, get_u32, get_i32 } from './opcodes.ts';\n\nexport function dump_byte_code(ctx: JSContext, b: JSFunctionBytecode): string {\n const buf = b.byte_code_buf;\n const len = b.byte_code_len;\n let out = '';\n const name = b.func_name ? JS_AtomGetStr(ctx, b.func_name) : '<anonymous>';\n out += `function ${name}: args=${b.arg_count} vars=${b.var_count} stack=${b.stack_size} closure_vars=${b.closure_var.length} cpool=${b.cpool.length}\\n`;\n for (let i = 0; i < b.closure_var.length; i++) {\n const cv = b.closure_var[i];\n out += ` closure_var[${i}]: ${JS_AtomGetStr(ctx, cv.var_name)} ${cv.is_local ? 'local' : 'parent'} ${cv.is_arg ? 'arg' : 'var'} idx=${cv.var_idx}\\n`;\n }\n for (let i = 0; i < b.vardefs.length; i++) {\n const vd = b.vardefs[i];\n out += ` ${i < b.arg_count ? 'arg' : 'var'}[${i < b.arg_count ? i : i - b.arg_count}]: ${JS_AtomGetStr(ctx, vd.var_name)} scope=${vd.scope_level}${vd.is_lexical ? ' lexical' : ''}${vd.is_const ? ' const' : ''}\\n`;\n }\n let pos = 0;\n while (pos < len) {\n const op = buf[pos];\n const oi = short_opcode_info(op);\n if (!oi) { out += `${pos}: invalid opcode ${op}\\n`; break; }\n let line = `${String(pos).padStart(5)}: ${oi.name}`;\n const p = pos + 1;\n switch (oi.fmt) {\n case OpFmt.none_int: line += ` ${op - OP.push_0}`; break;\n case OpFmt.none_loc: line += ` ${(op - OP.get_loc0) % 4}`; break;\n case OpFmt.none_arg: line += ` ${(op - OP.get_arg0) % 4}`; break;\n case OpFmt.none_var_ref: line += ` ${(op - OP.get_var_ref0) % 4}`; break;\n case OpFmt.u8: case OpFmt.loc8: case OpFmt.const8: line += ` ${get_u8(buf, p)}`; break;\n case OpFmt.i8: line += ` ${get_i8(buf, p)}`; break;\n case OpFmt.label8: line += ` ${pos + 1 + get_i8(buf, p)}`; break;\n case OpFmt.u16: case OpFmt.npop: case OpFmt.loc: case OpFmt.arg: case OpFmt.var_ref: line += ` ${get_u16(buf, p)}`; break;\n case OpFmt.npopx: line += ` ${op - OP.call0}`; break;\n case OpFmt.i16: line += ` ${get_i16(buf, p)}`; break;\n case OpFmt.label16: line += ` ${pos + 1 + get_i16(buf, p)}`; break;\n case OpFmt.npop_u16: line += ` ${get_u16(buf, p)},${get_u16(buf, p + 2)}`; break;\n case OpFmt.u32: line += ` ${get_u32(buf, p)}`; break;\n case OpFmt.i32: line += ` ${get_i32(buf, p)}`; break;\n case OpFmt.const: { const c = b.cpool[get_u32(buf, p)]; line += ` ${get_u32(buf, p)} (${fmt_const(ctx, c)})`; break; }\n case OpFmt.label: line += ` ${pos + 1 + get_i32(buf, p)}`; break;\n case OpFmt.atom: line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))}`; break;\n case OpFmt.atom_u8: line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))},${get_u8(buf, p + 4)}`; break;\n case OpFmt.atom_u16: line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))},${get_u16(buf, p + 4)}`; break;\n case OpFmt.atom_label_u8: line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))},${pos + 5 + get_i32(buf, p + 4)},${get_u8(buf, p + 8)}`; break;\n case OpFmt.atom_label_u16: line += ` ${JS_AtomGetStr(ctx, get_u32(buf, p))},${pos + 5 + get_i32(buf, p + 4)},${get_u16(buf, p + 8)}`; break;\n case OpFmt.label_u16: line += ` ${pos + 1 + get_i32(buf, p)},${get_u16(buf, p + 4)}`; break;\n default: break;\n }\n out += line + '\\n';\n pos += oi.size;\n }\n for (const c of b.cpool) {\n if (c instanceof JSFunctionBytecode) out += '\\n' + dump_byte_code(ctx, c);\n }\n return out;\n}\n\nfunction fmt_const(ctx: JSContext, c: JSValue | JSFunctionBytecode): string {\n if (c instanceof JSFunctionBytecode) return 'function ' + (c.func_name ? JS_AtomGetStr(ctx, c.func_name) : '');\n if (typeof c === 'string') return JSON.stringify(c);\n return String(c);\n}\n"]}
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JSContext, JSValue } from './quickjs.ts';
|
|
2
|
+
export interface ToGuestOptions {
|
|
3
|
+
/** convert a host value the default rules reject (class instances); return
|
|
4
|
+
* undefined to fall through to the TypeError */
|
|
5
|
+
custom?: (ctx: JSContext, value: object) => JSValue | undefined;
|
|
6
|
+
/** deep-convert the arguments guest code passes to a wrapped host function
|
|
7
|
+
* into plain host values (default: pass the guest values through) */
|
|
8
|
+
convertArgs?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function isGuestValue(v: unknown): boolean;
|
|
11
|
+
export declare function drainJobs(ctx: JSContext): void;
|
|
12
|
+
export declare function guestErrorToHost(ctx: JSContext, exc: JSValue): Error;
|
|
13
|
+
export declare function toGuest(ctx: JSContext, value: unknown, opts?: ToGuestOptions): JSValue;
|
|
14
|
+
export declare function hostFunction(ctx: JSContext, fn: (...args: any[]) => unknown, name?: string, length?: number, opts?: ToGuestOptions): JSValue;
|
|
15
|
+
export declare function hostPromise(ctx: JSContext, p: PromiseLike<unknown>, opts?: ToGuestOptions): JSValue;
|
|
16
|
+
export declare function expose(ctx: JSContext, name: string, value: unknown, opts?: ToGuestOptions): void;
|
|
17
|
+
export declare function fromGuest(ctx: JSContext, value: JSValue): unknown;
|
|
18
|
+
export declare function guestPromiseToHost(ctx: JSContext, promise: JSValue): Promise<unknown>;
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/* Embedding helpers: moving values between the host and the guest.
|
|
2
|
+
*
|
|
3
|
+
* Guest values are host values, but the sandbox requires that nothing the
|
|
4
|
+
* guest can reach has a host intrinsic in its prototype chain. A host
|
|
5
|
+
* object therefore cannot be handed to the guest as is: `toGuest` copies
|
|
6
|
+
* plain data into guest objects, wraps host functions in guest functions,
|
|
7
|
+
* and bridges host promises to guest promises. `fromGuest` does the
|
|
8
|
+
* reverse so the host gets ordinary host objects (and can call guest
|
|
9
|
+
* functions / await guest promises). Primitives cross unchanged. */
|
|
10
|
+
import { JS_IsException, JS_IsObject, JS_GetClassID, JS_GetAnyOpaque, JS_NewObject, JS_NewArrayFrom, JS_NewCFunction, JS_Call, JS_CallConstructor, JS_Throw, JS_GetException, JS_GetPropertyStr, JS_SetPropertyStr, JS_ToString, JS_NewErrorNative, JS_ExecutePendingJob, JS_IsJobPending, js_meta, } from "./quickjs.js";
|
|
11
|
+
import { JS_NewPromiseCapability } from "./builtins/promise.js";
|
|
12
|
+
import { JS_NewDate } from "./builtins/date.js";
|
|
13
|
+
import { JS_NewArrayBufferCopy } from "./builtins/typedarray.js";
|
|
14
|
+
const HOST_INTRINSIC_PROTOS = new Set([
|
|
15
|
+
Object.prototype, Array.prototype, Function.prototype, Error.prototype, Date.prototype, RegExp.prototype,
|
|
16
|
+
Map.prototype, Set.prototype, Promise.prototype, ArrayBuffer.prototype,
|
|
17
|
+
Object.getPrototypeOf(Uint8Array.prototype),
|
|
18
|
+
]);
|
|
19
|
+
/* true if the value is already safe to hand to the guest: engine metadata or
|
|
20
|
+
a prototype chain that never reaches a host intrinsic */
|
|
21
|
+
export function isGuestValue(v) {
|
|
22
|
+
if (typeof v === 'function' || (typeof v === 'object' && v !== null)) {
|
|
23
|
+
if (js_meta.has(v))
|
|
24
|
+
return true;
|
|
25
|
+
let p = v;
|
|
26
|
+
while (p !== null) {
|
|
27
|
+
if (HOST_INTRINSIC_PROTOS.has(p) || p === globalThis)
|
|
28
|
+
return false;
|
|
29
|
+
p = Object.getPrototypeOf(p);
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
/* run the guest job queue (promise reactions) until it is empty */
|
|
36
|
+
export function drainJobs(ctx) {
|
|
37
|
+
const rt = ctx.rt;
|
|
38
|
+
const pctx = { ctx: null };
|
|
39
|
+
while (JS_IsJobPending(rt))
|
|
40
|
+
JS_ExecutePendingJob(rt, pctx);
|
|
41
|
+
}
|
|
42
|
+
function guestCtor(ctx, name) {
|
|
43
|
+
return JS_GetPropertyStr(ctx, ctx.global_obj, name);
|
|
44
|
+
}
|
|
45
|
+
function throwGuestException(ctx) {
|
|
46
|
+
throw guestErrorToHost(ctx, JS_GetException(ctx));
|
|
47
|
+
}
|
|
48
|
+
/* convert a guest exception value into a host Error for host callers */
|
|
49
|
+
export function guestErrorToHost(ctx, exc) {
|
|
50
|
+
if (JS_IsObject(exc) && JS_GetClassID(exc) === 3 /* JSClassID.ERROR */) {
|
|
51
|
+
const o = exc;
|
|
52
|
+
const err = new Error(String(o.message ?? ''));
|
|
53
|
+
err.name = String(o.name ?? 'Error');
|
|
54
|
+
if (typeof o.stack === 'string')
|
|
55
|
+
err.guestStack = o.stack;
|
|
56
|
+
return err;
|
|
57
|
+
}
|
|
58
|
+
const err = new Error(typeof exc === 'string' ? exc : String(JS_ToString(ctx, exc)));
|
|
59
|
+
err.guestValue = exc;
|
|
60
|
+
return err;
|
|
61
|
+
}
|
|
62
|
+
const ERROR_KINDS = {
|
|
63
|
+
EvalError: 0 /* JSErrorEnum.EVAL_ERROR */, RangeError: 1 /* JSErrorEnum.RANGE_ERROR */, ReferenceError: 2 /* JSErrorEnum.REFERENCE_ERROR */,
|
|
64
|
+
SyntaxError: 3 /* JSErrorEnum.SYNTAX_ERROR */, TypeError: 4 /* JSErrorEnum.TYPE_ERROR */, URIError: 5 /* JSErrorEnum.URI_ERROR */,
|
|
65
|
+
};
|
|
66
|
+
/* host value -> guest value */
|
|
67
|
+
export function toGuest(ctx, value, opts = {}) {
|
|
68
|
+
return toGuestRec(ctx, value, opts, new Map());
|
|
69
|
+
}
|
|
70
|
+
function toGuestRec(ctx, v, opts, seen) {
|
|
71
|
+
switch (typeof v) {
|
|
72
|
+
case 'undefined':
|
|
73
|
+
case 'boolean':
|
|
74
|
+
case 'number':
|
|
75
|
+
case 'string':
|
|
76
|
+
case 'bigint':
|
|
77
|
+
case 'symbol':
|
|
78
|
+
return v;
|
|
79
|
+
case 'function':
|
|
80
|
+
if (isGuestValue(v))
|
|
81
|
+
return v;
|
|
82
|
+
return hostFunction(ctx, v, v.name, v.length, opts);
|
|
83
|
+
}
|
|
84
|
+
if (v === null)
|
|
85
|
+
return null;
|
|
86
|
+
const o = v;
|
|
87
|
+
if (isGuestValue(o))
|
|
88
|
+
return o;
|
|
89
|
+
const cached = seen.get(o);
|
|
90
|
+
if (cached !== undefined)
|
|
91
|
+
return cached;
|
|
92
|
+
const remember = (g) => { seen.set(o, g); return g; };
|
|
93
|
+
if (typeof o.then === 'function')
|
|
94
|
+
return remember(hostPromise(ctx, o, opts));
|
|
95
|
+
if (Array.isArray(o)) {
|
|
96
|
+
const arr = JS_NewArrayFrom(ctx, []);
|
|
97
|
+
seen.set(o, arr);
|
|
98
|
+
for (let i = 0; i < o.length; i++)
|
|
99
|
+
arr[i] = toGuestRec(ctx, o[i], opts, seen);
|
|
100
|
+
return arr;
|
|
101
|
+
}
|
|
102
|
+
if (o instanceof Date)
|
|
103
|
+
return remember(JS_NewDate(ctx, o.getTime()));
|
|
104
|
+
if (o instanceof RegExp)
|
|
105
|
+
return remember(construct(ctx, 'RegExp', [o.source, o.flags]));
|
|
106
|
+
if (o instanceof Error) {
|
|
107
|
+
const kind = ERROR_KINDS[o.name] ?? 8 /* JSErrorEnum.PLAIN_ERROR */;
|
|
108
|
+
const err = JS_NewErrorNative(ctx, kind, String(o.message));
|
|
109
|
+
return remember(err);
|
|
110
|
+
}
|
|
111
|
+
if (o instanceof Map) {
|
|
112
|
+
const m = construct(ctx, 'Map', []);
|
|
113
|
+
seen.set(o, m);
|
|
114
|
+
for (const [k, val] of o)
|
|
115
|
+
m.set(toGuestRec(ctx, k, opts, seen), toGuestRec(ctx, val, opts, seen));
|
|
116
|
+
return m;
|
|
117
|
+
}
|
|
118
|
+
if (o instanceof Set) {
|
|
119
|
+
const s = construct(ctx, 'Set', []);
|
|
120
|
+
seen.set(o, s);
|
|
121
|
+
for (const val of o)
|
|
122
|
+
s.add(toGuestRec(ctx, val, opts, seen));
|
|
123
|
+
return s;
|
|
124
|
+
}
|
|
125
|
+
if (o instanceof ArrayBuffer)
|
|
126
|
+
return remember(JS_NewArrayBufferCopy(ctx, new Uint8Array(o)));
|
|
127
|
+
if (ArrayBuffer.isView(o)) {
|
|
128
|
+
const buf = JS_NewArrayBufferCopy(ctx, new Uint8Array(o.buffer, o.byteOffset, o.byteLength));
|
|
129
|
+
const name = o[Symbol.toStringTag]; /* "Uint8Array", "DataView", ... */
|
|
130
|
+
return remember(construct(ctx, name, [buf]));
|
|
131
|
+
}
|
|
132
|
+
const proto = Object.getPrototypeOf(o);
|
|
133
|
+
if (proto === Object.prototype || proto === null) {
|
|
134
|
+
const g = JS_NewObject(ctx);
|
|
135
|
+
seen.set(o, g);
|
|
136
|
+
for (const k of Reflect.ownKeys(o)) {
|
|
137
|
+
const d = Reflect.getOwnPropertyDescriptor(o, k);
|
|
138
|
+
if (!d.enumerable)
|
|
139
|
+
continue;
|
|
140
|
+
g[k] = toGuestRec(ctx, o[k], opts, seen);
|
|
141
|
+
}
|
|
142
|
+
return g;
|
|
143
|
+
}
|
|
144
|
+
if (opts.custom) {
|
|
145
|
+
const r = opts.custom(ctx, o);
|
|
146
|
+
if (r !== undefined)
|
|
147
|
+
return remember(r);
|
|
148
|
+
}
|
|
149
|
+
throw new TypeError(`toGuest: cannot pass a host ${proto?.constructor?.name ?? 'object'} to the guest; ` +
|
|
150
|
+
'pass plain data, functions, promises, or provide a custom converter');
|
|
151
|
+
}
|
|
152
|
+
function construct(ctx, ctorName, args) {
|
|
153
|
+
const r = JS_CallConstructor(ctx, guestCtor(ctx, ctorName), args);
|
|
154
|
+
if (JS_IsException(r))
|
|
155
|
+
throwGuestException(ctx);
|
|
156
|
+
return r;
|
|
157
|
+
}
|
|
158
|
+
/* a guest function that calls the host function. Host exceptions become
|
|
159
|
+
guest errors; host return values (including promises) are converted. */
|
|
160
|
+
export function hostFunction(ctx, fn, name = fn.name || 'hostFunction', length = fn.length, opts = {}) {
|
|
161
|
+
return JS_NewCFunction(ctx, (ctx2, this_val, argv) => {
|
|
162
|
+
try {
|
|
163
|
+
const args = opts.convertArgs ? argv.map(a => fromGuest(ctx2, a)) : argv;
|
|
164
|
+
const self = opts.convertArgs ? fromGuest(ctx2, this_val) : this_val;
|
|
165
|
+
return toGuest(ctx2, fn.apply(self, args), opts);
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
return JS_Throw(ctx2, toGuest(ctx2, e, opts));
|
|
169
|
+
}
|
|
170
|
+
}, name, length);
|
|
171
|
+
}
|
|
172
|
+
/* a guest promise that settles when the host promise does; guest jobs are
|
|
173
|
+
run after the settlement so `await` continuations execute promptly */
|
|
174
|
+
export function hostPromise(ctx, p, opts = {}) {
|
|
175
|
+
const funcs = [undefined, undefined];
|
|
176
|
+
const promise = JS_NewPromiseCapability(ctx, funcs);
|
|
177
|
+
if (JS_IsException(promise))
|
|
178
|
+
throwGuestException(ctx);
|
|
179
|
+
const settle = (fn, v) => {
|
|
180
|
+
let g;
|
|
181
|
+
try {
|
|
182
|
+
g = toGuest(ctx, v, opts);
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
fn = funcs[1];
|
|
186
|
+
g = toGuest(ctx, e, opts);
|
|
187
|
+
}
|
|
188
|
+
JS_Call(ctx, fn, undefined, [g]);
|
|
189
|
+
drainJobs(ctx);
|
|
190
|
+
};
|
|
191
|
+
p.then(v => settle(funcs[0], v), e => settle(funcs[1], e));
|
|
192
|
+
return promise;
|
|
193
|
+
}
|
|
194
|
+
/* define a global variable in the guest */
|
|
195
|
+
export function expose(ctx, name, value, opts = {}) {
|
|
196
|
+
if (JS_SetPropertyStr(ctx, ctx.global_obj, name, toGuest(ctx, value, opts)) < 0)
|
|
197
|
+
throwGuestException(ctx);
|
|
198
|
+
}
|
|
199
|
+
/* guest value -> plain host value: objects and arrays are copied, guest
|
|
200
|
+
functions become host functions (that call into the guest), guest
|
|
201
|
+
promises become host promises, errors become host Errors */
|
|
202
|
+
export function fromGuest(ctx, value) {
|
|
203
|
+
return fromGuestRec(ctx, value, new Map());
|
|
204
|
+
}
|
|
205
|
+
function fromGuestRec(ctx, v, seen) {
|
|
206
|
+
if (typeof v === 'function') {
|
|
207
|
+
return (...args) => {
|
|
208
|
+
const r = JS_Call(ctx, v, undefined, args.map(a => toGuest(ctx, a)));
|
|
209
|
+
if (JS_IsException(r))
|
|
210
|
+
throwGuestException(ctx);
|
|
211
|
+
return fromGuest(ctx, r);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (typeof v !== 'object' || v === null)
|
|
215
|
+
return v;
|
|
216
|
+
const cached = seen.get(v);
|
|
217
|
+
if (cached !== undefined)
|
|
218
|
+
return cached;
|
|
219
|
+
const o = v;
|
|
220
|
+
switch (JS_GetClassID(v)) {
|
|
221
|
+
case 45 /* JSClassID.PROMISE */:
|
|
222
|
+
return guestPromiseToHost(ctx, v);
|
|
223
|
+
case 10 /* JSClassID.DATE */:
|
|
224
|
+
return new Date(JS_GetAnyOpaque(v));
|
|
225
|
+
case 3 /* JSClassID.ERROR */:
|
|
226
|
+
return guestErrorToHost(ctx, v);
|
|
227
|
+
case 18 /* JSClassID.REGEXP */:
|
|
228
|
+
return new RegExp(o.source, o.flags);
|
|
229
|
+
case 34 /* JSClassID.MAP */: {
|
|
230
|
+
const m = new Map();
|
|
231
|
+
seen.set(v, m);
|
|
232
|
+
for (const [k, val] of Map.prototype.entries.call(o))
|
|
233
|
+
m.set(fromGuestRec(ctx, k, seen), fromGuestRec(ctx, val, seen));
|
|
234
|
+
return m;
|
|
235
|
+
}
|
|
236
|
+
case 35 /* JSClassID.SET */: {
|
|
237
|
+
const s = new Set();
|
|
238
|
+
seen.set(v, s);
|
|
239
|
+
for (const val of Set.prototype.values.call(o))
|
|
240
|
+
s.add(fromGuestRec(ctx, val, seen));
|
|
241
|
+
return s;
|
|
242
|
+
}
|
|
243
|
+
case 19 /* JSClassID.ARRAY_BUFFER */:
|
|
244
|
+
/* the guest object is the host ArrayBuffer re-prototyped: copy it */
|
|
245
|
+
return new Uint8Array(o).slice().buffer;
|
|
246
|
+
}
|
|
247
|
+
if (ArrayBuffer.isView(o)) {
|
|
248
|
+
/* guest typed arrays are host views re-prototyped: copy with the host constructor */
|
|
249
|
+
const Ctor = globalThis[o[Symbol.toStringTag]];
|
|
250
|
+
return Ctor ? new Ctor(o) : new Uint8Array(o);
|
|
251
|
+
}
|
|
252
|
+
if (Array.isArray(o)) {
|
|
253
|
+
const a = [];
|
|
254
|
+
seen.set(v, a);
|
|
255
|
+
for (let i = 0; i < o.length; i++)
|
|
256
|
+
a[i] = fromGuestRec(ctx, o[i], seen);
|
|
257
|
+
return a;
|
|
258
|
+
}
|
|
259
|
+
const r = {};
|
|
260
|
+
seen.set(v, r);
|
|
261
|
+
for (const k of Reflect.ownKeys(o)) {
|
|
262
|
+
const d = Reflect.getOwnPropertyDescriptor(o, k);
|
|
263
|
+
if (!d.enumerable)
|
|
264
|
+
continue;
|
|
265
|
+
r[k] = fromGuestRec(ctx, o[k], seen);
|
|
266
|
+
}
|
|
267
|
+
return r;
|
|
268
|
+
}
|
|
269
|
+
/* a host promise that settles when the guest promise does */
|
|
270
|
+
export function guestPromiseToHost(ctx, promise) {
|
|
271
|
+
return new Promise((resolve, reject) => {
|
|
272
|
+
const then = JS_GetPropertyStr(ctx, promise, 'then');
|
|
273
|
+
const onFul = JS_NewCFunction(ctx, (_c, _t, argv) => { resolve(fromGuest(ctx, argv[0])); return undefined; }, 'resolve', 1);
|
|
274
|
+
const onRej = JS_NewCFunction(ctx, (_c, _t, argv) => { reject(fromGuestRejection(ctx, argv[0])); return undefined; }, 'reject', 1);
|
|
275
|
+
const r = JS_Call(ctx, then, promise, [onFul, onRej]);
|
|
276
|
+
if (JS_IsException(r))
|
|
277
|
+
reject(guestErrorToHost(ctx, JS_GetException(ctx)));
|
|
278
|
+
drainJobs(ctx);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
function fromGuestRejection(ctx, reason) {
|
|
282
|
+
if (JS_IsObject(reason) && JS_GetClassID(reason) === 3 /* JSClassID.ERROR */)
|
|
283
|
+
return guestErrorToHost(ctx, reason);
|
|
284
|
+
return fromGuest(ctx, reason);
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA;;;;;;;;oEAQoE;AAEpE,OAAO,EAC0B,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAC1F,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EACrF,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EACrF,oBAAoB,EAAE,eAAe,EAAE,OAAO,GAC/C,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAWjE,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAS;IAC5C,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS;IACxG,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,SAAS;IACtE,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC;CAC5C,CAAC,CAAC;AAEH;2DAC2D;AAC3D,MAAM,UAAU,YAAY,CAAC,CAAU;IACrC,IAAI,OAAO,CAAC,KAAK,UAAU,IAAI,CAAC,OAAO,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AI,GAAG,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACrD,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAC5H,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QACnI,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QACtD,IAAI,cAAc,CAAC,CAAC,CAAC;YAAE,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC3E,SAAS,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAc,EAAE,MAAe;IACzD,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,4BAAoB;QAAE,OAAO,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3G,OAAO,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/* Embedding helpers: moving values between the host and the guest.\n *\n * Guest values are host values, but the sandbox requires that nothing the\n * guest can reach has a host intrinsic in its prototype chain. A host\n * object therefore cannot be handed to the guest as is: `toGuest` copies\n * plain data into guest objects, wraps host functions in guest functions,\n * and bridges host promises to guest promises. `fromGuest` does the\n * reverse so the host gets ordinary host objects (and can call guest\n * functions / await guest promises). Primitives cross unchanged. */\n\nimport {\n JSContext, JSValue, JSClassID, JS_IsException, JS_IsObject, JS_GetClassID, JS_GetAnyOpaque,\n JS_NewObject, JS_NewArrayFrom, JS_NewCFunction, JS_Call, JS_CallConstructor, JS_Throw,\n JS_GetException, JS_GetPropertyStr, JS_SetPropertyStr, JS_ToString, JS_NewErrorNative,\n JS_ExecutePendingJob, JS_IsJobPending, js_meta,\n} from './quickjs.ts';\nimport { JSErrorEnum } from './values.ts';\nimport { JS_NewPromiseCapability } from './builtins/promise.ts';\nimport { JS_NewDate } from './builtins/date.ts';\nimport { JS_NewArrayBufferCopy } from './builtins/typedarray.ts';\n\nexport interface ToGuestOptions {\n /** convert a host value the default rules reject (class instances); return\n * undefined to fall through to the TypeError */\n custom?: (ctx: JSContext, value: object) => JSValue | undefined;\n /** deep-convert the arguments guest code passes to a wrapped host function\n * into plain host values (default: pass the guest values through) */\n convertArgs?: boolean;\n}\n\nconst HOST_INTRINSIC_PROTOS = new Set<object>([\n Object.prototype, Array.prototype, Function.prototype, Error.prototype, Date.prototype, RegExp.prototype,\n Map.prototype, Set.prototype, Promise.prototype, ArrayBuffer.prototype,\n Object.getPrototypeOf(Uint8Array.prototype),\n]);\n\n/* true if the value is already safe to hand to the guest: engine metadata or\n a prototype chain that never reaches a host intrinsic */\nexport function isGuestValue(v: unknown): boolean {\n if (typeof v === 'function' || (typeof v === 'object' && v !== null)) {\n if (js_meta.has(v as object)) return true;\n let p: object | null = v as object;\n while (p !== null) {\n if (HOST_INTRINSIC_PROTOS.has(p) || p === globalThis) return false;\n p = Object.getPrototypeOf(p);\n }\n return true;\n }\n return true;\n}\n\n/* run the guest job queue (promise reactions) until it is empty */\nexport function drainJobs(ctx: JSContext): void {\n const rt = ctx.rt;\n const pctx = { ctx: null as JSContext | null };\n while (JS_IsJobPending(rt)) JS_ExecutePendingJob(rt, pctx);\n}\n\nfunction guestCtor(ctx: JSContext, name: string): JSValue {\n return JS_GetPropertyStr(ctx, ctx.global_obj, name);\n}\n\nfunction throwGuestException(ctx: JSContext): never {\n throw guestErrorToHost(ctx, JS_GetException(ctx));\n}\n\n/* convert a guest exception value into a host Error for host callers */\nexport function guestErrorToHost(ctx: JSContext, exc: JSValue): Error {\n if (JS_IsObject(exc) && JS_GetClassID(exc) === JSClassID.ERROR) {\n const o = exc as any;\n const err = new Error(String(o.message ?? ''));\n err.name = String(o.name ?? 'Error');\n if (typeof o.stack === 'string') (err as any).guestStack = o.stack;\n return err;\n }\n const err = new Error(typeof exc === 'string' ? exc : String(JS_ToString(ctx, exc)));\n (err as any).guestValue = exc;\n return err;\n}\n\nconst ERROR_KINDS: Record<string, JSErrorEnum> = {\n EvalError: JSErrorEnum.EVAL_ERROR, RangeError: JSErrorEnum.RANGE_ERROR, ReferenceError: JSErrorEnum.REFERENCE_ERROR,\n SyntaxError: JSErrorEnum.SYNTAX_ERROR, TypeError: JSErrorEnum.TYPE_ERROR, URIError: JSErrorEnum.URI_ERROR,\n};\n\n/* host value -> guest value */\nexport function toGuest(ctx: JSContext, value: unknown, opts: ToGuestOptions = {}): JSValue {\n return toGuestRec(ctx, value, opts, new Map());\n}\n\nfunction toGuestRec(ctx: JSContext, v: unknown, opts: ToGuestOptions, seen: Map<object, JSValue>): JSValue {\n switch (typeof v) {\n case 'undefined': case 'boolean': case 'number': case 'string': case 'bigint': case 'symbol':\n return v as JSValue;\n case 'function':\n if (isGuestValue(v)) return v as JSValue;\n return hostFunction(ctx, v as (...args: any[]) => unknown, (v as Function).name, (v as Function).length, opts);\n }\n if (v === null) return null;\n const o = v as any;\n if (isGuestValue(o)) return o;\n const cached = seen.get(o);\n if (cached !== undefined) return cached;\n const remember = (g: JSValue): JSValue => { seen.set(o, g); return g; };\n\n if (typeof o.then === 'function') return remember(hostPromise(ctx, o, opts));\n if (Array.isArray(o)) {\n const arr = JS_NewArrayFrom(ctx, []) as any;\n seen.set(o, arr);\n for (let i = 0; i < o.length; i++) arr[i] = toGuestRec(ctx, o[i], opts, seen);\n return arr;\n }\n if (o instanceof Date) return remember(JS_NewDate(ctx, o.getTime()));\n if (o instanceof RegExp) return remember(construct(ctx, 'RegExp', [o.source, o.flags]));\n if (o instanceof Error) {\n const kind = ERROR_KINDS[o.name] ?? JSErrorEnum.PLAIN_ERROR;\n const err = JS_NewErrorNative(ctx, kind, String(o.message));\n return remember(err);\n }\n if (o instanceof Map) {\n const m = construct(ctx, 'Map', []) as any;\n seen.set(o, m);\n for (const [k, val] of o) m.set(toGuestRec(ctx, k, opts, seen), toGuestRec(ctx, val, opts, seen));\n return m;\n }\n if (o instanceof Set) {\n const s = construct(ctx, 'Set', []) as any;\n seen.set(o, s);\n for (const val of o) s.add(toGuestRec(ctx, val, opts, seen));\n return s;\n }\n if (o instanceof ArrayBuffer) return remember(JS_NewArrayBufferCopy(ctx, new Uint8Array(o)));\n if (ArrayBuffer.isView(o)) {\n const buf = JS_NewArrayBufferCopy(ctx, new Uint8Array(o.buffer, o.byteOffset, o.byteLength));\n const name = (o as any)[Symbol.toStringTag] as string; /* \"Uint8Array\", \"DataView\", ... */\n return remember(construct(ctx, name, [buf]));\n }\n const proto = Object.getPrototypeOf(o);\n if (proto === Object.prototype || proto === null) {\n const g = JS_NewObject(ctx) as any;\n seen.set(o, g);\n for (const k of Reflect.ownKeys(o)) {\n const d = Reflect.getOwnPropertyDescriptor(o, k)!;\n if (!d.enumerable) continue;\n g[k] = toGuestRec(ctx, o[k], opts, seen);\n }\n return g;\n }\n if (opts.custom) {\n const r = opts.custom(ctx, o);\n if (r !== undefined) return remember(r);\n }\n throw new TypeError(`toGuest: cannot pass a host ${proto?.constructor?.name ?? 'object'} to the guest; ` +\n 'pass plain data, functions, promises, or provide a custom converter');\n}\n\nfunction construct(ctx: JSContext, ctorName: string, args: unknown[]): JSValue {\n const r = JS_CallConstructor(ctx, guestCtor(ctx, ctorName), args as JSValue[]);\n if (JS_IsException(r)) throwGuestException(ctx);\n return r;\n}\n\n/* a guest function that calls the host function. Host exceptions become\n guest errors; host return values (including promises) are converted. */\nexport function hostFunction(ctx: JSContext, fn: (...args: any[]) => unknown, name = fn.name || 'hostFunction',\n length = fn.length, opts: ToGuestOptions = {}): JSValue {\n return JS_NewCFunction(ctx, (ctx2: JSContext, this_val: JSValue, argv: JSValue[]) => {\n try {\n const args = opts.convertArgs ? argv.map(a => fromGuest(ctx2, a)) : argv;\n const self = opts.convertArgs ? fromGuest(ctx2, this_val) : this_val;\n return toGuest(ctx2, fn.apply(self, args), opts);\n } catch (e) {\n return JS_Throw(ctx2, toGuest(ctx2, e, opts));\n }\n }, name, length);\n}\n\n/* a guest promise that settles when the host promise does; guest jobs are\n run after the settlement so `await` continuations execute promptly */\nexport function hostPromise(ctx: JSContext, p: PromiseLike<unknown>, opts: ToGuestOptions = {}): JSValue {\n const funcs: [JSValue, JSValue] = [undefined, undefined];\n const promise = JS_NewPromiseCapability(ctx, funcs);\n if (JS_IsException(promise)) throwGuestException(ctx);\n const settle = (fn: JSValue, v: unknown) => {\n let g: JSValue;\n try { g = toGuest(ctx, v, opts); } catch (e) { fn = funcs[1]; g = toGuest(ctx, e, opts); }\n JS_Call(ctx, fn, undefined, [g]);\n drainJobs(ctx);\n };\n p.then(v => settle(funcs[0], v), e => settle(funcs[1], e));\n return promise;\n}\n\n/* define a global variable in the guest */\nexport function expose(ctx: JSContext, name: string, value: unknown, opts: ToGuestOptions = {}): void {\n if (JS_SetPropertyStr(ctx, ctx.global_obj, name, toGuest(ctx, value, opts)) < 0) throwGuestException(ctx);\n}\n\n/* guest value -> plain host value: objects and arrays are copied, guest\n functions become host functions (that call into the guest), guest\n promises become host promises, errors become host Errors */\nexport function fromGuest(ctx: JSContext, value: JSValue): unknown {\n return fromGuestRec(ctx, value, new Map());\n}\n\nfunction fromGuestRec(ctx: JSContext, v: JSValue, seen: Map<object, unknown>): unknown {\n if (typeof v === 'function') {\n return (...args: unknown[]) => {\n const r = JS_Call(ctx, v, undefined, args.map(a => toGuest(ctx, a)));\n if (JS_IsException(r)) throwGuestException(ctx);\n return fromGuest(ctx, r);\n };\n }\n if (typeof v !== 'object' || v === null) return v;\n const cached = seen.get(v);\n if (cached !== undefined) return cached;\n const o = v as any;\n switch (JS_GetClassID(v)) {\n case JSClassID.PROMISE:\n return guestPromiseToHost(ctx, v);\n case JSClassID.DATE:\n return new Date(JS_GetAnyOpaque(v) as number);\n case JSClassID.ERROR:\n return guestErrorToHost(ctx, v);\n case JSClassID.REGEXP:\n return new RegExp(o.source, o.flags);\n case JSClassID.MAP: {\n const m = new Map(); seen.set(v, m);\n for (const [k, val] of Map.prototype.entries.call(o)) m.set(fromGuestRec(ctx, k, seen), fromGuestRec(ctx, val, seen));\n return m;\n }\n case JSClassID.SET: {\n const s = new Set(); seen.set(v, s);\n for (const val of Set.prototype.values.call(o)) s.add(fromGuestRec(ctx, val, seen));\n return s;\n }\n case JSClassID.ARRAY_BUFFER:\n /* the guest object is the host ArrayBuffer re-prototyped: copy it */\n return new Uint8Array(o as ArrayBuffer).slice().buffer;\n }\n if (ArrayBuffer.isView(o)) {\n /* guest typed arrays are host views re-prototyped: copy with the host constructor */\n const Ctor = (globalThis as any)[(o as any)[Symbol.toStringTag]];\n return Ctor ? new Ctor(o as any) : new Uint8Array(o as any);\n }\n if (Array.isArray(o)) {\n const a: unknown[] = []; seen.set(v, a);\n for (let i = 0; i < o.length; i++) a[i] = fromGuestRec(ctx, o[i], seen);\n return a;\n }\n const r: Record<PropertyKey, unknown> = {}; seen.set(v, r);\n for (const k of Reflect.ownKeys(o)) {\n const d = Reflect.getOwnPropertyDescriptor(o, k)!;\n if (!d.enumerable) continue;\n r[k] = fromGuestRec(ctx, o[k], seen);\n }\n return r;\n}\n\n/* a host promise that settles when the guest promise does */\nexport function guestPromiseToHost(ctx: JSContext, promise: JSValue): Promise<unknown> {\n return new Promise((resolve, reject) => {\n const then = JS_GetPropertyStr(ctx, promise, 'then');\n const onFul = JS_NewCFunction(ctx, (_c, _t, argv) => { resolve(fromGuest(ctx, argv[0])); return undefined; }, 'resolve', 1);\n const onRej = JS_NewCFunction(ctx, (_c, _t, argv) => { reject(fromGuestRejection(ctx, argv[0])); return undefined; }, 'reject', 1);\n const r = JS_Call(ctx, then, promise, [onFul, onRej]);\n if (JS_IsException(r)) reject(guestErrorToHost(ctx, JS_GetException(ctx)));\n drainJobs(ctx);\n });\n}\n\nfunction fromGuestRejection(ctx: JSContext, reason: JSValue): unknown {\n if (JS_IsObject(reason) && JS_GetClassID(reason) === JSClassID.ERROR) return guestErrorToHost(ctx, reason);\n return fromGuest(ctx, reason);\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { JSContext, JSRuntime, JSValue, JSObject, JSAtom, JSClassID, JSFunctionBytecode, JSVarRef, JSStackFrame, JSAsyncFunctionState, JSCFunctionListEntry } from './quickjs.ts';
|
|
2
|
+
export declare const ARG_SCOPE_END = -2;
|
|
3
|
+
export declare const GEN_MAGIC_NEXT = 0;
|
|
4
|
+
export declare const GEN_MAGIC_RETURN = 1;
|
|
5
|
+
export declare const GEN_MAGIC_THROW = 2;
|
|
6
|
+
export declare function js_class_has_bytecode(class_id: JSClassID): boolean;
|
|
7
|
+
export declare function get_var_ref(ctx: JSContext, sf: JSStackFrame, var_idx: number, is_arg: boolean): JSVarRef;
|
|
8
|
+
export declare function close_var_refs(rt: JSRuntime, sf: JSStackFrame): void;
|
|
9
|
+
export declare function close_lexical_var(ctx: JSContext, sf: JSStackFrame, var_idx: number): void;
|
|
10
|
+
export declare function js_closure_from_refs(ctx: JSContext, b: JSFunctionBytecode, var_refs: JSVarRef[], proto: JSValue | null, is_ctor: boolean): JSValue;
|
|
11
|
+
export declare function js_closure2(ctx: JSContext, b: JSFunctionBytecode, cur_var_refs: JSVarRef[] | null, sf: JSStackFrame | null, proto: JSValue | null, is_ctor: boolean): JSValue;
|
|
12
|
+
export declare function js_function_set_properties(ctx: JSContext, func_obj: JSValue, name: JSAtom, len: number): void;
|
|
13
|
+
export declare function js_closure(ctx: JSContext, b: JSFunctionBytecode, cur_var_refs: JSVarRef[] | null, sf: JSStackFrame | null): JSValue;
|
|
14
|
+
export declare function js_build_arguments(ctx: JSContext, argc: number, argv: JSValue[]): JSValue;
|
|
15
|
+
export declare function js_build_mapped_arguments(ctx: JSContext, argc: number, argv: JSValue[], sf: JSStackFrame, arg_count: number): JSValue;
|
|
16
|
+
export declare function js_build_rest(ctx: JSContext, first: number, argc: number, argv: JSValue[]): JSValue;
|
|
17
|
+
export declare function JS_DefinePrivateField(ctx: JSContext, obj: JSValue, name: JSValue, val: JSValue): number;
|
|
18
|
+
export declare function JS_GetPrivateField(ctx: JSContext, obj: JSValue, name: JSValue): JSValue;
|
|
19
|
+
export declare function JS_SetPrivateField(ctx: JSContext, obj: JSValue, name: JSValue, val: JSValue): number;
|
|
20
|
+
export declare function JS_AddBrand(ctx: JSContext, obj: JSValue, home_obj: JSValue): number;
|
|
21
|
+
export declare function JS_CheckBrand(ctx: JSContext, obj: JSValue, func: JSValue): number;
|
|
22
|
+
export declare function js_operator_private_in(ctx: JSContext, op1: JSValue, op2: JSValue): number;
|
|
23
|
+
export declare function js_method_set_home_object(ctx: JSContext, func_obj: JSValue, home_obj: JSValue): void;
|
|
24
|
+
export declare function js_get_function_name(ctx: JSContext, name: JSAtom): string;
|
|
25
|
+
export declare function js_method_set_properties(ctx: JSContext, func_obj: JSValue, name: JSAtom, flags: number, home_obj: JSValue): number;
|
|
26
|
+
export declare function JS_DefineObjectName(ctx: JSContext, obj: JSValue, name: JSAtom, flags: number): number;
|
|
27
|
+
export declare function JS_DefineObjectNameComputed(ctx: JSContext, obj: JSValue, str: JSValue, flags: number): number;
|
|
28
|
+
export declare function js_define_class(ctx: JSContext, class_name: JSAtom, class_flags: number, parent_class: JSValue, b: JSFunctionBytecode, var_refs: JSVarRef[], is_computed_name: boolean, computed_name: JSValue): [JSValue, JSValue] | null;
|
|
29
|
+
export declare function js_function_apply(ctx: JSContext, this_val: JSValue, argv: JSValue[], magic: number): JSValue;
|
|
30
|
+
export declare function JS_CallInternal(ctx: JSContext, func_obj: JSValue, this_obj: JSValue, new_target: JSValue, argv: JSValue[], flags: number): JSValue;
|
|
31
|
+
export declare let jit_osr_threshold: number;
|
|
32
|
+
export declare function jit_set_osr_threshold(n: number): void;
|
|
33
|
+
export declare function async_func_init(ctx: JSContext, func_obj: JSValue, this_obj: JSValue, argv: JSValue[]): JSAsyncFunctionState;
|
|
34
|
+
export declare function async_func_resume(ctx: JSContext, s: JSAsyncFunctionState): JSValue;
|
|
35
|
+
export declare function js_generator_next(ctx: JSContext, this_val: JSValue, argv: JSValue[], pdone: {
|
|
36
|
+
done: number;
|
|
37
|
+
}, magic: number): JSValue;
|
|
38
|
+
export declare function js_generator_function_call(ctx: JSContext, func_obj: JSValue, this_obj: JSValue, argv: JSValue[], flags: number): JSValue;
|
|
39
|
+
export declare const js_generator_proto_funcs: JSCFunctionListEntry[];
|
|
40
|
+
export declare const js_generator_function_proto_funcs: JSCFunctionListEntry[];
|
|
41
|
+
export declare function js_async_function_call(ctx: JSContext, func_obj: JSValue, this_obj: JSValue, argv: JSValue[], flags: number): JSValue;
|
|
42
|
+
export declare const js_async_function_proto_funcs: JSCFunctionListEntry[];
|
|
43
|
+
export declare const enum JSAsyncGeneratorState {
|
|
44
|
+
SUSPENDED_START = 0,
|
|
45
|
+
SUSPENDED_YIELD = 1,
|
|
46
|
+
SUSPENDED_YIELD_STAR = 2,
|
|
47
|
+
EXECUTING = 3,
|
|
48
|
+
AWAITING_RETURN = 4,
|
|
49
|
+
COMPLETED = 5
|
|
50
|
+
}
|
|
51
|
+
export declare class JSAsyncGeneratorRequest {
|
|
52
|
+
completion_type: number;
|
|
53
|
+
result: JSValue;
|
|
54
|
+
promise: JSValue;
|
|
55
|
+
resolving_funcs: [JSValue, JSValue];
|
|
56
|
+
constructor(completion_type: number, result: JSValue, promise: JSValue, resolving_funcs: [JSValue, JSValue]);
|
|
57
|
+
}
|
|
58
|
+
export declare class JSAsyncGeneratorData {
|
|
59
|
+
generator: JSObject | null;
|
|
60
|
+
state: JSAsyncGeneratorState;
|
|
61
|
+
func_state: JSAsyncFunctionState | null;
|
|
62
|
+
queue: JSAsyncGeneratorRequest[];
|
|
63
|
+
}
|
|
64
|
+
export declare function js_async_generator_next(ctx: JSContext, this_val: JSValue, argv: JSValue[], magic: number): JSValue;
|
|
65
|
+
export declare function js_async_generator_function_call(ctx: JSContext, func_obj: JSValue, this_obj: JSValue, argv: JSValue[], flags: number): JSValue;
|
|
66
|
+
export declare const js_async_generator_proto_funcs: JSCFunctionListEntry[];
|
|
67
|
+
export declare const js_async_generator_function_proto_funcs: JSCFunctionListEntry[];
|
|
68
|
+
export declare class JSAsyncFromSyncIteratorData {
|
|
69
|
+
sync_iter: JSValue;
|
|
70
|
+
next_method: JSValue;
|
|
71
|
+
constructor(sync_iter: JSValue, next_method: JSValue);
|
|
72
|
+
}
|
|
73
|
+
export declare function JS_CreateAsyncFromSyncIterator(ctx: JSContext, sync_iter: JSValue): JSValue;
|
|
74
|
+
export declare const js_async_from_sync_iterator_proto_funcs: JSCFunctionListEntry[];
|
|
75
|
+
export declare function js_for_of_start_value(ctx: JSContext, obj: JSValue, is_async: boolean): [JSValue, JSValue] | null;
|
|
76
|
+
export declare function js_for_of_next_value(ctx: JSContext, iter: JSValue, next: JSValue): {
|
|
77
|
+
value: JSValue;
|
|
78
|
+
done: boolean;
|
|
79
|
+
} | null;
|
|
80
|
+
export declare function js_append_enumerate_value(ctx: JSContext, target: JSValue, pos: number, src: JSValue): number;
|
|
81
|
+
export declare function js_build_arguments_value(ctx: JSContext, argv: JSValue[]): JSValue;
|