jseption 0.0.2 → 0.0.3

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 CHANGED
@@ -33,6 +33,7 @@ JSEPTION_JIT=0 bun test # run the suite on the interpreter tier only
33
33
  JSEPTION_JIT=always bun test # compile every function that runs (no lazy tier-up)
34
34
  JSEPTION_JIT_DUMP=1 bun run src/qjs.ts file.js # print the generated host code
35
35
  bun run bench/inproc.ts # host vs tier modes, incl. cold-code bundles
36
+ bun run bench/bytecode.ts file.js # compile vs read precompiled bytecode vs run
36
37
  ```
37
38
 
38
39
  ## Installing
@@ -72,6 +73,37 @@ engine metadata kept in a `WeakMap`). Engine code signals exceptions with the
72
73
  the two conventions meet at the call boundary. See `docs/PORTING.md` and
73
74
  `docs/HOST_VALUES.md` for the internals.
74
75
 
76
+ ## Precompiled bytecode
77
+
78
+ A script can be compiled ahead of time and loaded without parsing, as with QuickJS's
79
+ `JS_WriteObject` / `JS_ReadObject`:
80
+
81
+ ```ts
82
+ import { JS_Eval, JS_EVAL_TYPE_GLOBAL, JS_EVAL_FLAG_COMPILE_ONLY, JS_WriteObject, JS_ReadObject,
83
+ JS_EvalFunction, JS_IsException } from 'jseption';
84
+
85
+ /* at build time */
86
+ const fn = JS_Eval(ctx, src, 'runtime.js', JS_EVAL_TYPE_GLOBAL | JS_EVAL_FLAG_COMPILE_ONLY);
87
+ const bytes = JS_WriteObject(ctx, fn); /* Uint8Array, or null with an exception pending */
88
+
89
+ /* at run time, in any runtime of the same jseption version */
90
+ const loaded = JS_ReadObject(ctx2, bytes); /* JS_EXCEPTION (a SyntaxError) on bad input */
91
+ if (!JS_IsException(loaded)) JS_EvalFunction(ctx2, loaded);
92
+ ```
93
+
94
+ Reading is 18x (host JIT on) to 37x (JIT off, as on iOS) faster than parsing a 300 KB
95
+ bundle. Line numbers in error stacks are kept; function source text (for
96
+ `Function.prototype.toString`) is dropped unless `JS_WRITE_OBJ_SOURCE` is passed. The
97
+ bytes record the jseption version and only load in that version.
98
+
99
+ **Only load bytecode you produced yourself.** As in QuickJS, the reader checks the format
100
+ (version, bounds, tags, indices, instruction boundaries, a checksum) but not the meaning
101
+ of the byte code: hand-made bytecode can reach engine states the parser never produces,
102
+ so loading untrusted bytecode is not safe even though running untrusted source is. The
103
+ checksum only catches accidental corruption; bytecode that passes through storage or a
104
+ service you do not control needs a signature you verify before loading. See
105
+ `docs/BYTECODE.md` for the format and the measurements.
106
+
75
107
  ## Passing values between host and guest
76
108
 
77
109
  Guest values are host values, but the sandbox forbids handing the guest an object whose
@@ -106,6 +138,7 @@ src/values.ts JSValue, object metadata, bytecode & frame structures
106
138
  src/opcodes.ts opcode table generated from quickjs-opcode.h
107
139
  src/quickjs.ts runtime, context, property layer over Reflect, calls, conversions, jobs
108
140
  src/parser.ts tokenizer, parser, bytecode emitter, variable/label resolution, eval
141
+ src/bytecode.ts bytecode serialization (JS_WriteObject / JS_ReadObject)
109
142
  src/interpreter.ts JS_CallInternal, closures, generators, async functions (fallback tier)
110
143
  src/jit.ts bytecode -> host JavaScript compiler (stack-to-register, relooper)
111
144
  src/jit_runtime.ts the helpers generated code calls into (the only engine touchpoint)
@@ -181,8 +214,9 @@ Differences from the C implementation:
181
214
  * Memory management relies on the host garbage collector: there is no reference
182
215
  counting, `JS_FreeValue`/`JS_DupValue` are no-ops, and `WeakRef` / `FinalizationRegistry`
183
216
  use the host weak references.
184
- * ES modules (`import` / `export`), `Atomics`, `SharedArrayBuffer` threads and the
185
- bytecode serialization (`JS_WriteObject` / `JS_ReadObject`) are not ported.
217
+ * ES modules (`import` / `export`), `Atomics` and `SharedArrayBuffer` threads are not
218
+ ported. `JS_WriteObject` / `JS_ReadObject` serialize compiled scripts (bytecode
219
+ function trees) only, not arbitrary values, in a jseption-specific format.
186
220
  * Number formatting and parsing use the host conversions (they are specified by
187
221
  ECMAScript, so the results are identical).
188
222
 
@@ -0,0 +1,6 @@
1
+ import { JSContext, JSValue } from './quickjs.ts';
2
+ export declare const JS_WRITE_OBJ_SOURCE: number;
3
+ export declare const BC_MAGIC: number[];
4
+ export declare const BC_FORMAT = 1;
5
+ export declare function JS_WriteObject(ctx: JSContext, obj: JSValue, flags?: number): Uint8Array | null;
6
+ export declare function JS_ReadObject(ctx: JSContext, buf: Uint8Array): JSValue;
@@ -0,0 +1,911 @@
1
+ /*
2
+ * Bytecode serialization: JS_WriteObject / JS_ReadObject.
3
+ *
4
+ * Writes the function tree produced by JS_EVAL_FLAG_COMPILE_ONLY to bytes and
5
+ * reads it back into any runtime of the same jseption version, so that a
6
+ * script can be compiled ahead of time and loaded without parsing. The design
7
+ * follows quickjs.c (bc_write_* / bc_read_*): atoms are runtime specific, so
8
+ * the writer emits an atom table and renumbers every atom (in the function
9
+ * fields and in the atom operands of the byte code, found by walking the
10
+ * opcodes by their format), and the reader interns the strings in its own
11
+ * runtime and patches the operands back.
12
+ *
13
+ * Only load bytecode you produced yourself: like in QuickJS, the reader checks
14
+ * the format (header, bounds, tags, indices, opcode boundaries, checksum), not
15
+ * the semantics of the byte code, and hand-made byte code can reach states the
16
+ * parser never emits.
17
+ *
18
+ * Format (all integers are unsigned LEB128 unless stated otherwise):
19
+ *
20
+ * magic 4 bytes "JSBC"
21
+ * format u8 (BC_FORMAT)
22
+ * version length + ASCII bytes: the jseption package version
23
+ * flags BC_FLAG_*
24
+ * strings count, then per string (length << 1 | wide), then the
25
+ * byte length and bytes of the Latin-1 blob, then the
26
+ * byte length and bytes of the UTF-16LE blob
27
+ * atoms count, then the string index of each atom
28
+ * root a tagged value (BC_TAG_FUNCTION_BYTECODE)
29
+ * checksum 8 bytes: two 32-bit little-endian sums (Fletcher style, over
30
+ * little-endian 32-bit words) of everything before them
31
+ *
32
+ * Atom references (function fields and byte code operands) use the encoding of
33
+ * bc_atom_to_idx: predefined atoms (< JS_ATOM_END) and tagged integer atoms are
34
+ * kept, other atoms become JS_ATOM_END + their index in the atom table.
35
+ */
36
+ import { JS_ATOM_END, JS_ATOM_raw, JS_ATOM_TAG_INT, JS_ATOM_TYPE_STRING, __JS_AtomIsTaggedInt } from "./atoms.js";
37
+ import { JS_GetFunctionData, JS_ThrowSyntaxError, JS_ThrowTypeError, JS_NewArray, JS_DefinePropertyValue, JS_DefinePropertyValueUint32, JS_IsException, JS_PROP_ENUMERABLE, hooks } from "./quickjs.js";
38
+ import { JSClosureVar, JSFunctionBytecode, JSVarDef } from "./values.js";
39
+ import { short_opcode_info } from "./opcodes.js";
40
+ import { JSEPTION_VERSION } from "./version.js";
41
+ /* keep each function's source text (Function.prototype.toString); off by default */
42
+ export const JS_WRITE_OBJ_SOURCE = 1 << 0;
43
+ export const BC_MAGIC = [0x4a, 0x53, 0x42, 0x43]; /* "JSBC" */
44
+ export const BC_FORMAT = 1;
45
+ const BC_FLAG_SOURCE = 1 << 0;
46
+ /* JSFunctionBytecode flags */
47
+ const F_HAS_PROTOTYPE = 1 << 0;
48
+ const F_SIMPLE_PARAMS = 1 << 1;
49
+ const F_DERIVED_CTOR = 1 << 2;
50
+ const F_HOME_OBJECT = 1 << 3;
51
+ const F_NEW_TARGET = 1 << 4;
52
+ const F_SUPER_CALL = 1 << 5;
53
+ const F_SUPER = 1 << 6;
54
+ const F_ARGUMENTS = 1 << 7;
55
+ const F_HAS_DEBUG = 1 << 8;
56
+ const F_EVAL = 1 << 9;
57
+ const F_HAS_SOURCE = 1 << 10;
58
+ /* JSVarDef / JSClosureVar flags */
59
+ const V_CONST = 1 << 0;
60
+ const V_LEXICAL = 1 << 1;
61
+ const V_CAPTURED = 1 << 2;
62
+ const V_STATIC_PRIVATE = 1 << 3;
63
+ const V_LOCAL = 1 << 4;
64
+ const V_ARG = 1 << 5;
65
+ const VAR_KIND_MAX = 9 /* JSVarKind.PRIVATE_GETTER_SETTER */;
66
+ /* the size of each opcode of the final byte code (0: not an opcode) and what its operand
67
+ holds, indexed by the opcode byte, so that walking the byte code costs a few array reads
68
+ per instruction */
69
+ const OPK_ATOM = 1, OPK_CONST = 2, OPK_CONST8 = 3, OPK_FCLOSURE = 4, OPK_FCLOSURE8 = 5;
70
+ const OP_SIZE = new Uint8Array(256);
71
+ const OP_KIND = new Uint8Array(256);
72
+ for (let op = 0; op < 256; op++) {
73
+ const info = short_opcode_info(op);
74
+ if (info === undefined)
75
+ continue;
76
+ OP_SIZE[op] = info.size;
77
+ switch (info.fmt) {
78
+ case 23 /* OpFmt.atom */:
79
+ case 24 /* OpFmt.atom_u8 */:
80
+ case 25 /* OpFmt.atom_u16 */:
81
+ case 26 /* OpFmt.atom_label_u8 */:
82
+ case 27 /* OpFmt.atom_label_u16 */:
83
+ OP_KIND[op] = OPK_ATOM;
84
+ break;
85
+ case 21 /* OpFmt.const */:
86
+ OP_KIND[op] = OPK_CONST;
87
+ break;
88
+ case 8 /* OpFmt.const8 */:
89
+ OP_KIND[op] = OPK_CONST8;
90
+ break;
91
+ }
92
+ }
93
+ OP_KIND[3 /* OP.fclosure */] = OPK_FCLOSURE;
94
+ OP_KIND[194 /* OP.fclosure8 */] = OPK_FCLOSURE8;
95
+ /* ---------------------------------------------------------------------
96
+ Writer
97
+ --------------------------------------------------------------------- */
98
+ class BCWriteError extends Error {
99
+ }
100
+ class ByteBuf {
101
+ buf = new Uint8Array(4096);
102
+ len = 0;
103
+ f64 = new Float64Array(1);
104
+ f64b = new Uint8Array(this.f64.buffer);
105
+ grow(n) {
106
+ let size = this.buf.length * 2;
107
+ while (size < this.len + n)
108
+ size *= 2;
109
+ const b = new Uint8Array(size);
110
+ b.set(this.buf.subarray(0, this.len));
111
+ this.buf = b;
112
+ }
113
+ u8(v) {
114
+ if (this.len >= this.buf.length)
115
+ this.grow(1);
116
+ this.buf[this.len++] = v;
117
+ }
118
+ leb(v) {
119
+ if (this.len + 5 > this.buf.length)
120
+ this.grow(5);
121
+ const buf = this.buf;
122
+ while (v >= 0x80) {
123
+ buf[this.len++] = (v % 0x80) | 0x80;
124
+ v = Math.floor(v / 0x80);
125
+ }
126
+ buf[this.len++] = v;
127
+ }
128
+ sleb(v) {
129
+ this.leb(v < 0 ? -2 * v - 1 : 2 * v);
130
+ }
131
+ f64v(v) {
132
+ if (this.len + 8 > this.buf.length)
133
+ this.grow(8);
134
+ this.f64[0] = v;
135
+ const b = this.f64b;
136
+ /* little endian on the wire */
137
+ if (LITTLE_ENDIAN)
138
+ for (let i = 0; i < 8; i++)
139
+ this.buf[this.len++] = b[i];
140
+ else
141
+ for (let i = 7; i >= 0; i--)
142
+ this.buf[this.len++] = b[i];
143
+ }
144
+ bytes(src) {
145
+ if (this.len + src.length > this.buf.length)
146
+ this.grow(src.length);
147
+ this.buf.set(src, this.len);
148
+ this.len += src.length;
149
+ }
150
+ result() { return this.buf.slice(0, this.len); }
151
+ }
152
+ const LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
153
+ class BCWriter {
154
+ ctx;
155
+ flags;
156
+ out = new ByteBuf();
157
+ strings = [];
158
+ string_idx = new Map();
159
+ atoms = []; /* string index of each atom table entry */
160
+ atom_idx = new Map();
161
+ constructor(ctx, flags) {
162
+ this.ctx = ctx;
163
+ this.flags = flags;
164
+ }
165
+ string_ref(s) {
166
+ let i = this.string_idx.get(s);
167
+ if (i === undefined) {
168
+ i = this.strings.length;
169
+ this.strings.push(s);
170
+ this.string_idx.set(s, i);
171
+ }
172
+ return i;
173
+ }
174
+ /* bc_atom_to_idx */
175
+ atom_to_idx(atom) {
176
+ if (atom < JS_ATOM_END || __JS_AtomIsTaggedInt(atom))
177
+ return atom;
178
+ let i = this.atom_idx.get(atom);
179
+ if (i === undefined) {
180
+ const atoms = this.ctx.rt.atoms;
181
+ if (atoms.getType(atom) !== JS_ATOM_TYPE_STRING)
182
+ throw new BCWriteError('cannot serialize a symbol atom: ' + atoms.toDisplayStr(atom));
183
+ i = this.atoms.length;
184
+ this.atoms.push(this.string_ref(atoms.toStr(atom)));
185
+ this.atom_idx.set(atom, i);
186
+ }
187
+ return JS_ATOM_END + i;
188
+ }
189
+ atom(atom) { this.out.leb(this.atom_to_idx(atom)); }
190
+ value(v) {
191
+ const out = this.out;
192
+ switch (typeof v) {
193
+ case 'undefined':
194
+ out.u8(2 /* BCTag.UNDEFINED */);
195
+ return;
196
+ case 'boolean':
197
+ out.u8(v ? 4 /* BCTag.TRUE */ : 3 /* BCTag.FALSE */);
198
+ return;
199
+ case 'number':
200
+ if ((v | 0) === v && !(v === 0 && 1 / v < 0)) {
201
+ out.u8(5 /* BCTag.INT32 */);
202
+ out.sleb(v);
203
+ }
204
+ else {
205
+ out.u8(6 /* BCTag.FLOAT64 */);
206
+ out.f64v(v);
207
+ }
208
+ return;
209
+ case 'string':
210
+ out.u8(7 /* BCTag.STRING */);
211
+ out.leb(this.string_ref(v));
212
+ return;
213
+ case 'bigint':
214
+ out.u8(8 /* BCTag.BIG_INT */);
215
+ out.leb(this.string_ref(v.toString()));
216
+ return;
217
+ case 'object':
218
+ if (v === null) {
219
+ out.u8(1 /* BCTag.NULL */);
220
+ return;
221
+ }
222
+ if (v instanceof JSFunctionBytecode) {
223
+ this.function(v);
224
+ return;
225
+ }
226
+ if (Array.isArray(v) && Object.isFrozen(v) && Object.prototype.hasOwnProperty.call(v, 'raw')) {
227
+ this.template(v);
228
+ return;
229
+ }
230
+ break;
231
+ }
232
+ throw new BCWriteError('unsupported constant in the function tree: ' + describe(v));
233
+ }
234
+ /* a template object (js_parse_template): frozen array of cooked strings with a frozen
235
+ 'raw' array of raw strings */
236
+ template(arr) {
237
+ const out = this.out;
238
+ const raw = arr.raw;
239
+ if (!Array.isArray(raw) || raw.length !== arr.length)
240
+ throw new BCWriteError('malformed template object');
241
+ out.u8(10 /* BCTag.TEMPLATE_OBJECT */);
242
+ out.leb(arr.length);
243
+ for (let i = 0; i < arr.length; i++) {
244
+ const c = arr[i], r = raw[i];
245
+ if ((c !== undefined && typeof c !== 'string') || typeof r !== 'string')
246
+ throw new BCWriteError('malformed template object');
247
+ out.leb(c === undefined ? 0 : this.string_ref(c) + 1);
248
+ out.leb(this.string_ref(r));
249
+ }
250
+ }
251
+ function(b) {
252
+ const out = this.out;
253
+ const keep_source = (this.flags & JS_WRITE_OBJ_SOURCE) !== 0 && b.has_debug && b.debug.source !== null;
254
+ let flags = 0;
255
+ if (b.has_prototype)
256
+ flags |= F_HAS_PROTOTYPE;
257
+ if (b.has_simple_parameter_list)
258
+ flags |= F_SIMPLE_PARAMS;
259
+ if (b.is_derived_class_constructor)
260
+ flags |= F_DERIVED_CTOR;
261
+ if (b.need_home_object)
262
+ flags |= F_HOME_OBJECT;
263
+ if (b.new_target_allowed)
264
+ flags |= F_NEW_TARGET;
265
+ if (b.super_call_allowed)
266
+ flags |= F_SUPER_CALL;
267
+ if (b.super_allowed)
268
+ flags |= F_SUPER;
269
+ if (b.arguments_allowed)
270
+ flags |= F_ARGUMENTS;
271
+ if (b.has_debug)
272
+ flags |= F_HAS_DEBUG;
273
+ if (b.is_direct_or_indirect_eval)
274
+ flags |= F_EVAL;
275
+ if (keep_source)
276
+ flags |= F_HAS_SOURCE;
277
+ if (b.vardefs.length !== b.arg_count + b.var_count)
278
+ throw new BCWriteError('inconsistent variable count');
279
+ out.u8(9 /* BCTag.FUNCTION_BYTECODE */);
280
+ out.leb(flags);
281
+ out.u8(b.js_mode);
282
+ out.u8(b.func_kind);
283
+ this.atom(b.func_name);
284
+ out.leb(b.arg_count);
285
+ out.leb(b.var_count);
286
+ out.leb(b.defined_arg_count);
287
+ out.leb(b.stack_size);
288
+ out.leb(b.closure_var.length);
289
+ out.leb(b.cpool.length);
290
+ out.leb(b.byte_code_len);
291
+ for (const vd of b.vardefs) {
292
+ this.atom(vd.var_name);
293
+ out.leb(vd.scope_level);
294
+ out.sleb(vd.scope_next);
295
+ out.u8((vd.is_const ? V_CONST : 0) | (vd.is_lexical ? V_LEXICAL : 0) | (vd.is_captured ? V_CAPTURED : 0) |
296
+ (vd.is_static_private ? V_STATIC_PRIVATE : 0));
297
+ out.u8(vd.var_kind);
298
+ out.sleb(vd.func_pool_idx);
299
+ }
300
+ for (const cv of b.closure_var) {
301
+ this.atom(cv.var_name);
302
+ out.leb(cv.var_idx);
303
+ out.u8((cv.is_const ? V_CONST : 0) | (cv.is_lexical ? V_LEXICAL : 0) | (cv.is_local ? V_LOCAL : 0) |
304
+ (cv.is_arg ? V_ARG : 0));
305
+ out.u8(cv.var_kind);
306
+ }
307
+ out.bytes(this.byte_code(b));
308
+ if (b.has_debug) {
309
+ this.atom(b.debug.filename);
310
+ const pc2line = b.debug.pc2line;
311
+ if (pc2line === null)
312
+ out.leb(0);
313
+ else {
314
+ out.leb(pc2line.length);
315
+ out.bytes(pc2line);
316
+ }
317
+ if (keep_source)
318
+ out.leb(this.string_ref(b.debug.source));
319
+ }
320
+ for (const v of b.cpool)
321
+ this.value(v);
322
+ }
323
+ /* the byte code with its atom operands renumbered (JS_WriteFunctionBytecode) */
324
+ byte_code(b) {
325
+ const len = b.byte_code_len;
326
+ const bc = b.byte_code_buf.slice(0, len);
327
+ let pos = 0;
328
+ while (pos < len) {
329
+ const op = bc[pos], size = OP_SIZE[op];
330
+ if (size === 0)
331
+ throw new BCWriteError(`invalid opcode ${op} at pc ${pos}`);
332
+ if (OP_KIND[op] === OPK_ATOM && pos + 5 <= len) {
333
+ const atom = (bc[pos + 1] | (bc[pos + 2] << 8) | (bc[pos + 3] << 16) | (bc[pos + 4] << 24)) >>> 0;
334
+ const v = this.atom_to_idx(atom);
335
+ bc[pos + 1] = v;
336
+ bc[pos + 2] = v >>> 8;
337
+ bc[pos + 3] = v >>> 16;
338
+ bc[pos + 4] = v >>> 24;
339
+ }
340
+ pos += size;
341
+ }
342
+ if (pos !== len)
343
+ throw new BCWriteError('truncated instruction at the end of the byte code');
344
+ return bc;
345
+ }
346
+ finish(body) {
347
+ const out = new ByteBuf();
348
+ for (const c of BC_MAGIC)
349
+ out.u8(c);
350
+ out.u8(BC_FORMAT);
351
+ out.leb(JSEPTION_VERSION.length);
352
+ for (let i = 0; i < JSEPTION_VERSION.length; i++)
353
+ out.u8(JSEPTION_VERSION.charCodeAt(i));
354
+ out.leb(this.flags & JS_WRITE_OBJ_SOURCE ? BC_FLAG_SOURCE : 0);
355
+ /* string table */
356
+ const strings = this.strings;
357
+ out.leb(strings.length);
358
+ let narrow_len = 0, wide_len = 0;
359
+ const wide = [];
360
+ for (const s of strings) {
361
+ let w = false;
362
+ for (let i = 0; i < s.length; i++)
363
+ if (s.charCodeAt(i) > 0xff) {
364
+ w = true;
365
+ break;
366
+ }
367
+ wide.push(w);
368
+ out.leb(s.length * 2 + (w ? 1 : 0));
369
+ if (w)
370
+ wide_len += s.length;
371
+ else
372
+ narrow_len += s.length;
373
+ }
374
+ out.leb(narrow_len);
375
+ const narrow = new Uint8Array(narrow_len);
376
+ let p = 0;
377
+ for (let k = 0; k < strings.length; k++) {
378
+ if (wide[k])
379
+ continue;
380
+ const s = strings[k];
381
+ for (let i = 0; i < s.length; i++)
382
+ narrow[p++] = s.charCodeAt(i);
383
+ }
384
+ out.bytes(narrow);
385
+ out.leb(wide_len * 2);
386
+ const wbuf = new Uint8Array(wide_len * 2);
387
+ p = 0;
388
+ for (let k = 0; k < strings.length; k++) {
389
+ if (!wide[k])
390
+ continue;
391
+ const s = strings[k];
392
+ for (let i = 0; i < s.length; i++) {
393
+ const c = s.charCodeAt(i);
394
+ wbuf[p++] = c;
395
+ wbuf[p++] = c >>> 8;
396
+ }
397
+ }
398
+ out.bytes(wbuf);
399
+ /* atom table */
400
+ out.leb(this.atoms.length);
401
+ for (const i of this.atoms)
402
+ out.leb(i);
403
+ out.bytes(body.buf.subarray(0, body.len));
404
+ const [a, b] = checksum(out.buf, out.len);
405
+ for (const v of [a, b]) {
406
+ out.u8(v & 0xff);
407
+ out.u8((v >>> 8) & 0xff);
408
+ out.u8((v >>> 16) & 0xff);
409
+ out.u8(v >>> 24);
410
+ }
411
+ return out.result();
412
+ }
413
+ }
414
+ function describe(v) {
415
+ if (typeof v === 'function')
416
+ return 'function object';
417
+ if (Array.isArray(v))
418
+ return 'array';
419
+ if (typeof v === 'object' && v !== null)
420
+ return 'object';
421
+ return typeof v;
422
+ }
423
+ const CHECKSUM_SIZE = 8;
424
+ /* Fletcher-style sums of buf[0, end) taken as little-endian 32-bit words (the tail bytewise):
425
+ detects truncation and corrupted bytes, at a quarter of the cost of a bytewise checksum
426
+ (it is not a defence against deliberate tampering) */
427
+ function checksum(buf, end) {
428
+ const n = end >>> 2;
429
+ let a = 1, b = 0;
430
+ if (LITTLE_ENDIAN) {
431
+ if (buf.byteOffset & 3)
432
+ buf = buf.slice(0, end);
433
+ const w = new Int32Array(buf.buffer, buf.byteOffset, n);
434
+ for (let i = 0; i < n; i++) {
435
+ a = (a + w[i]) | 0;
436
+ b = (b + a) | 0;
437
+ }
438
+ }
439
+ else {
440
+ for (let i = 0; i < n; i++) {
441
+ const p = i * 4;
442
+ a = (a + (buf[p] | (buf[p + 1] << 8) | (buf[p + 2] << 16) | (buf[p + 3] << 24))) | 0;
443
+ b = (b + a) | 0;
444
+ }
445
+ }
446
+ for (let i = n * 4; i < end; i++) {
447
+ a = (a + buf[i]) | 0;
448
+ b = (b + a) | 0;
449
+ }
450
+ return [a >>> 0, b >>> 0];
451
+ }
452
+ /* Serialize the function returned by JS_Eval(..., JS_EVAL_FLAG_COMPILE_ONLY) (or any
453
+ bytecode function that does not close over variables). Returns null with a pending
454
+ exception on failure. */
455
+ export function JS_WriteObject(ctx, obj, flags = 0) {
456
+ const fd = JS_GetFunctionData(obj);
457
+ if (fd === null) {
458
+ JS_ThrowTypeError(ctx, 'JS_WriteObject: not a bytecode function (expected the result of JS_EVAL_FLAG_COMPILE_ONLY)');
459
+ return null;
460
+ }
461
+ const b = fd.function_bytecode;
462
+ if (b.closure_var.length !== 0) {
463
+ JS_ThrowTypeError(ctx, 'JS_WriteObject: the function closes over variables of an enclosing scope');
464
+ return null;
465
+ }
466
+ const w = new BCWriter(ctx, flags);
467
+ try {
468
+ w.function(b);
469
+ const body = w.out;
470
+ return w.finish(body);
471
+ }
472
+ catch (e) {
473
+ if (e instanceof BCWriteError) {
474
+ JS_ThrowTypeError(ctx, 'JS_WriteObject: ' + e.message);
475
+ return null;
476
+ }
477
+ throw e;
478
+ }
479
+ }
480
+ /* ---------------------------------------------------------------------
481
+ Reader
482
+ --------------------------------------------------------------------- */
483
+ class BCReadError extends Error {
484
+ }
485
+ const MAX_DEPTH = 2000;
486
+ /* parser limits (define_var / add_arg: at most 65534 each; compute_stack_size: JS_STACK_SIZE_MAX) */
487
+ const MAX_LOCALS = 65535;
488
+ const MAX_STACK_SIZE = 65534;
489
+ class BCReader {
490
+ ctx;
491
+ pos = 0;
492
+ end;
493
+ strings = [];
494
+ atoms = [];
495
+ keep_source = false;
496
+ depth = 0;
497
+ f64 = new Float64Array(1);
498
+ f64b = new Uint8Array(this.f64.buffer);
499
+ buf;
500
+ /* the reader works on a private copy of the input: the byte code is patched in place and
501
+ the functions keep views of it (one copy instead of two per function) */
502
+ constructor(ctx, input) {
503
+ this.ctx = ctx;
504
+ this.buf = input.slice();
505
+ this.end = this.buf.length;
506
+ }
507
+ fail(msg) { throw new BCReadError(msg); }
508
+ truncated() { throw new BCReadError('read after the end of the buffer'); }
509
+ u8() {
510
+ if (this.pos >= this.end)
511
+ this.truncated();
512
+ return this.buf[this.pos++];
513
+ }
514
+ leb() {
515
+ const buf = this.buf;
516
+ let pos = this.pos;
517
+ if (pos >= this.end)
518
+ this.truncated();
519
+ let a = buf[pos++];
520
+ if (a < 0x80) {
521
+ this.pos = pos;
522
+ return a;
523
+ }
524
+ let v = a & 0x7f, mul = 0x80;
525
+ for (let i = 1;; i++) {
526
+ if (pos >= this.end)
527
+ this.truncated();
528
+ if (i >= 5)
529
+ this.fail('invalid LEB128 number');
530
+ a = buf[pos++];
531
+ v += (a & 0x7f) * mul;
532
+ if (a < 0x80)
533
+ break;
534
+ mul *= 0x80;
535
+ }
536
+ if (v > 0xffffffff)
537
+ this.fail('invalid LEB128 number');
538
+ this.pos = pos;
539
+ return v;
540
+ }
541
+ sleb() {
542
+ const v = this.leb();
543
+ return (v % 2 === 1) ? -((v + 1) / 2) : v / 2;
544
+ }
545
+ f64v() {
546
+ if (this.pos + 8 > this.end)
547
+ this.truncated();
548
+ const b = this.f64b, buf = this.buf;
549
+ if (LITTLE_ENDIAN)
550
+ for (let i = 0; i < 8; i++)
551
+ b[i] = buf[this.pos++];
552
+ else
553
+ for (let i = 7; i >= 0; i--)
554
+ b[i] = buf[this.pos++];
555
+ return this.f64[0];
556
+ }
557
+ /* a count whose items each take at least one byte */
558
+ count() {
559
+ const n = this.leb();
560
+ if (n > this.end - this.pos)
561
+ this.truncated();
562
+ return n;
563
+ }
564
+ bytes(n) {
565
+ if (n > this.end - this.pos)
566
+ this.truncated();
567
+ const r = this.buf.subarray(this.pos, this.pos + n);
568
+ this.pos += n;
569
+ return r;
570
+ }
571
+ string() {
572
+ const i = this.leb();
573
+ if (i >= this.strings.length)
574
+ this.fail(`invalid string index ${i}`);
575
+ return this.strings[i];
576
+ }
577
+ /* bc_idx_to_atom */
578
+ idx_to_atom(v) {
579
+ if (v < JS_ATOM_END || v >= JS_ATOM_TAG_INT)
580
+ return v;
581
+ const i = v - JS_ATOM_END;
582
+ if (i >= this.atoms.length)
583
+ this.fail(`invalid atom index ${v}`);
584
+ return this.atoms[i];
585
+ }
586
+ atom() { return this.idx_to_atom(this.leb()); }
587
+ header() {
588
+ const buf = this.buf;
589
+ if (buf.length < BC_MAGIC.length + 2 + CHECKSUM_SIZE)
590
+ this.truncated();
591
+ for (let i = 0; i < BC_MAGIC.length; i++)
592
+ if (buf[i] !== BC_MAGIC[i])
593
+ this.fail('not jseption bytecode (bad magic number)');
594
+ this.pos = BC_MAGIC.length;
595
+ const format = this.u8();
596
+ const vlen = this.leb();
597
+ if (vlen > 64)
598
+ this.fail('not jseption bytecode (bad header)');
599
+ if (vlen > this.end - this.pos)
600
+ this.truncated();
601
+ let version = '';
602
+ for (let i = 0; i < vlen; i++)
603
+ version += String.fromCharCode(buf[this.pos++]);
604
+ if (format !== BC_FORMAT || version !== JSEPTION_VERSION)
605
+ this.fail(`bytecode version mismatch: written by jseption ${version} (format ${format}), ` +
606
+ `this is jseption ${JSEPTION_VERSION} (format ${BC_FORMAT})`);
607
+ /* everything after the version is covered by the checksum */
608
+ if (buf.length - CHECKSUM_SIZE < this.pos)
609
+ this.truncated();
610
+ this.end = buf.length - CHECKSUM_SIZE;
611
+ const [a, b] = checksum(buf, this.end);
612
+ const u32 = (p) => (buf[p] | (buf[p + 1] << 8) | (buf[p + 2] << 16) | (buf[p + 3] << 24)) >>> 0;
613
+ if (u32(this.end) !== a || u32(this.end + 4) !== b)
614
+ this.fail('checksum mismatch (truncated or corrupted bytecode)');
615
+ const flags = this.leb();
616
+ if (flags & ~BC_FLAG_SOURCE)
617
+ this.fail('unknown flags');
618
+ this.keep_source = (flags & BC_FLAG_SOURCE) !== 0;
619
+ }
620
+ string_table() {
621
+ const n = this.count();
622
+ const lens = new Array(n);
623
+ let narrow_len = 0, wide_len = 0;
624
+ for (let i = 0; i < n; i++) {
625
+ const v = this.leb();
626
+ lens[i] = v;
627
+ if (v & 1)
628
+ wide_len += (v - 1) / 2;
629
+ else
630
+ narrow_len += v / 2;
631
+ }
632
+ if (this.leb() !== narrow_len)
633
+ this.fail('inconsistent string table');
634
+ if (narrow_len > this.end - this.pos)
635
+ this.truncated();
636
+ const narrow = latin1_decode(this.buf, this.pos, this.pos + narrow_len);
637
+ this.pos += narrow_len;
638
+ if (this.leb() !== wide_len * 2)
639
+ this.fail('inconsistent string table');
640
+ if (wide_len * 2 > this.end - this.pos)
641
+ this.truncated();
642
+ const wide = utf16_decode(this.buf, this.pos, wide_len);
643
+ this.pos += wide_len * 2;
644
+ const strings = this.strings = new Array(n);
645
+ let np = 0, wp = 0;
646
+ for (let i = 0; i < n; i++) {
647
+ const v = lens[i];
648
+ if (v & 1) {
649
+ const l = (v - 1) / 2;
650
+ strings[i] = wide.slice(wp, wp + l);
651
+ wp += l;
652
+ }
653
+ else {
654
+ const l = v / 2;
655
+ strings[i] = narrow.slice(np, np + l);
656
+ np += l;
657
+ }
658
+ }
659
+ }
660
+ atom_table() {
661
+ const n = this.count();
662
+ const atoms = this.atoms = new Array(n);
663
+ const table = this.ctx.rt.atoms;
664
+ for (let i = 0; i < n; i++)
665
+ atoms[i] = table.newAtomStr(this.string());
666
+ }
667
+ value() {
668
+ const tag = this.u8();
669
+ switch (tag) {
670
+ case 1 /* BCTag.NULL */: return null;
671
+ case 2 /* BCTag.UNDEFINED */: return undefined;
672
+ case 3 /* BCTag.FALSE */: return false;
673
+ case 4 /* BCTag.TRUE */: return true;
674
+ case 5 /* BCTag.INT32 */: {
675
+ const v = this.sleb();
676
+ if ((v | 0) !== v)
677
+ this.fail('invalid int32');
678
+ return v;
679
+ }
680
+ case 6 /* BCTag.FLOAT64 */: return this.f64v();
681
+ case 7 /* BCTag.STRING */: return this.string();
682
+ case 8 /* BCTag.BIG_INT */: {
683
+ const s = this.string();
684
+ if (!/^-?[0-9]+$/.test(s))
685
+ this.fail('invalid BigInt');
686
+ return BigInt(s);
687
+ }
688
+ case 9 /* BCTag.FUNCTION_BYTECODE */: return this.function();
689
+ case 10 /* BCTag.TEMPLATE_OBJECT */: return this.template();
690
+ }
691
+ return this.fail(`invalid tag ${tag} at offset ${this.pos - 1}`);
692
+ }
693
+ template() {
694
+ const ctx = this.ctx;
695
+ const n = this.count();
696
+ const arr = JS_NewArray(ctx), raw = JS_NewArray(ctx);
697
+ if (JS_IsException(arr) || JS_IsException(raw))
698
+ this.fail('out of memory');
699
+ for (let i = 0; i < n; i++) {
700
+ const c = this.leb();
701
+ let cooked;
702
+ if (c !== 0) {
703
+ if (c > this.strings.length)
704
+ this.fail(`invalid string index ${c - 1}`);
705
+ cooked = this.strings[c - 1];
706
+ }
707
+ JS_DefinePropertyValueUint32(ctx, raw, i, this.string(), JS_PROP_ENUMERABLE);
708
+ JS_DefinePropertyValueUint32(ctx, arr, i, cooked, JS_PROP_ENUMERABLE);
709
+ }
710
+ JS_DefinePropertyValue(ctx, arr, JS_ATOM_raw, raw, 0);
711
+ Object.freeze(raw);
712
+ Object.freeze(arr);
713
+ return arr;
714
+ }
715
+ function() {
716
+ if (++this.depth > MAX_DEPTH)
717
+ this.fail('functions nested too deeply');
718
+ const b = new JSFunctionBytecode();
719
+ const flags = this.leb();
720
+ if (flags >= F_HAS_SOURCE << 1)
721
+ this.fail('invalid function flags');
722
+ b.has_prototype = (flags & F_HAS_PROTOTYPE) !== 0;
723
+ b.has_simple_parameter_list = (flags & F_SIMPLE_PARAMS) !== 0;
724
+ b.is_derived_class_constructor = (flags & F_DERIVED_CTOR) !== 0;
725
+ b.need_home_object = (flags & F_HOME_OBJECT) !== 0;
726
+ b.new_target_allowed = (flags & F_NEW_TARGET) !== 0;
727
+ b.super_call_allowed = (flags & F_SUPER_CALL) !== 0;
728
+ b.super_allowed = (flags & F_SUPER) !== 0;
729
+ b.arguments_allowed = (flags & F_ARGUMENTS) !== 0;
730
+ b.has_debug = (flags & F_HAS_DEBUG) !== 0;
731
+ b.is_direct_or_indirect_eval = (flags & F_EVAL) !== 0;
732
+ b.js_mode = this.u8();
733
+ const kind = this.u8();
734
+ if (kind > 3 /* JSFunctionKind.ASYNC_GENERATOR */)
735
+ this.fail('invalid function kind');
736
+ b.func_kind = kind;
737
+ b.func_name = this.atom();
738
+ b.arg_count = this.count();
739
+ b.var_count = this.count();
740
+ b.defined_arg_count = this.leb();
741
+ b.stack_size = this.leb();
742
+ /* the parser's limits: the interpreter sizes each frame from these, so an out-of-range
743
+ value would make it allocate a huge frame instead of failing here */
744
+ if (b.arg_count >= MAX_LOCALS || b.var_count >= MAX_LOCALS)
745
+ this.fail('too many variables');
746
+ if (b.defined_arg_count > b.arg_count)
747
+ this.fail('invalid defined argument count');
748
+ if (b.stack_size > MAX_STACK_SIZE)
749
+ this.fail(`invalid stack size ${b.stack_size}`);
750
+ const closure_count = this.count();
751
+ const cpool_count = this.count();
752
+ const bc_len = this.count();
753
+ const nvars = b.arg_count + b.var_count;
754
+ const vardefs = b.vardefs = new Array(nvars);
755
+ for (let i = 0; i < nvars; i++) {
756
+ const vd = new JSVarDef(this.atom());
757
+ vd.scope_level = this.leb();
758
+ vd.scope_next = this.sleb();
759
+ const f = this.u8();
760
+ vd.is_const = (f & V_CONST) !== 0;
761
+ vd.is_lexical = (f & V_LEXICAL) !== 0;
762
+ vd.is_captured = (f & V_CAPTURED) !== 0;
763
+ vd.is_static_private = (f & V_STATIC_PRIVATE) !== 0;
764
+ const k = this.u8();
765
+ if (k > VAR_KIND_MAX)
766
+ this.fail('invalid variable kind');
767
+ vd.var_kind = k;
768
+ vd.func_pool_idx = this.sleb();
769
+ vardefs[i] = vd;
770
+ }
771
+ const closure_var = b.closure_var = new Array(closure_count);
772
+ for (let i = 0; i < closure_count; i++) {
773
+ const cv = new JSClosureVar();
774
+ cv.var_name = this.atom();
775
+ cv.var_idx = this.leb();
776
+ const f = this.u8();
777
+ cv.is_const = (f & V_CONST) !== 0;
778
+ cv.is_lexical = (f & V_LEXICAL) !== 0;
779
+ cv.is_local = (f & V_LOCAL) !== 0;
780
+ cv.is_arg = (f & V_ARG) !== 0;
781
+ const k = this.u8();
782
+ if (k > VAR_KIND_MAX)
783
+ this.fail('invalid variable kind');
784
+ cv.var_kind = k;
785
+ closure_var[i] = cv;
786
+ }
787
+ const bc = this.bytes(bc_len);
788
+ b.byte_code_buf = bc;
789
+ b.byte_code_len = bc_len;
790
+ if (b.has_debug) {
791
+ b.debug.filename = this.atom();
792
+ const n = this.leb();
793
+ b.debug.pc2line = this.bytes(n);
794
+ if (flags & F_HAS_SOURCE) {
795
+ if (!this.keep_source)
796
+ this.fail('invalid function flags');
797
+ const src = this.string();
798
+ b.debug.source = src;
799
+ b.debug.source_len = src.length;
800
+ }
801
+ }
802
+ else if (flags & F_HAS_SOURCE) {
803
+ this.fail('invalid function flags');
804
+ }
805
+ const cpool = b.cpool = new Array(cpool_count);
806
+ for (let i = 0; i < cpool_count; i++)
807
+ cpool[i] = this.value();
808
+ this.fixup_byte_code(b);
809
+ b.realm = this.ctx;
810
+ this.depth--;
811
+ return b;
812
+ }
813
+ /* patch the atom operands and check the instruction boundaries and the constant pool
814
+ indices (JS_ReadFunctionBytecode) */
815
+ fixup_byte_code(b) {
816
+ const bc = b.byte_code_buf, len = b.byte_code_len, cpool = b.cpool;
817
+ let pos = 0;
818
+ const natoms = this.atoms.length, atoms = this.atoms;
819
+ while (pos < len) {
820
+ const op = bc[pos], size = OP_SIZE[op];
821
+ if (size === 0)
822
+ this.fail(`invalid opcode ${op} at pc ${pos}`);
823
+ if (pos + size > len)
824
+ this.fail(`truncated instruction at pc ${pos}`);
825
+ const kind = OP_KIND[op];
826
+ if (kind !== 0) {
827
+ if (kind === OPK_ATOM) {
828
+ const v = (bc[pos + 1] | (bc[pos + 2] << 8) | (bc[pos + 3] << 16) | (bc[pos + 4] << 24)) >>> 0;
829
+ if (v >= JS_ATOM_END && v < JS_ATOM_TAG_INT) {
830
+ const i = v - JS_ATOM_END;
831
+ if (i >= natoms)
832
+ this.fail(`invalid atom index ${v} at pc ${pos}`);
833
+ const atom = atoms[i];
834
+ bc[pos + 1] = atom;
835
+ bc[pos + 2] = atom >>> 8;
836
+ bc[pos + 3] = atom >>> 16;
837
+ bc[pos + 4] = atom >>> 24;
838
+ }
839
+ }
840
+ else {
841
+ const idx = (kind === OPK_CONST8 || kind === OPK_FCLOSURE8) ? bc[pos + 1]
842
+ : (bc[pos + 1] | (bc[pos + 2] << 8) | (bc[pos + 3] << 16) | (bc[pos + 4] << 24)) >>> 0;
843
+ if (idx >= cpool.length)
844
+ this.fail(`invalid constant pool index ${idx} at pc ${pos}`);
845
+ if (kind >= OPK_FCLOSURE && !(cpool[idx] instanceof JSFunctionBytecode))
846
+ this.fail(`closure of a constant that is not a function at pc ${pos}`);
847
+ }
848
+ }
849
+ pos += size;
850
+ }
851
+ }
852
+ }
853
+ /* buf[start, end) as a Latin-1 string */
854
+ function latin1_decode(buf, start, end) {
855
+ const CHUNK = 8192;
856
+ if (end - start <= CHUNK)
857
+ return String.fromCharCode.apply(null, buf.subarray(start, end));
858
+ const parts = [];
859
+ for (let i = start; i < end; i += CHUNK)
860
+ parts.push(String.fromCharCode.apply(null, buf.subarray(i, Math.min(end, i + CHUNK))));
861
+ return parts.join('');
862
+ }
863
+ /* n UTF-16LE code units at buf[start] as a string (lone surrogates preserved) */
864
+ function utf16_decode(buf, start, n) {
865
+ if (n === 0)
866
+ return '';
867
+ let units;
868
+ if (LITTLE_ENDIAN) {
869
+ units = new Uint16Array(buf.slice(start, start + 2 * n).buffer);
870
+ }
871
+ else {
872
+ units = new Uint16Array(n);
873
+ for (let i = 0; i < n; i++)
874
+ units[i] = buf[start + 2 * i] | (buf[start + 2 * i + 1] << 8);
875
+ }
876
+ const CHUNK = 8192;
877
+ const parts = [];
878
+ for (let i = 0; i < n; i += CHUNK)
879
+ parts.push(String.fromCharCode.apply(null, units.subarray(i, Math.min(n, i + CHUNK))));
880
+ return parts.join('');
881
+ }
882
+ /* Read bytes produced by JS_WriteObject into this context. Returns a function object to
883
+ run with JS_EvalFunction, or JS_EXCEPTION with a SyntaxError pending when the input is
884
+ not valid bytecode of this jseption version. */
885
+ export function JS_ReadObject(ctx, buf) {
886
+ if (!(buf instanceof Uint8Array))
887
+ return JS_ThrowTypeError(ctx, 'JS_ReadObject: expected a Uint8Array');
888
+ const r = new BCReader(ctx, buf);
889
+ let b;
890
+ try {
891
+ r.header();
892
+ r.string_table();
893
+ r.atom_table();
894
+ if (r.u8() !== 9 /* BCTag.FUNCTION_BYTECODE */)
895
+ r.fail('the root value is not a function');
896
+ b = r.function();
897
+ if (r.pos !== r.end)
898
+ r.fail('trailing bytes after the root value');
899
+ }
900
+ catch (e) {
901
+ if (e instanceof BCReadError)
902
+ return JS_ThrowSyntaxError(ctx, 'JS_ReadObject: ' + e.message);
903
+ if (e instanceof RangeError)
904
+ return JS_ThrowSyntaxError(ctx, 'JS_ReadObject: ' + e.message);
905
+ throw e;
906
+ }
907
+ if (b.closure_var.length !== 0)
908
+ return JS_ThrowSyntaxError(ctx, 'JS_ReadObject: the root function has closure variables');
909
+ return hooks.js_closure(ctx, b, null, null);
910
+ }
911
+ //# sourceMappingURL=bytecode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytecode.js","sourceRoot":"","sources":["../src/bytecode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EAAU,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC1H,OAAO,EAAsB,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,WAAW,EAClG,sBAAsB,EAAE,4BAA4B,EAAE,cAAc,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACxH,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAkB,QAAQ,EAAa,MAAM,aAAa,CAAC;AACpG,OAAO,EAAa,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,oFAAoF;AACpF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAI,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,YAAY;AAC9D,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAE3B,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,CAAC;AAe9B,8BAA8B;AAC9B,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,CAAC;AAC/B,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,CAAC;AAC/B,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,CAAC;AAC9B,MAAM,aAAa,GAAG,CAAC,IAAI,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C,IAAI,CAAC,qCAAqC,CAAC,CAAC;IACrE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,WAAW;YAAE,OAAO,mBAAmB,CAAC,GAAG,EAAE,iBAAiB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;QAC7F,IAAI,CAAC,YAAY,UAAU;YAAE,OAAO,mBAAmB,CAAC,GAAG,EAAE,iBAAiB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;QAC5F,MAAM,CAAC,CAAC;IACV,CAAC;IACD,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,mBAAmB,CAAC,GAAG,EAAE,wDAAwD,CAAC,CAAC;IAC1H,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["/*\n * Bytecode serialization: JS_WriteObject / JS_ReadObject.\n *\n * Writes the function tree produced by JS_EVAL_FLAG_COMPILE_ONLY to bytes and\n * reads it back into any runtime of the same jseption version, so that a\n * script can be compiled ahead of time and loaded without parsing. The design\n * follows quickjs.c (bc_write_* / bc_read_*): atoms are runtime specific, so\n * the writer emits an atom table and renumbers every atom (in the function\n * fields and in the atom operands of the byte code, found by walking the\n * opcodes by their format), and the reader interns the strings in its own\n * runtime and patches the operands back.\n *\n * Only load bytecode you produced yourself: like in QuickJS, the reader checks\n * the format (header, bounds, tags, indices, opcode boundaries, checksum), not\n * the semantics of the byte code, and hand-made byte code can reach states the\n * parser never emits.\n *\n * Format (all integers are unsigned LEB128 unless stated otherwise):\n *\n * magic 4 bytes \"JSBC\"\n * format u8 (BC_FORMAT)\n * version length + ASCII bytes: the jseption package version\n * flags BC_FLAG_*\n * strings count, then per string (length << 1 | wide), then the\n * byte length and bytes of the Latin-1 blob, then the\n * byte length and bytes of the UTF-16LE blob\n * atoms count, then the string index of each atom\n * root a tagged value (BC_TAG_FUNCTION_BYTECODE)\n * checksum 8 bytes: two 32-bit little-endian sums (Fletcher style, over\n * little-endian 32-bit words) of everything before them\n *\n * Atom references (function fields and byte code operands) use the encoding of\n * bc_atom_to_idx: predefined atoms (< JS_ATOM_END) and tagged integer atoms are\n * kept, other atoms become JS_ATOM_END + their index in the atom table.\n */\nimport { JSAtom, JS_ATOM_END, JS_ATOM_raw, JS_ATOM_TAG_INT, JS_ATOM_TYPE_STRING, __JS_AtomIsTaggedInt } from './atoms.ts';\nimport { JSContext, JSValue, JS_GetFunctionData, JS_ThrowSyntaxError, JS_ThrowTypeError, JS_NewArray,\n JS_DefinePropertyValue, JS_DefinePropertyValueUint32, JS_IsException, JS_PROP_ENUMERABLE, hooks } from './quickjs.ts';\nimport { JSClosureVar, JSFunctionBytecode, JSFunctionKind, JSVarDef, JSVarKind } from './values.ts';\nimport { OP, OpFmt, short_opcode_info } from './opcodes.ts';\nimport { JSEPTION_VERSION } from './version.ts';\n\n/* keep each function's source text (Function.prototype.toString); off by default */\nexport const JS_WRITE_OBJ_SOURCE = 1 << 0;\n\nexport const BC_MAGIC = [0x4a, 0x53, 0x42, 0x43]; /* \"JSBC\" */\nexport const BC_FORMAT = 1;\n\nconst BC_FLAG_SOURCE = 1 << 0;\n\nconst enum BCTag {\n NULL = 1,\n UNDEFINED,\n FALSE,\n TRUE,\n INT32,\n FLOAT64,\n STRING,\n BIG_INT,\n FUNCTION_BYTECODE,\n TEMPLATE_OBJECT,\n}\n\n/* JSFunctionBytecode flags */\nconst F_HAS_PROTOTYPE = 1 << 0;\nconst F_SIMPLE_PARAMS = 1 << 1;\nconst F_DERIVED_CTOR = 1 << 2;\nconst F_HOME_OBJECT = 1 << 3;\nconst F_NEW_TARGET = 1 << 4;\nconst F_SUPER_CALL = 1 << 5;\nconst F_SUPER = 1 << 6;\nconst F_ARGUMENTS = 1 << 7;\nconst F_HAS_DEBUG = 1 << 8;\nconst F_EVAL = 1 << 9;\nconst F_HAS_SOURCE = 1 << 10;\n\n/* JSVarDef / JSClosureVar flags */\nconst V_CONST = 1 << 0;\nconst V_LEXICAL = 1 << 1;\nconst V_CAPTURED = 1 << 2;\nconst V_STATIC_PRIVATE = 1 << 3;\nconst V_LOCAL = 1 << 4;\nconst V_ARG = 1 << 5;\n\nconst VAR_KIND_MAX = JSVarKind.PRIVATE_GETTER_SETTER;\n\n/* the size of each opcode of the final byte code (0: not an opcode) and what its operand\n holds, indexed by the opcode byte, so that walking the byte code costs a few array reads\n per instruction */\nconst OPK_ATOM = 1, OPK_CONST = 2, OPK_CONST8 = 3, OPK_FCLOSURE = 4, OPK_FCLOSURE8 = 5;\nconst OP_SIZE = new Uint8Array(256);\nconst OP_KIND = new Uint8Array(256);\nfor (let op = 0; op < 256; op++) {\n const info = short_opcode_info(op);\n if (info === undefined) continue;\n OP_SIZE[op] = info.size;\n switch (info.fmt) {\n case OpFmt.atom: case OpFmt.atom_u8: case OpFmt.atom_u16: case OpFmt.atom_label_u8: case OpFmt.atom_label_u16:\n OP_KIND[op] = OPK_ATOM; break;\n case OpFmt.const: OP_KIND[op] = OPK_CONST; break;\n case OpFmt.const8: OP_KIND[op] = OPK_CONST8; break;\n }\n}\nOP_KIND[OP.fclosure] = OPK_FCLOSURE;\nOP_KIND[OP.fclosure8] = OPK_FCLOSURE8;\n\n/* ---------------------------------------------------------------------\n Writer\n --------------------------------------------------------------------- */\n\nclass BCWriteError extends Error {}\n\nclass ByteBuf {\n buf = new Uint8Array(4096);\n len = 0;\n private f64 = new Float64Array(1);\n private f64b = new Uint8Array(this.f64.buffer);\n\n private grow(n: number): void {\n let size = this.buf.length * 2;\n while (size < this.len + n) size *= 2;\n const b = new Uint8Array(size);\n b.set(this.buf.subarray(0, this.len));\n this.buf = b;\n }\n u8(v: number): void {\n if (this.len >= this.buf.length) this.grow(1);\n this.buf[this.len++] = v;\n }\n leb(v: number): void {\n if (this.len + 5 > this.buf.length) this.grow(5);\n const buf = this.buf;\n while (v >= 0x80) {\n buf[this.len++] = (v % 0x80) | 0x80;\n v = Math.floor(v / 0x80);\n }\n buf[this.len++] = v;\n }\n sleb(v: number): void {\n this.leb(v < 0 ? -2 * v - 1 : 2 * v);\n }\n f64v(v: number): void {\n if (this.len + 8 > this.buf.length) this.grow(8);\n this.f64[0] = v;\n const b = this.f64b;\n /* little endian on the wire */\n if (LITTLE_ENDIAN) for (let i = 0; i < 8; i++) this.buf[this.len++] = b[i];\n else for (let i = 7; i >= 0; i--) this.buf[this.len++] = b[i];\n }\n bytes(src: Uint8Array): void {\n if (this.len + src.length > this.buf.length) this.grow(src.length);\n this.buf.set(src, this.len);\n this.len += src.length;\n }\n result(): Uint8Array { return this.buf.slice(0, this.len); }\n}\n\nconst LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;\n\nclass BCWriter {\n out = new ByteBuf();\n strings: string[] = [];\n string_idx = new Map<string, number>();\n atoms: number[] = []; /* string index of each atom table entry */\n atom_idx = new Map<JSAtom, number>();\n constructor(public ctx: JSContext, public flags: number) {}\n\n string_ref(s: string): number {\n let i = this.string_idx.get(s);\n if (i === undefined) {\n i = this.strings.length;\n this.strings.push(s);\n this.string_idx.set(s, i);\n }\n return i;\n }\n\n /* bc_atom_to_idx */\n atom_to_idx(atom: JSAtom): number {\n if (atom < JS_ATOM_END || __JS_AtomIsTaggedInt(atom)) return atom;\n let i = this.atom_idx.get(atom);\n if (i === undefined) {\n const atoms = this.ctx.rt.atoms;\n if (atoms.getType(atom) !== JS_ATOM_TYPE_STRING)\n throw new BCWriteError('cannot serialize a symbol atom: ' + atoms.toDisplayStr(atom));\n i = this.atoms.length;\n this.atoms.push(this.string_ref(atoms.toStr(atom)));\n this.atom_idx.set(atom, i);\n }\n return JS_ATOM_END + i;\n }\n\n atom(atom: JSAtom): void { this.out.leb(this.atom_to_idx(atom)); }\n\n value(v: JSValue | JSFunctionBytecode): void {\n const out = this.out;\n switch (typeof v) {\n case 'undefined': out.u8(BCTag.UNDEFINED); return;\n case 'boolean': out.u8(v ? BCTag.TRUE : BCTag.FALSE); return;\n case 'number':\n if ((v | 0) === v && !(v === 0 && 1 / v < 0)) { out.u8(BCTag.INT32); out.sleb(v); }\n else { out.u8(BCTag.FLOAT64); out.f64v(v); }\n return;\n case 'string': out.u8(BCTag.STRING); out.leb(this.string_ref(v)); return;\n case 'bigint': out.u8(BCTag.BIG_INT); out.leb(this.string_ref(v.toString())); return;\n case 'object':\n if (v === null) { out.u8(BCTag.NULL); return; }\n if (v instanceof JSFunctionBytecode) { this.function(v); return; }\n if (Array.isArray(v) && Object.isFrozen(v) && Object.prototype.hasOwnProperty.call(v, 'raw')) {\n this.template(v);\n return;\n }\n break;\n }\n throw new BCWriteError('unsupported constant in the function tree: ' + describe(v));\n }\n\n /* a template object (js_parse_template): frozen array of cooked strings with a frozen\n 'raw' array of raw strings */\n template(arr: unknown[]): void {\n const out = this.out;\n const raw = (arr as any).raw;\n if (!Array.isArray(raw) || raw.length !== arr.length) throw new BCWriteError('malformed template object');\n out.u8(BCTag.TEMPLATE_OBJECT);\n out.leb(arr.length);\n for (let i = 0; i < arr.length; i++) {\n const c = arr[i], r = raw[i];\n if ((c !== undefined && typeof c !== 'string') || typeof r !== 'string') throw new BCWriteError('malformed template object');\n out.leb(c === undefined ? 0 : this.string_ref(c) + 1);\n out.leb(this.string_ref(r));\n }\n }\n\n function(b: JSFunctionBytecode): void {\n const out = this.out;\n const keep_source = (this.flags & JS_WRITE_OBJ_SOURCE) !== 0 && b.has_debug && b.debug.source !== null;\n let flags = 0;\n if (b.has_prototype) flags |= F_HAS_PROTOTYPE;\n if (b.has_simple_parameter_list) flags |= F_SIMPLE_PARAMS;\n if (b.is_derived_class_constructor) flags |= F_DERIVED_CTOR;\n if (b.need_home_object) flags |= F_HOME_OBJECT;\n if (b.new_target_allowed) flags |= F_NEW_TARGET;\n if (b.super_call_allowed) flags |= F_SUPER_CALL;\n if (b.super_allowed) flags |= F_SUPER;\n if (b.arguments_allowed) flags |= F_ARGUMENTS;\n if (b.has_debug) flags |= F_HAS_DEBUG;\n if (b.is_direct_or_indirect_eval) flags |= F_EVAL;\n if (keep_source) flags |= F_HAS_SOURCE;\n if (b.vardefs.length !== b.arg_count + b.var_count) throw new BCWriteError('inconsistent variable count');\n out.u8(BCTag.FUNCTION_BYTECODE);\n out.leb(flags);\n out.u8(b.js_mode);\n out.u8(b.func_kind);\n this.atom(b.func_name);\n out.leb(b.arg_count);\n out.leb(b.var_count);\n out.leb(b.defined_arg_count);\n out.leb(b.stack_size);\n out.leb(b.closure_var.length);\n out.leb(b.cpool.length);\n out.leb(b.byte_code_len);\n for (const vd of b.vardefs) {\n this.atom(vd.var_name);\n out.leb(vd.scope_level);\n out.sleb(vd.scope_next);\n out.u8((vd.is_const ? V_CONST : 0) | (vd.is_lexical ? V_LEXICAL : 0) | (vd.is_captured ? V_CAPTURED : 0) |\n (vd.is_static_private ? V_STATIC_PRIVATE : 0));\n out.u8(vd.var_kind);\n out.sleb(vd.func_pool_idx);\n }\n for (const cv of b.closure_var) {\n this.atom(cv.var_name);\n out.leb(cv.var_idx);\n out.u8((cv.is_const ? V_CONST : 0) | (cv.is_lexical ? V_LEXICAL : 0) | (cv.is_local ? V_LOCAL : 0) |\n (cv.is_arg ? V_ARG : 0));\n out.u8(cv.var_kind);\n }\n out.bytes(this.byte_code(b));\n if (b.has_debug) {\n this.atom(b.debug.filename);\n const pc2line = b.debug.pc2line;\n if (pc2line === null) out.leb(0);\n else { out.leb(pc2line.length); out.bytes(pc2line); }\n if (keep_source) out.leb(this.string_ref(b.debug.source!));\n }\n for (const v of b.cpool) this.value(v);\n }\n\n /* the byte code with its atom operands renumbered (JS_WriteFunctionBytecode) */\n byte_code(b: JSFunctionBytecode): Uint8Array {\n const len = b.byte_code_len;\n const bc = b.byte_code_buf.slice(0, len);\n let pos = 0;\n while (pos < len) {\n const op = bc[pos], size = OP_SIZE[op];\n if (size === 0) throw new BCWriteError(`invalid opcode ${op} at pc ${pos}`);\n if (OP_KIND[op] === OPK_ATOM && pos + 5 <= len) {\n const atom = (bc[pos + 1] | (bc[pos + 2] << 8) | (bc[pos + 3] << 16) | (bc[pos + 4] << 24)) >>> 0;\n const v = this.atom_to_idx(atom);\n bc[pos + 1] = v; bc[pos + 2] = v >>> 8; bc[pos + 3] = v >>> 16; bc[pos + 4] = v >>> 24;\n }\n pos += size;\n }\n if (pos !== len) throw new BCWriteError('truncated instruction at the end of the byte code');\n return bc;\n }\n\n finish(body: ByteBuf): Uint8Array {\n const out = new ByteBuf();\n for (const c of BC_MAGIC) out.u8(c);\n out.u8(BC_FORMAT);\n out.leb(JSEPTION_VERSION.length);\n for (let i = 0; i < JSEPTION_VERSION.length; i++) out.u8(JSEPTION_VERSION.charCodeAt(i));\n out.leb(this.flags & JS_WRITE_OBJ_SOURCE ? BC_FLAG_SOURCE : 0);\n /* string table */\n const strings = this.strings;\n out.leb(strings.length);\n let narrow_len = 0, wide_len = 0;\n const wide: boolean[] = [];\n for (const s of strings) {\n let w = false;\n for (let i = 0; i < s.length; i++) if (s.charCodeAt(i) > 0xff) { w = true; break; }\n wide.push(w);\n out.leb(s.length * 2 + (w ? 1 : 0));\n if (w) wide_len += s.length; else narrow_len += s.length;\n }\n out.leb(narrow_len);\n const narrow = new Uint8Array(narrow_len);\n let p = 0;\n for (let k = 0; k < strings.length; k++) {\n if (wide[k]) continue;\n const s = strings[k];\n for (let i = 0; i < s.length; i++) narrow[p++] = s.charCodeAt(i);\n }\n out.bytes(narrow);\n out.leb(wide_len * 2);\n const wbuf = new Uint8Array(wide_len * 2);\n p = 0;\n for (let k = 0; k < strings.length; k++) {\n if (!wide[k]) continue;\n const s = strings[k];\n for (let i = 0; i < s.length; i++) { const c = s.charCodeAt(i); wbuf[p++] = c; wbuf[p++] = c >>> 8; }\n }\n out.bytes(wbuf);\n /* atom table */\n out.leb(this.atoms.length);\n for (const i of this.atoms) out.leb(i);\n out.bytes(body.buf.subarray(0, body.len));\n const [a, b] = checksum(out.buf, out.len);\n for (const v of [a, b]) { out.u8(v & 0xff); out.u8((v >>> 8) & 0xff); out.u8((v >>> 16) & 0xff); out.u8(v >>> 24); }\n return out.result();\n }\n}\n\nfunction describe(v: unknown): string {\n if (typeof v === 'function') return 'function object';\n if (Array.isArray(v)) return 'array';\n if (typeof v === 'object' && v !== null) return 'object';\n return typeof v;\n}\n\nconst CHECKSUM_SIZE = 8;\n\n/* Fletcher-style sums of buf[0, end) taken as little-endian 32-bit words (the tail bytewise):\n detects truncation and corrupted bytes, at a quarter of the cost of a bytewise checksum\n (it is not a defence against deliberate tampering) */\nfunction checksum(buf: Uint8Array, end: number): [number, number] {\n const n = end >>> 2;\n let a = 1, b = 0;\n if (LITTLE_ENDIAN) {\n if (buf.byteOffset & 3) buf = buf.slice(0, end);\n const w = new Int32Array(buf.buffer, buf.byteOffset, n);\n for (let i = 0; i < n; i++) { a = (a + w[i]) | 0; b = (b + a) | 0; }\n } else {\n for (let i = 0; i < n; i++) {\n const p = i * 4;\n a = (a + (buf[p] | (buf[p + 1] << 8) | (buf[p + 2] << 16) | (buf[p + 3] << 24))) | 0; b = (b + a) | 0;\n }\n }\n for (let i = n * 4; i < end; i++) { a = (a + buf[i]) | 0; b = (b + a) | 0; }\n return [a >>> 0, b >>> 0];\n}\n\n/* Serialize the function returned by JS_Eval(..., JS_EVAL_FLAG_COMPILE_ONLY) (or any\n bytecode function that does not close over variables). Returns null with a pending\n exception on failure. */\nexport function JS_WriteObject(ctx: JSContext, obj: JSValue, flags = 0): Uint8Array | null {\n const fd = JS_GetFunctionData(obj);\n if (fd === null) {\n JS_ThrowTypeError(ctx, 'JS_WriteObject: not a bytecode function (expected the result of JS_EVAL_FLAG_COMPILE_ONLY)');\n return null;\n }\n const b = fd.function_bytecode;\n if (b.closure_var.length !== 0) {\n JS_ThrowTypeError(ctx, 'JS_WriteObject: the function closes over variables of an enclosing scope');\n return null;\n }\n const w = new BCWriter(ctx, flags);\n try {\n w.function(b);\n const body = w.out;\n return w.finish(body);\n } catch (e) {\n if (e instanceof BCWriteError) { JS_ThrowTypeError(ctx, 'JS_WriteObject: ' + e.message); return null; }\n throw e;\n }\n}\n\n/* ---------------------------------------------------------------------\n Reader\n --------------------------------------------------------------------- */\n\nclass BCReadError extends Error {}\n\nconst MAX_DEPTH = 2000;\n/* parser limits (define_var / add_arg: at most 65534 each; compute_stack_size: JS_STACK_SIZE_MAX) */\nconst MAX_LOCALS = 65535;\nconst MAX_STACK_SIZE = 65534;\n\nclass BCReader {\n pos = 0;\n end: number;\n strings: string[] = [];\n atoms: JSAtom[] = [];\n keep_source = false;\n depth = 0;\n private f64 = new Float64Array(1);\n private f64b = new Uint8Array(this.f64.buffer);\n buf: Uint8Array;\n /* the reader works on a private copy of the input: the byte code is patched in place and\n the functions keep views of it (one copy instead of two per function) */\n constructor(public ctx: JSContext, input: Uint8Array) { this.buf = input.slice(); this.end = this.buf.length; }\n\n fail(msg: string): never { throw new BCReadError(msg); }\n truncated(): never { throw new BCReadError('read after the end of the buffer'); }\n\n u8(): number {\n if (this.pos >= this.end) this.truncated();\n return this.buf[this.pos++];\n }\n leb(): number {\n const buf = this.buf;\n let pos = this.pos;\n if (pos >= this.end) this.truncated();\n let a = buf[pos++];\n if (a < 0x80) { this.pos = pos; return a; }\n let v = a & 0x7f, mul = 0x80;\n for (let i = 1; ; i++) {\n if (pos >= this.end) this.truncated();\n if (i >= 5) this.fail('invalid LEB128 number');\n a = buf[pos++];\n v += (a & 0x7f) * mul;\n if (a < 0x80) break;\n mul *= 0x80;\n }\n if (v > 0xffffffff) this.fail('invalid LEB128 number');\n this.pos = pos;\n return v;\n }\n sleb(): number {\n const v = this.leb();\n return (v % 2 === 1) ? -((v + 1) / 2) : v / 2;\n }\n f64v(): number {\n if (this.pos + 8 > this.end) this.truncated();\n const b = this.f64b, buf = this.buf;\n if (LITTLE_ENDIAN) for (let i = 0; i < 8; i++) b[i] = buf[this.pos++];\n else for (let i = 7; i >= 0; i--) b[i] = buf[this.pos++];\n return this.f64[0];\n }\n /* a count whose items each take at least one byte */\n count(): number {\n const n = this.leb();\n if (n > this.end - this.pos) this.truncated();\n return n;\n }\n bytes(n: number): Uint8Array {\n if (n > this.end - this.pos) this.truncated();\n const r = this.buf.subarray(this.pos, this.pos + n);\n this.pos += n;\n return r;\n }\n string(): string {\n const i = this.leb();\n if (i >= this.strings.length) this.fail(`invalid string index ${i}`);\n return this.strings[i];\n }\n\n /* bc_idx_to_atom */\n idx_to_atom(v: number): JSAtom {\n if (v < JS_ATOM_END || v >= JS_ATOM_TAG_INT) return v;\n const i = v - JS_ATOM_END;\n if (i >= this.atoms.length) this.fail(`invalid atom index ${v}`);\n return this.atoms[i];\n }\n atom(): JSAtom { return this.idx_to_atom(this.leb()); }\n\n header(): void {\n const buf = this.buf;\n if (buf.length < BC_MAGIC.length + 2 + CHECKSUM_SIZE) this.truncated();\n for (let i = 0; i < BC_MAGIC.length; i++) if (buf[i] !== BC_MAGIC[i]) this.fail('not jseption bytecode (bad magic number)');\n this.pos = BC_MAGIC.length;\n const format = this.u8();\n const vlen = this.leb();\n if (vlen > 64) this.fail('not jseption bytecode (bad header)');\n if (vlen > this.end - this.pos) this.truncated();\n let version = '';\n for (let i = 0; i < vlen; i++) version += String.fromCharCode(buf[this.pos++]);\n if (format !== BC_FORMAT || version !== JSEPTION_VERSION)\n this.fail(`bytecode version mismatch: written by jseption ${version} (format ${format}), ` +\n `this is jseption ${JSEPTION_VERSION} (format ${BC_FORMAT})`);\n /* everything after the version is covered by the checksum */\n if (buf.length - CHECKSUM_SIZE < this.pos) this.truncated();\n this.end = buf.length - CHECKSUM_SIZE;\n const [a, b] = checksum(buf, this.end);\n const u32 = (p: number) => (buf[p] | (buf[p + 1] << 8) | (buf[p + 2] << 16) | (buf[p + 3] << 24)) >>> 0;\n if (u32(this.end) !== a || u32(this.end + 4) !== b) this.fail('checksum mismatch (truncated or corrupted bytecode)');\n const flags = this.leb();\n if (flags & ~BC_FLAG_SOURCE) this.fail('unknown flags');\n this.keep_source = (flags & BC_FLAG_SOURCE) !== 0;\n }\n\n string_table(): void {\n const n = this.count();\n const lens = new Array<number>(n);\n let narrow_len = 0, wide_len = 0;\n for (let i = 0; i < n; i++) {\n const v = this.leb();\n lens[i] = v;\n if (v & 1) wide_len += (v - 1) / 2; else narrow_len += v / 2;\n }\n if (this.leb() !== narrow_len) this.fail('inconsistent string table');\n if (narrow_len > this.end - this.pos) this.truncated();\n const narrow = latin1_decode(this.buf, this.pos, this.pos + narrow_len);\n this.pos += narrow_len;\n if (this.leb() !== wide_len * 2) this.fail('inconsistent string table');\n if (wide_len * 2 > this.end - this.pos) this.truncated();\n const wide = utf16_decode(this.buf, this.pos, wide_len);\n this.pos += wide_len * 2;\n const strings = this.strings = new Array<string>(n);\n let np = 0, wp = 0;\n for (let i = 0; i < n; i++) {\n const v = lens[i];\n if (v & 1) { const l = (v - 1) / 2; strings[i] = wide.slice(wp, wp + l); wp += l; }\n else { const l = v / 2; strings[i] = narrow.slice(np, np + l); np += l; }\n }\n }\n\n atom_table(): void {\n const n = this.count();\n const atoms = this.atoms = new Array<JSAtom>(n);\n const table = this.ctx.rt.atoms;\n for (let i = 0; i < n; i++) atoms[i] = table.newAtomStr(this.string());\n }\n\n value(): JSValue | JSFunctionBytecode {\n const tag = this.u8();\n switch (tag) {\n case BCTag.NULL: return null;\n case BCTag.UNDEFINED: return undefined;\n case BCTag.FALSE: return false;\n case BCTag.TRUE: return true;\n case BCTag.INT32: {\n const v = this.sleb();\n if ((v | 0) !== v) this.fail('invalid int32');\n return v;\n }\n case BCTag.FLOAT64: return this.f64v();\n case BCTag.STRING: return this.string();\n case BCTag.BIG_INT: {\n const s = this.string();\n if (!/^-?[0-9]+$/.test(s)) this.fail('invalid BigInt');\n return BigInt(s);\n }\n case BCTag.FUNCTION_BYTECODE: return this.function();\n case BCTag.TEMPLATE_OBJECT: return this.template();\n }\n return this.fail(`invalid tag ${tag} at offset ${this.pos - 1}`);\n }\n\n template(): JSValue {\n const ctx = this.ctx;\n const n = this.count();\n const arr = JS_NewArray(ctx), raw = JS_NewArray(ctx);\n if (JS_IsException(arr) || JS_IsException(raw)) this.fail('out of memory');\n for (let i = 0; i < n; i++) {\n const c = this.leb();\n let cooked: string | undefined;\n if (c !== 0) {\n if (c > this.strings.length) this.fail(`invalid string index ${c - 1}`);\n cooked = this.strings[c - 1];\n }\n JS_DefinePropertyValueUint32(ctx, raw, i, this.string(), JS_PROP_ENUMERABLE);\n JS_DefinePropertyValueUint32(ctx, arr, i, cooked, JS_PROP_ENUMERABLE);\n }\n JS_DefinePropertyValue(ctx, arr, JS_ATOM_raw, raw, 0);\n Object.freeze(raw as object);\n Object.freeze(arr as object);\n return arr;\n }\n\n function(): JSFunctionBytecode {\n if (++this.depth > MAX_DEPTH) this.fail('functions nested too deeply');\n const b = new JSFunctionBytecode();\n const flags = this.leb();\n if (flags >= F_HAS_SOURCE << 1) this.fail('invalid function flags');\n b.has_prototype = (flags & F_HAS_PROTOTYPE) !== 0;\n b.has_simple_parameter_list = (flags & F_SIMPLE_PARAMS) !== 0;\n b.is_derived_class_constructor = (flags & F_DERIVED_CTOR) !== 0;\n b.need_home_object = (flags & F_HOME_OBJECT) !== 0;\n b.new_target_allowed = (flags & F_NEW_TARGET) !== 0;\n b.super_call_allowed = (flags & F_SUPER_CALL) !== 0;\n b.super_allowed = (flags & F_SUPER) !== 0;\n b.arguments_allowed = (flags & F_ARGUMENTS) !== 0;\n b.has_debug = (flags & F_HAS_DEBUG) !== 0;\n b.is_direct_or_indirect_eval = (flags & F_EVAL) !== 0;\n b.js_mode = this.u8();\n const kind = this.u8();\n if (kind > JSFunctionKind.ASYNC_GENERATOR) this.fail('invalid function kind');\n b.func_kind = kind;\n b.func_name = this.atom();\n b.arg_count = this.count();\n b.var_count = this.count();\n b.defined_arg_count = this.leb();\n b.stack_size = this.leb();\n /* the parser's limits: the interpreter sizes each frame from these, so an out-of-range\n value would make it allocate a huge frame instead of failing here */\n if (b.arg_count >= MAX_LOCALS || b.var_count >= MAX_LOCALS) this.fail('too many variables');\n if (b.defined_arg_count > b.arg_count) this.fail('invalid defined argument count');\n if (b.stack_size > MAX_STACK_SIZE) this.fail(`invalid stack size ${b.stack_size}`);\n const closure_count = this.count();\n const cpool_count = this.count();\n const bc_len = this.count();\n const nvars = b.arg_count + b.var_count;\n const vardefs = b.vardefs = new Array<JSVarDef>(nvars);\n for (let i = 0; i < nvars; i++) {\n const vd = new JSVarDef(this.atom());\n vd.scope_level = this.leb();\n vd.scope_next = this.sleb();\n const f = this.u8();\n vd.is_const = (f & V_CONST) !== 0;\n vd.is_lexical = (f & V_LEXICAL) !== 0;\n vd.is_captured = (f & V_CAPTURED) !== 0;\n vd.is_static_private = (f & V_STATIC_PRIVATE) !== 0;\n const k = this.u8();\n if (k > VAR_KIND_MAX) this.fail('invalid variable kind');\n vd.var_kind = k;\n vd.func_pool_idx = this.sleb();\n vardefs[i] = vd;\n }\n const closure_var = b.closure_var = new Array<JSClosureVar>(closure_count);\n for (let i = 0; i < closure_count; i++) {\n const cv = new JSClosureVar();\n cv.var_name = this.atom();\n cv.var_idx = this.leb();\n const f = this.u8();\n cv.is_const = (f & V_CONST) !== 0;\n cv.is_lexical = (f & V_LEXICAL) !== 0;\n cv.is_local = (f & V_LOCAL) !== 0;\n cv.is_arg = (f & V_ARG) !== 0;\n const k = this.u8();\n if (k > VAR_KIND_MAX) this.fail('invalid variable kind');\n cv.var_kind = k;\n closure_var[i] = cv;\n }\n const bc = this.bytes(bc_len);\n b.byte_code_buf = bc;\n b.byte_code_len = bc_len;\n if (b.has_debug) {\n b.debug.filename = this.atom();\n const n = this.leb();\n b.debug.pc2line = this.bytes(n);\n if (flags & F_HAS_SOURCE) {\n if (!this.keep_source) this.fail('invalid function flags');\n const src = this.string();\n b.debug.source = src;\n b.debug.source_len = src.length;\n }\n } else if (flags & F_HAS_SOURCE) {\n this.fail('invalid function flags');\n }\n const cpool = b.cpool = new Array<JSValue | JSFunctionBytecode>(cpool_count);\n for (let i = 0; i < cpool_count; i++) cpool[i] = this.value();\n this.fixup_byte_code(b);\n b.realm = this.ctx;\n this.depth--;\n return b;\n }\n\n /* patch the atom operands and check the instruction boundaries and the constant pool\n indices (JS_ReadFunctionBytecode) */\n fixup_byte_code(b: JSFunctionBytecode): void {\n const bc = b.byte_code_buf, len = b.byte_code_len, cpool = b.cpool;\n let pos = 0;\n const natoms = this.atoms.length, atoms = this.atoms;\n while (pos < len) {\n const op = bc[pos], size = OP_SIZE[op];\n if (size === 0) this.fail(`invalid opcode ${op} at pc ${pos}`);\n if (pos + size > len) this.fail(`truncated instruction at pc ${pos}`);\n const kind = OP_KIND[op];\n if (kind !== 0) {\n if (kind === OPK_ATOM) {\n const v = (bc[pos + 1] | (bc[pos + 2] << 8) | (bc[pos + 3] << 16) | (bc[pos + 4] << 24)) >>> 0;\n if (v >= JS_ATOM_END && v < JS_ATOM_TAG_INT) {\n const i = v - JS_ATOM_END;\n if (i >= natoms) this.fail(`invalid atom index ${v} at pc ${pos}`);\n const atom = atoms[i];\n bc[pos + 1] = atom; bc[pos + 2] = atom >>> 8; bc[pos + 3] = atom >>> 16; bc[pos + 4] = atom >>> 24;\n }\n } else {\n const idx = (kind === OPK_CONST8 || kind === OPK_FCLOSURE8) ? bc[pos + 1]\n : (bc[pos + 1] | (bc[pos + 2] << 8) | (bc[pos + 3] << 16) | (bc[pos + 4] << 24)) >>> 0;\n if (idx >= cpool.length) this.fail(`invalid constant pool index ${idx} at pc ${pos}`);\n if (kind >= OPK_FCLOSURE && !(cpool[idx] instanceof JSFunctionBytecode))\n this.fail(`closure of a constant that is not a function at pc ${pos}`);\n }\n }\n pos += size;\n }\n }\n}\n\n/* buf[start, end) as a Latin-1 string */\nfunction latin1_decode(buf: Uint8Array, start: number, end: number): string {\n const CHUNK = 8192;\n if (end - start <= CHUNK) return String.fromCharCode.apply(null, buf.subarray(start, end) as unknown as number[]);\n const parts: string[] = [];\n for (let i = start; i < end; i += CHUNK)\n parts.push(String.fromCharCode.apply(null, buf.subarray(i, Math.min(end, i + CHUNK)) as unknown as number[]));\n return parts.join('');\n}\n\n/* n UTF-16LE code units at buf[start] as a string (lone surrogates preserved) */\nfunction utf16_decode(buf: Uint8Array, start: number, n: number): string {\n if (n === 0) return '';\n let units: Uint16Array;\n if (LITTLE_ENDIAN) {\n units = new Uint16Array(buf.slice(start, start + 2 * n).buffer);\n } else {\n units = new Uint16Array(n);\n for (let i = 0; i < n; i++) units[i] = buf[start + 2 * i] | (buf[start + 2 * i + 1] << 8);\n }\n const CHUNK = 8192;\n const parts: string[] = [];\n for (let i = 0; i < n; i += CHUNK)\n parts.push(String.fromCharCode.apply(null, units.subarray(i, Math.min(n, i + CHUNK)) as unknown as number[]));\n return parts.join('');\n}\n\n/* Read bytes produced by JS_WriteObject into this context. Returns a function object to\n run with JS_EvalFunction, or JS_EXCEPTION with a SyntaxError pending when the input is\n not valid bytecode of this jseption version. */\nexport function JS_ReadObject(ctx: JSContext, buf: Uint8Array): JSValue {\n if (!(buf instanceof Uint8Array)) return JS_ThrowTypeError(ctx, 'JS_ReadObject: expected a Uint8Array');\n const r = new BCReader(ctx, buf);\n let b: JSFunctionBytecode;\n try {\n r.header();\n r.string_table();\n r.atom_table();\n if (r.u8() !== BCTag.FUNCTION_BYTECODE) r.fail('the root value is not a function');\n b = r.function();\n if (r.pos !== r.end) r.fail('trailing bytes after the root value');\n } catch (e) {\n if (e instanceof BCReadError) return JS_ThrowSyntaxError(ctx, 'JS_ReadObject: ' + e.message);\n if (e instanceof RangeError) return JS_ThrowSyntaxError(ctx, 'JS_ReadObject: ' + e.message);\n throw e;\n }\n if (b.closure_var.length !== 0) return JS_ThrowSyntaxError(ctx, 'JS_ReadObject: the root function has closure variables');\n return hooks.js_closure(ctx, b, null, null);\n}\n\n"]}
@@ -4,6 +4,8 @@ import './builtins/index.ts';
4
4
  import './jit.ts';
5
5
  export * from './quickjs.ts';
6
6
  export { OP, opcode_info } from './opcodes.ts';
7
+ export { JS_WriteObject, JS_ReadObject, JS_WRITE_OBJ_SOURCE } from './bytecode.ts';
8
+ export { JSEPTION_VERSION } from './version.ts';
7
9
  export { JS_CallInternal, js_closure } from './interpreter.ts';
8
10
  export { jit_config, jit_configure, jit_compile, jit_generate_source, jit_stats, jit_probe, jit_is_wrapper, jit_default_mode } from './jit.ts';
9
11
  export { JS_EvalInternal, next_token, JSParseState, TOK } from './parser.ts';
package/dist/jseption.js CHANGED
@@ -10,6 +10,8 @@ import "./builtins/index.js";
10
10
  import "./jit.js";
11
11
  export * from "./quickjs.js";
12
12
  export { opcode_info } from "./opcodes.js";
13
+ export { JS_WriteObject, JS_ReadObject, JS_WRITE_OBJ_SOURCE } from "./bytecode.js";
14
+ export { JSEPTION_VERSION } from "./version.js";
13
15
  export { JS_CallInternal, js_closure } from "./interpreter.js";
14
16
  export { jit_config, jit_configure, jit_compile, jit_generate_source, jit_stats, jit_probe, jit_is_wrapper, jit_default_mode } from "./jit.js";
15
17
  export { JS_EvalInternal, next_token, JSParseState } from "./parser.js";
@@ -1 +1 @@
1
- {"version":3,"file":"jseption.js","sourceRoot":"","sources":["../src/jseption.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,aAAa,CAAC;AACrB,OAAO,qBAAqB,CAAC;AAC7B,OAAO,UAAU,CAAC;AAElB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAM,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC/I,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAO,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE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ACzE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,cAAc,CAAC,EAAa;IAC1C,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,IAAwB,EAAE,CAAC;IAC/C,OAAO,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,oBAAoB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACV,0CAA0C;YAC1C,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;gBACb,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACtC,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;QACD,CAAC,EAAE,CAAC;IACN,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC","sourcesContent":["/*\n * jseption: TypeScript port of QuickJS - public entry point\n *\n * Importing this module loads the interpreter, the compiler and the\n * builtin objects and re-exports the core API.\n */\nimport './interpreter.ts';\nimport './parser.ts';\nimport './builtins/index.ts';\nimport './jit.ts';\n\nexport * from './quickjs.ts';\nexport { OP, opcode_info } from './opcodes.ts';\nexport { JS_CallInternal, js_closure } from './interpreter.ts';\nexport { jit_config, jit_configure, jit_compile, jit_generate_source, jit_stats, jit_probe, jit_is_wrapper, jit_default_mode } from './jit.ts';\nexport { JS_EvalInternal, next_token, JSParseState, TOK } from './parser.ts';\nexport { toGuest, fromGuest, expose, hostFunction, hostPromise, guestPromiseToHost, guestErrorToHost, isGuestValue, drainJobs } from './embed.ts';\nexport type { ToGuestOptions } from './embed.ts';\n\nimport { JSContext, JSValue, JS_Eval, JS_IsException, JS_GetException, JS_ToString, JS_GetPropertyStr, JS_IsError,\n JS_EVAL_TYPE_GLOBAL, JSRuntime, JS_ExecutePendingJob, JS_IsJobPending } from './quickjs.ts';\n\n/* convenience helpers for tests and the CLI */\n\n/* evaluate 'src' and return the result or throw a host Error describing the JS exception */\nexport function evalOrThrow(ctx: JSContext, src: string, filename = '<eval>', flags: number = JS_EVAL_TYPE_GLOBAL): JSValue {\n const r = JS_Eval(ctx, src, filename, flags);\n if (JS_IsException(r)) {\n const exc = JS_GetException(ctx);\n throw new Error(formatException(ctx, exc));\n }\n return r;\n}\n\nexport function formatException(ctx: JSContext, exc: JSValue): string {\n let msg: string;\n const s = JS_ToString(ctx, exc);\n if (JS_IsException(s)) { JS_GetException(ctx); msg = '[exception]'; }\n else msg = s as string;\n if (JS_IsError(ctx, exc)) {\n const stack = JS_GetPropertyStr(ctx, exc, 'stack');\n if (typeof stack === 'string' && stack.length > 0) msg += '\\n' + stack;\n }\n return msg;\n}\n\n/* run all pending promise jobs; returns the number of jobs executed */\nexport function runPendingJobs(rt: JSRuntime): number {\n let n = 0;\n const pctx = { ctx: null as JSContext | null };\n while (JS_IsJobPending(rt)) {\n const r = JS_ExecutePendingJob(rt, pctx);\n if (r < 0) {\n /* the exception is left in the context */\n if (pctx.ctx) {\n const exc = JS_GetException(pctx.ctx);\n throw new Error('uncaught exception in job: ' + formatException(pctx.ctx, exc));\n }\n }\n n++;\n }\n return n;\n}\n"]}
1
+ {"version":3,"file":"jseption.js","sourceRoot":"","sources":["../src/jseption.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,aAAa,CAAC;AACrB,OAAO,qBAAqB,CAAC;AAC7B,OAAO,UAAU,CAAC;AAElB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAM,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,C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e,CAAC,GAAG,CAAC,CAAC;QAAC,GAAG,GAAG,aAAa,CAAC;IAAC,CAAC;;QAChE,GAAG,GAAG,CAAW,CAAC;IACvB,IAAI,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,GAAG,IAAI,IAAI,GAAG,KAAK,CAAC;IACzE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,cAAc,CAAC,EAAa;IAC1C,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,IAAwB,EAAE,CAAC;IAC/C,OAAO,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,oBAAoB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACV,0CAA0C;YAC1C,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;gBACb,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACtC,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;QACD,CAAC,EAAE,CAAC;IACN,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC","sourcesContent":["/*\n * jseption: TypeScript port of QuickJS - public entry point\n *\n * Importing this module loads the interpreter, the compiler and the\n * builtin objects and re-exports the core API.\n */\nimport './interpreter.ts';\nimport './parser.ts';\nimport './builtins/index.ts';\nimport './jit.ts';\n\nexport * from './quickjs.ts';\nexport { OP, opcode_info } from './opcodes.ts';\nexport { JS_WriteObject, JS_ReadObject, JS_WRITE_OBJ_SOURCE } from './bytecode.ts';\nexport { JSEPTION_VERSION } from './version.ts';\nexport { JS_CallInternal, js_closure } from './interpreter.ts';\nexport { jit_config, jit_configure, jit_compile, jit_generate_source, jit_stats, jit_probe, jit_is_wrapper, jit_default_mode } from './jit.ts';\nexport { JS_EvalInternal, next_token, JSParseState, TOK } from './parser.ts';\nexport { toGuest, fromGuest, expose, hostFunction, hostPromise, guestPromiseToHost, guestErrorToHost, isGuestValue, drainJobs } from './embed.ts';\nexport type { ToGuestOptions } from './embed.ts';\n\nimport { JSContext, JSValue, JS_Eval, JS_IsException, JS_GetException, JS_ToString, JS_GetPropertyStr, JS_IsError,\n JS_EVAL_TYPE_GLOBAL, JSRuntime, JS_ExecutePendingJob, JS_IsJobPending } from './quickjs.ts';\n\n/* convenience helpers for tests and the CLI */\n\n/* evaluate 'src' and return the result or throw a host Error describing the JS exception */\nexport function evalOrThrow(ctx: JSContext, src: string, filename = '<eval>', flags: number = JS_EVAL_TYPE_GLOBAL): JSValue {\n const r = JS_Eval(ctx, src, filename, flags);\n if (JS_IsException(r)) {\n const exc = JS_GetException(ctx);\n throw new Error(formatException(ctx, exc));\n }\n return r;\n}\n\nexport function formatException(ctx: JSContext, exc: JSValue): string {\n let msg: string;\n const s = JS_ToString(ctx, exc);\n if (JS_IsException(s)) { JS_GetException(ctx); msg = '[exception]'; }\n else msg = s as string;\n if (JS_IsError(ctx, exc)) {\n const stack = JS_GetPropertyStr(ctx, exc, 'stack');\n if (typeof stack === 'string' && stack.length > 0) msg += '\\n' + stack;\n }\n return msg;\n}\n\n/* run all pending promise jobs; returns the number of jobs executed */\nexport function runPendingJobs(rt: JSRuntime): number {\n let n = 0;\n const pctx = { ctx: null as JSContext | null };\n while (JS_IsJobPending(rt)) {\n const r = JS_ExecutePendingJob(rt, pctx);\n if (r < 0) {\n /* the exception is left in the context */\n if (pctx.ctx) {\n const exc = JS_GetException(pctx.ctx);\n throw new Error('uncaught exception in job: ' + formatException(pctx.ctx, exc));\n }\n }\n n++;\n }\n return n;\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const JSEPTION_VERSION = "0.0.3";
@@ -0,0 +1,5 @@
1
+ /* The jseption package version, kept equal to package.json by the npm "version" script
2
+ (scripts/sync-version.mjs) and checked by tests/bytecode.test.ts. Serialized bytecode
3
+ records it and only loads in the same version. */
4
+ export const JSEPTION_VERSION = '0.0.3';
5
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;oDAEoD;AACpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC","sourcesContent":["/* The jseption package version, kept equal to package.json by the npm \"version\" script\n (scripts/sync-version.mjs) and checked by tests/bytecode.test.ts. Serialized bytecode\n records it and only loads in the same version. */\nexport const JSEPTION_VERSION = '0.0.3';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jseption",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A sandboxed JavaScript engine for any JavaScript host, built on a TypeScript port of QuickJS with a bytecode-to-JavaScript compiler",
5
5
  "keywords": [
6
6
  "quickjs",
@@ -52,7 +52,8 @@
52
52
  "qjs": "bun run src/qjs.ts",
53
53
  "typecheck": "bun x tsc --noEmit -p tsconfig.json",
54
54
  "build": "rm -rf dist && bun x tsc -p tsconfig.build.json && chmod +x dist/qjs.js",
55
- "prepack": "bun run build"
55
+ "prepack": "bun run build",
56
+ "version": "node scripts/sync-version.mjs && git add src/version.ts"
56
57
  },
57
58
  "devDependencies": {
58
59
  "@types/bun": "latest",