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/bindings/ScriptExecutionContext.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/bun.js/bindings/ScriptExecutionContext.h') diff --git a/src/bun.js/bindings/ScriptExecutionContext.h b/src/bun.js/bindings/ScriptExecutionContext.h index ab86b6816..1643820dd 100644 --- a/src/bun.js/bindings/ScriptExecutionContext.h +++ b/src/bun.js/bindings/ScriptExecutionContext.h @@ -68,13 +68,17 @@ protected: bool m_isCleanupTask; }; +using ScriptExecutionContextIdentifier = uint32_t; + class ScriptExecutionContext : public CanMakeWeakPtr { -public: + public: ScriptExecutionContext(JSC::VM* vm, JSC::JSGlobalObject* globalObject) : m_vm(vm) , m_globalObject(globalObject) + , m_identifier(0) { + regenerateIdentifier(); } JSC::JSGlobalObject* jsGlobalObject() @@ -106,12 +110,23 @@ public: // { // } + static bool postTaskTo(ScriptExecutionContextIdentifier identifier, Function&& task); + + void regenerateIdentifier(); + void addToContextsMap(); + void removeFromContextsMap(); + + void postTaskConcurrently(Function&& lambda) + { + auto* task = new EventLoopTask(WTFMove(lambda)); + reinterpret_cast(m_globalObject)->queueTaskConcurrently(task); + } // Executes the task on context's thread asynchronously. + void postTask(Function&& lambda) { auto* task = new EventLoopTask(WTFMove(lambda)); reinterpret_cast(m_globalObject)->queueTask(task); } // Executes the task on context's thread asynchronously. - void postTask(EventLoopTask* task) { reinterpret_cast(m_globalObject)->queueTask(task); @@ -126,11 +141,13 @@ public: } JSC::VM& vm() { return *m_vm; } + ScriptExecutionContextIdentifier identifier() const { return m_identifier; } private: JSC::VM* m_vm = nullptr; JSC::JSGlobalObject* m_globalObject = nullptr; WTF::URL m_url = WTF::URL(); + ScriptExecutionContextIdentifier m_identifier; us_socket_context_t* webSocketContextSSL(); us_socket_context_t* webSocketContextNoSSL(); -- cgit v1.2.3