From 76652ac3cad64dbc2fd54e976ce4bad0a37caa03 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 23 Oct 2022 20:25:18 -0700 Subject: Add Web Crypto API (#1384) * Add Web Crypto API * Duplicate symbols * Update c_cpp_properties.json Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- src/bun.js/javascript.zig | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/bun.js/javascript.zig') diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 07c5318b2..9ba69aaa2 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -273,7 +273,8 @@ comptime { _ = Bun__getDefaultGlobal; _ = Bun__getVM; _ = Bun__drainMicrotasks; - _ = Bun__queueMicrotask; + _ = Bun__queueTask; + _ = Bun__queueTaskConcurrently; _ = Bun__handleRejectedPromise; _ = Bun__readOriginTimer; _ = Bun__onDidAppendPlugin; @@ -281,10 +282,24 @@ comptime { } } -pub export fn Bun__queueMicrotask(global: *JSGlobalObject, task: *JSC.CppTask) void { +/// This function is called on the main thread +/// The bunVM() call will assert this +pub export fn Bun__queueTask(global: *JSGlobalObject, task: *JSC.CppTask) void { global.bunVM().eventLoop().enqueueTask(Task.init(task)); } +/// This function is called on another thread +/// The main difference: we need to allocate the task & wakeup the thread +/// We can avoid that if we run it from the main thread. +pub export fn Bun__queueTaskConcurrently(global: *JSGlobalObject, task: *JSC.CppTask) void { + var concurrent = bun.default_allocator.create(JSC.ConcurrentTask) catch unreachable; + concurrent.* = JSC.ConcurrentTask{ + .task = Task.init(task), + .auto_delete = true, + }; + global.bunVMConcurrently().eventLoop().enqueueTaskConcurrent(concurrent); +} + pub export fn Bun__handleRejectedPromise(global: *JSGlobalObject, promise: *JSC.JSPromise) void { const result = promise.result(global.vm()); global.bunVM().runErrorHandler(result, null); -- cgit v1.2.3