aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ScriptExecutionContext.h
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-10-23 20:25:18 -0700
committerGravatar GitHub <noreply@github.com> 2022-10-23 20:25:18 -0700
commit76652ac3cad64dbc2fd54e976ce4bad0a37caa03 (patch)
tree179865bc417dc6bf2f224dd310b77b931ee45c73 /src/bun.js/bindings/ScriptExecutionContext.h
parent14cec299f5170b8ed35eed28e53b88724b8cc04f (diff)
downloadbun-76652ac3cad64dbc2fd54e976ce4bad0a37caa03.tar.gz
bun-76652ac3cad64dbc2fd54e976ce4bad0a37caa03.tar.zst
bun-76652ac3cad64dbc2fd54e976ce4bad0a37caa03.zip
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>
Diffstat (limited to 'src/bun.js/bindings/ScriptExecutionContext.h')
-rw-r--r--src/bun.js/bindings/ScriptExecutionContext.h21
1 files changed, 19 insertions, 2 deletions
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<ScriptExecutionContext> {
-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<void(ScriptExecutionContext&)>&& task);
+
+ void regenerateIdentifier();
+ void addToContextsMap();
+ void removeFromContextsMap();
+
+ void postTaskConcurrently(Function<void(ScriptExecutionContext&)>&& lambda)
+ {
+ auto* task = new EventLoopTask(WTFMove(lambda));
+ reinterpret_cast<Zig::GlobalObject*>(m_globalObject)->queueTaskConcurrently(task);
+ } // Executes the task on context's thread asynchronously.
+
void postTask(Function<void(ScriptExecutionContext&)>&& lambda)
{
auto* task = new EventLoopTask(WTFMove(lambda));
reinterpret_cast<Zig::GlobalObject*>(m_globalObject)->queueTask(task);
} // Executes the task on context's thread asynchronously.
-
void postTask(EventLoopTask* task)
{
reinterpret_cast<Zig::GlobalObject*>(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();