Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/quickbeam/context_worker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ pub fn pool_worker_main(pd: *ct.PoolData) void {
qjs.JS_SetInterruptHandler(rt, &interrupt_handler, @ptrCast(pd));

types.class_ids_mutex.lock();
_ = qjs.JS_NewClassID(rt, &beam_proxy.class_id);
_ = qjs.JS_NewClassID(rt, &dom.document_class_id);
_ = qjs.JS_NewClassID(rt, &dom.element_class_id);
types.reserveClassID(rt, &beam_proxy.class_id);
types.reserveClassID(rt, &dom.document_class_id);
types.reserveClassID(rt, &dom.element_class_id);
types.class_ids_mutex.unlock();

beam_proxy.initRuntime(rt);
Expand Down
1 change: 1 addition & 0 deletions lib/quickbeam/dom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ fn install_element_proto(ctx: *qjs.JSContext, obj: qjs.JSValue) void {
fn document_finalizer(rt: ?*qjs.JSRuntime, val: qjs.JSValue) callconv(.c) void {
const ptr = qjs.JS_GetOpaque(val, document_class_id);
if (ptr == null) return;
_ = qjs.JS_SetOpaque(val, null);
const dd: *DocumentData = @ptrCast(@alignCast(ptr));
var it = dd.node_map.iterator();
while (it.next()) |entry| {
Expand Down
15 changes: 7 additions & 8 deletions lib/quickbeam/napi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2175,14 +2175,13 @@ pub const napi_symbol_table = [_]*const anyopaque{
};

pub fn initRuntime(rt: *qjs.JSRuntime) void {
if (nt.external_class_id == 0) {
_ = qjs.JS_NewClassID(rt, &nt.external_class_id);
_ = qjs.JS_NewClass(rt, nt.external_class_id, &external_class_def);
}
if (wrap_mod.wrap_class_id == 0) {
_ = qjs.JS_NewClassID(rt, &wrap_mod.wrap_class_id);
_ = qjs.JS_NewClass(rt, wrap_mod.wrap_class_id, &wrap_mod.wrap_class_def);
}
types.class_ids_mutex.lock();
types.reserveClassID(rt, &nt.external_class_id);
types.reserveClassID(rt, &wrap_mod.wrap_class_id);
types.class_ids_mutex.unlock();

_ = qjs.JS_NewClass(rt, nt.external_class_id, &external_class_def);
_ = qjs.JS_NewClass(rt, wrap_mod.wrap_class_id, &wrap_mod.wrap_class_def);
std.mem.doNotOptimizeAway(&napi_symbol_table);
}

Expand Down
11 changes: 11 additions & 0 deletions lib/quickbeam/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ pub const gpa = std.heap.c_allocator;

pub var class_ids_mutex: std.Thread.Mutex = .{};

pub fn reserveClassID(rt: *qjs.JSRuntime, class_id: *qjs.JSClassID) void {
if (class_id.* == 0) {
_ = qjs.JS_NewClassID(rt, class_id);
return;
}

var reserved: qjs.JSClassID = 0;
_ = qjs.JS_NewClassID(rt, &reserved);
if (reserved != class_id.*) @panic("QuickJS class ID allocation order mismatch");
}

pub const SyncCallSlot = struct {
result_json: []const u8 = "",
result_env: ?*e.ErlNifEnv = null,
Expand Down
12 changes: 6 additions & 6 deletions lib/quickbeam/worker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ pub const WorkerState = struct {

wasm_js.destroy_context(self.ctx);

// Run GC before freeing context to collect cycles
qjs.JS_RunGC(self.rt);
qjs.JS_FreeContext(self.ctx);
// Collect cycles after context-owned globals and host objects have run finalizers.
qjs.JS_RunGC(self.rt);

if (self.napi_env) |nenv| {
nenv.deinit();
Expand Down Expand Up @@ -601,8 +601,8 @@ pub const WorkerState = struct {
}
self.atoms.deinit(self.ctx);
wasm_js.destroy_context(self.ctx);
qjs.JS_RunGC(self.rt);
qjs.JS_FreeContext(self.ctx);
qjs.JS_RunGC(self.rt);
self.ctx = qjs.JS_NewContext(self.rt) orelse {
result.ok = false;
result.json = "Failed to create new context";
Expand Down Expand Up @@ -921,9 +921,9 @@ pub fn worker_main(rd: *types.RuntimeData, owner_pid: beam.pid) void {
qjs.JS_SetInterruptHandler(rt, &interrupt_handler, @ptrCast(rd));

types.class_ids_mutex.lock();
_ = qjs.JS_NewClassID(rt, &beam_proxy.class_id);
_ = qjs.JS_NewClassID(rt, &dom.document_class_id);
_ = qjs.JS_NewClassID(rt, &dom.element_class_id);
types.reserveClassID(rt, &beam_proxy.class_id);
types.reserveClassID(rt, &dom.document_class_id);
types.reserveClassID(rt, &dom.element_class_id);
types.class_ids_mutex.unlock();

beam_proxy.initRuntime(rt);
Expand Down
144 changes: 72 additions & 72 deletions priv/c_src/builtin-array-fromasync.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const uint32_t qjsc_builtin_array_fromasync_size = 875;

const uint8_t qjsc_builtin_array_fromasync[875] = {
0x18, 0x19, 0x88, 0x92, 0xde, 0x0e, 0x01, 0x28,
0x1a, 0x29, 0xd1, 0x7b, 0x48, 0x0e, 0x01, 0x28,
0x53, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0xb7, 0x61,
0x73, 0x79, 0x6e, 0x63, 0x49, 0x74, 0x65, 0x72,
0x61, 0x74, 0x6f, 0x72, 0x01, 0x2a, 0x4f, 0x62,
Expand All @@ -25,95 +25,95 @@ const uint8_t qjsc_builtin_array_fromasync[875] = {
0x08, 0x69, 0x74, 0x65, 0x72, 0x01, 0x1c, 0x6e,
0x6f, 0x74, 0x20, 0x61, 0x20, 0x66, 0x75, 0x6e,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x01, 0x08, 0x63,
0x61, 0x6c, 0x6c, 0x0c, 0x00, 0x02, 0x00, 0xa2,
0x61, 0x6c, 0x6c, 0x0c, 0x00, 0x02, 0x00, 0xa8,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x04, 0x01, 0xa4, 0x01, 0x00, 0x00, 0x00, 0x0c,
0x04, 0x01, 0xaa, 0x01, 0x00, 0x00, 0x00, 0x0c,
0x43, 0x02, 0x01, 0x00, 0x05, 0x00, 0x05, 0x01,
0x05, 0x00, 0x01, 0x03, 0x05, 0xae, 0x02, 0x00,
0x01, 0x40, 0x03, 0xa4, 0x03, 0x00, 0x01, 0x40,
0x00, 0xca, 0x03, 0x00, 0x01, 0x40, 0x01, 0xcc,
0x03, 0x00, 0x01, 0x40, 0x04, 0xce, 0x03, 0x00,
0x01, 0x40, 0x02, 0x0c, 0x60, 0x02, 0x01, 0xf8,
0x01, 0x03, 0x0e, 0x01, 0x06, 0x00, 0x05, 0x00,
0x86, 0x04, 0x11, 0xd0, 0x03, 0x00, 0x01, 0x00,
0xd2, 0x03, 0x00, 0x01, 0x00, 0xd4, 0x03, 0x00,
0x01, 0x00, 0xd0, 0x03, 0x01, 0xff, 0xff, 0xff,
0xff, 0x0f, 0x20, 0xd2, 0x03, 0x01, 0x01, 0x20,
0xd4, 0x03, 0x01, 0x02, 0x20, 0xd6, 0x03, 0x02,
0x00, 0x20, 0xd8, 0x03, 0x02, 0x04, 0x20, 0xda,
0x03, 0x02, 0x05, 0x20, 0xdc, 0x03, 0x02, 0x06,
0x20, 0xde, 0x03, 0x02, 0x07, 0x20, 0x64, 0x06,
0x08, 0x20, 0x82, 0x01, 0x07, 0x09, 0x20, 0xe0,
0x03, 0x0a, 0x08, 0x30, 0x82, 0x01, 0x0d, 0x0b,
0x20, 0xd4, 0x01, 0x0d, 0x0c, 0x20, 0x10, 0x00,
0x01, 0x00, 0xa4, 0x03, 0x01, 0x01, 0xca, 0x03,
0x02, 0x01, 0xce, 0x03, 0x04, 0x01, 0xae, 0x02,
0x00, 0x01, 0xcc, 0x03, 0x03, 0x01, 0x08, 0xc2,
0x05, 0x00, 0x01, 0x03, 0x05, 0xbe, 0x02, 0x00,
0x01, 0x40, 0x03, 0xb4, 0x03, 0x00, 0x01, 0x40,
0x00, 0xe4, 0x03, 0x00, 0x01, 0x40, 0x01, 0xe6,
0x03, 0x00, 0x01, 0x40, 0x04, 0xe8, 0x03, 0x00,
0x01, 0x40, 0x02, 0x0c, 0x60, 0x02, 0x01, 0x88,
0x02, 0x03, 0x0e, 0x01, 0x06, 0x00, 0x05, 0x00,
0x86, 0x04, 0x11, 0xea, 0x03, 0x00, 0x01, 0x00,
0xec, 0x03, 0x00, 0x01, 0x00, 0xee, 0x03, 0x00,
0x01, 0x00, 0xea, 0x03, 0x01, 0xff, 0xff, 0xff,
0xff, 0x0f, 0x20, 0xec, 0x03, 0x01, 0x01, 0x20,
0xee, 0x03, 0x01, 0x02, 0x20, 0xf0, 0x03, 0x02,
0x00, 0x20, 0xf2, 0x03, 0x02, 0x04, 0x20, 0xf4,
0x03, 0x02, 0x05, 0x20, 0xf6, 0x03, 0x02, 0x06,
0x20, 0xf8, 0x03, 0x02, 0x07, 0x20, 0x66, 0x06,
0x08, 0x20, 0x88, 0x01, 0x07, 0x09, 0x20, 0xfa,
0x03, 0x0a, 0x08, 0x30, 0x88, 0x01, 0x0d, 0x0b,
0x20, 0xe2, 0x01, 0x0d, 0x0c, 0x20, 0x10, 0x00,
0x01, 0x00, 0xb4, 0x03, 0x01, 0x01, 0xe4, 0x03,
0x02, 0x01, 0xe8, 0x03, 0x04, 0x01, 0xbe, 0x02,
0x00, 0x01, 0xe6, 0x03, 0x03, 0x01, 0x08, 0xc8,
0x0d, 0x60, 0x02, 0x00, 0x60, 0x01, 0x00, 0x60,
0x00, 0x00, 0xd1, 0xc9, 0xd2, 0x11, 0xf2, 0xea,
0x08, 0x0e, 0x38, 0x46, 0x00, 0x00, 0x00, 0xda,
0xca, 0xd3, 0x11, 0xf2, 0xea, 0x08, 0x0e, 0x38,
0x46, 0x00, 0x00, 0x00, 0xdb, 0xcb, 0x60, 0x07,
0x00, 0x00, 0xd7, 0xcf, 0xd8, 0x11, 0xf8, 0xf0,
0x08, 0x0e, 0x38, 0x49, 0x00, 0x00, 0x00, 0xe0,
0xd0, 0xd9, 0x11, 0xf8, 0xf0, 0x08, 0x0e, 0x38,
0x49, 0x00, 0x00, 0x00, 0xe1, 0xd1, 0x60, 0x07,
0x00, 0x60, 0x06, 0x00, 0x60, 0x05, 0x00, 0x60,
0x04, 0x00, 0x60, 0x03, 0x00, 0xd2, 0x38, 0x46,
0x00, 0x00, 0x00, 0xae, 0xea, 0x16, 0xd2, 0x96,
0x04, 0x1b, 0x00, 0x00, 0x00, 0xae, 0xea, 0x0c,
0xdd, 0x11, 0x04, 0xf1, 0x00, 0x00, 0x00, 0x21,
0x01, 0x00, 0x30, 0x06, 0xcc, 0xb4, 0xc2, 0x04,
0xc1, 0x0d, 0xf5, 0xc2, 0x05, 0x09, 0xc2, 0x06,
0xd1, 0xde, 0x46, 0xc2, 0x07, 0x61, 0x07, 0x00,
0x07, 0xab, 0xea, 0x0f, 0x0a, 0x11, 0x62, 0x06,
0x00, 0x0e, 0xd1, 0xdf, 0x46, 0x11, 0x62, 0x07,
0x04, 0x00, 0x60, 0x03, 0x00, 0xd8, 0x38, 0x49,
0x00, 0x00, 0x00, 0xae, 0xf0, 0x16, 0xd8, 0x96,
0x04, 0x1b, 0x00, 0x00, 0x00, 0xae, 0xf0, 0x0c,
0xe3, 0x11, 0x04, 0xfe, 0x00, 0x00, 0x00, 0x21,
0x01, 0x00, 0x30, 0x06, 0xd2, 0xba, 0xc8, 0x04,
0xc7, 0x0d, 0xfb, 0xc8, 0x05, 0x09, 0xc8, 0x06,
0xd7, 0xe4, 0x46, 0xc8, 0x07, 0x61, 0x07, 0x00,
0x07, 0xab, 0xf0, 0x0f, 0x0a, 0x11, 0x62, 0x06,
0x00, 0x0e, 0xd7, 0xe5, 0x46, 0x11, 0x62, 0x07,
0x00, 0x0e, 0x61, 0x07, 0x00, 0x07, 0xab, 0x68,
0xa6, 0x00, 0x00, 0x00, 0x60, 0x08, 0x00, 0x06,
0x11, 0xf2, 0xeb, 0x0c, 0x6f, 0x41, 0x32, 0x00,
0x00, 0x00, 0xc2, 0x08, 0x0e, 0xec, 0x05, 0x0e,
0xd1, 0xec, 0xf2, 0x61, 0x08, 0x00, 0x8c, 0x11,
0xeb, 0x03, 0x0e, 0xb4, 0x11, 0x62, 0x08, 0x00,
0x0e, 0x61, 0x05, 0x00, 0xea, 0x0c, 0xc1, 0x0d,
0x11, 0x61, 0x08, 0x00, 0x21, 0x01, 0x00, 0xec,
0x06, 0xe0, 0x61, 0x08, 0x00, 0xef, 0x11, 0x62,
0x11, 0xf8, 0xf1, 0x0c, 0x70, 0x41, 0x33, 0x00,
0x00, 0x00, 0xc8, 0x08, 0x0e, 0xf2, 0x05, 0x0e,
0xd7, 0xf2, 0xf2, 0x61, 0x08, 0x00, 0x8c, 0x11,
0xf1, 0x03, 0x0e, 0xba, 0x11, 0x62, 0x08, 0x00,
0x0e, 0x61, 0x05, 0x00, 0xf0, 0x0c, 0xc7, 0x0d,
0x11, 0x61, 0x08, 0x00, 0x21, 0x01, 0x00, 0xf2,
0x06, 0xe6, 0x61, 0x08, 0x00, 0xf5, 0x11, 0x62,
0x03, 0x00, 0x0e, 0x61, 0x04, 0x00, 0x61, 0x08,
0x00, 0xa5, 0x68, 0x2a, 0x01, 0x00, 0x00, 0x60,
0x09, 0x00, 0xd1, 0x61, 0x04, 0x00, 0x46, 0xc2,
0x09, 0x61, 0x06, 0x00, 0xea, 0x0a, 0x61, 0x09,
0x00, 0x8a, 0x11, 0x62, 0x09, 0x00, 0x0e, 0xd2,
0xea, 0x17, 0xd2, 0x41, 0xf2, 0x00, 0x00, 0x00,
0xd3, 0x61, 0x09, 0x00, 0x61, 0x04, 0x00, 0x24,
0x09, 0x00, 0xd7, 0x61, 0x04, 0x00, 0x46, 0xc8,
0x09, 0x61, 0x06, 0x00, 0xf0, 0x0a, 0x61, 0x09,
0x00, 0x8a, 0x11, 0x62, 0x09, 0x00, 0x0e, 0xd8,
0xf0, 0x17, 0xd8, 0x41, 0xff, 0x00, 0x00, 0x00,
0xd9, 0x61, 0x09, 0x00, 0x61, 0x04, 0x00, 0x24,
0x03, 0x00, 0x8a, 0x11, 0x62, 0x09, 0x00, 0x0e,
0x5d, 0x04, 0x00, 0x61, 0x03, 0x00, 0x61, 0x04,
0x00, 0x90, 0x62, 0x04, 0x00, 0x0b, 0x61, 0x09,
0x00, 0x4b, 0x41, 0x00, 0x00, 0x00, 0x0a, 0x4b,
0x3e, 0x00, 0x00, 0x00, 0x0a, 0x4b, 0x3f, 0x00,
0x00, 0x00, 0xf1, 0x0e, 0xec, 0x9e, 0x60, 0x0a,
0x00, 0x61, 0x07, 0x00, 0x41, 0xf2, 0x00, 0x00,
0x00, 0xd1, 0x24, 0x01, 0x00, 0xc2, 0x0a, 0x61,
0x05, 0x00, 0xea, 0x09, 0xc1, 0x0d, 0x11, 0x21,
0x00, 0x00, 0xec, 0x03, 0xe0, 0xee, 0x11, 0x62,
0x00, 0x4b, 0x44, 0x00, 0x00, 0x00, 0x0a, 0x4b,
0x41, 0x00, 0x00, 0x00, 0x0a, 0x4b, 0x42, 0x00,
0x00, 0x00, 0xf7, 0x0e, 0xf2, 0x9e, 0x60, 0x0a,
0x00, 0x61, 0x07, 0x00, 0x41, 0xff, 0x00, 0x00,
0x00, 0xd7, 0x24, 0x01, 0x00, 0xc8, 0x0a, 0x61,
0x05, 0x00, 0xf0, 0x09, 0xc7, 0x0d, 0x11, 0x21,
0x00, 0x00, 0xf2, 0x03, 0xe6, 0xf4, 0x11, 0x62,
0x03, 0x00, 0x0e, 0x6b, 0x8c, 0x00, 0x00, 0x00,
0x60, 0x0c, 0x00, 0x60, 0x0b, 0x00, 0x06, 0x11,
0xf2, 0xeb, 0x13, 0x6f, 0x41, 0x41, 0x00, 0x00,
0x00, 0xc2, 0x0b, 0x41, 0x6a, 0x00, 0x00, 0x00,
0xc2, 0x0c, 0x0e, 0xec, 0x10, 0x0e, 0x61, 0x0a,
0x00, 0x41, 0x6b, 0x00, 0x00, 0x00, 0x24, 0x00,
0x00, 0x8a, 0xec, 0xe0, 0x61, 0x0c, 0x00, 0xeb,
0x4e, 0x61, 0x06, 0x00, 0xea, 0x0a, 0x61, 0x0b,
0x00, 0x8a, 0x11, 0x62, 0x0b, 0x00, 0x0e, 0xd2,
0xea, 0x17, 0xd2, 0x41, 0xf2, 0x00, 0x00, 0x00,
0xd3, 0x61, 0x0b, 0x00, 0x61, 0x04, 0x00, 0x24,
0xf8, 0xf1, 0x13, 0x70, 0x41, 0x44, 0x00, 0x00,
0x00, 0xc8, 0x0b, 0x41, 0x71, 0x00, 0x00, 0x00,
0xc8, 0x0c, 0x0e, 0xf2, 0x10, 0x0e, 0x61, 0x0a,
0x00, 0x41, 0x72, 0x00, 0x00, 0x00, 0x24, 0x00,
0x00, 0x8a, 0xf2, 0xe0, 0x61, 0x0c, 0x00, 0xf1,
0x4e, 0x61, 0x06, 0x00, 0xf0, 0x0a, 0x61, 0x0b,
0x00, 0x8a, 0x11, 0x62, 0x0b, 0x00, 0x0e, 0xd8,
0xf0, 0x17, 0xd8, 0x41, 0xff, 0x00, 0x00, 0x00,
0xd9, 0x61, 0x0b, 0x00, 0x61, 0x04, 0x00, 0x24,
0x03, 0x00, 0x8a, 0x11, 0x62, 0x0b, 0x00, 0x0e,
0x5d, 0x04, 0x00, 0x61, 0x03, 0x00, 0x61, 0x04,
0x00, 0x90, 0x62, 0x04, 0x00, 0x0b, 0x61, 0x0b,
0x00, 0x4b, 0x41, 0x00, 0x00, 0x00, 0x0a, 0x4b,
0x3e, 0x00, 0x00, 0x00, 0x0a, 0x4b, 0x3f, 0x00,
0x00, 0x00, 0xf1, 0x0e, 0xec, 0x83, 0x0e, 0x06,
0x6c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0xec, 0x1e,
0x00, 0x4b, 0x44, 0x00, 0x00, 0x00, 0x0a, 0x4b,
0x41, 0x00, 0x00, 0x00, 0x0a, 0x4b, 0x42, 0x00,
0x00, 0x00, 0xf7, 0x0e, 0xf2, 0x83, 0x0e, 0x06,
0x6c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0xf2, 0x1e,
0x6c, 0x05, 0x00, 0x00, 0x00, 0x30, 0x61, 0x0a,
0x00, 0x40, 0x06, 0x00, 0x00, 0x00, 0xea, 0x0d,
0x00, 0x40, 0x06, 0x00, 0x00, 0x00, 0xf0, 0x0d,
0x61, 0x0a, 0x00, 0x41, 0x06, 0x00, 0x00, 0x00,
0x24, 0x00, 0x00, 0x0e, 0x6d, 0x61, 0x03, 0x00,
0x61, 0x04, 0x00, 0x42, 0x32, 0x00, 0x00, 0x00,
0x61, 0x03, 0x00, 0x2f, 0xbf, 0x00, 0x28, 0xbf,
0x00, 0xcd, 0x28,
0x61, 0x04, 0x00, 0x42, 0x33, 0x00, 0x00, 0x00,
0x61, 0x03, 0x00, 0x2f, 0xc5, 0x00, 0x28, 0xc5,
0x00, 0xd3, 0x28,
};

Loading
Loading