diff options
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 78 |
1 files changed, 74 insertions, 4 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index c91a232e6..71113e9a6 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -163,6 +163,9 @@ using JSBuffer = WebCore::JSBuffer; #include "DOMJITHelpers.h" #include <JavaScriptCore/DFGAbstractHeap.h> +#include "JSCryptoKey.h" +#include "JSSubtleCrypto.h" + #include "OnigurumaRegExp.h" #ifdef __APPLE__ @@ -427,7 +430,10 @@ GlobalObject::GlobalObject(JSC::VM& vm, JSC::Structure* structure) m_scriptExecutionContext = new WebCore::ScriptExecutionContext(&vm, this); } -GlobalObject::~GlobalObject() = default; +GlobalObject::~GlobalObject() +{ + scriptExecutionContext()->removeFromContextsMap(); +} void GlobalObject::destroy(JSCell* cell) { @@ -1264,6 +1270,40 @@ JSC_DEFINE_CUSTOM_GETTER(jsServiceWorkerGlobalScope_WritableStreamDefaultWriterC return IDLAttribute<Zig::GlobalObject>::get<jsServiceWorkerGlobalScope_WritableStreamDefaultWriterConstructorGetter>(*lexicalGlobalObject, thisValue, attributeName); } +static inline JSValue getterSubtleCryptoBodyConstructor(JSGlobalObject& lexicalGlobalObject, Zig::GlobalObject& thisObject) +{ + UNUSED_PARAM(lexicalGlobalObject); + return JSSubtleCrypto::getConstructor(JSC::getVM(&lexicalGlobalObject), &thisObject); +} + +JSC_DEFINE_CUSTOM_GETTER(getterSubtleCryptoConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute<Zig::GlobalObject>::get<getterSubtleCryptoBodyConstructor>(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline JSValue getterCryptoKeyBodyConstructor(JSGlobalObject& lexicalGlobalObject, Zig::GlobalObject& thisObject) +{ + UNUSED_PARAM(lexicalGlobalObject); + return JSCryptoKey::getConstructor(JSC::getVM(&lexicalGlobalObject), &thisObject); +} + +JSC_DEFINE_CUSTOM_GETTER(getterCryptoKeyConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return IDLAttribute<Zig::GlobalObject>::get<getterCryptoKeyBodyConstructor>(*lexicalGlobalObject, thisValue, attributeName); +} + +static inline JSValue getterSubtleCryptoBody(JSGlobalObject& lexicalGlobalObject, Zig::GlobalObject& thisObject) +{ + UNUSED_PARAM(lexicalGlobalObject); + return thisObject.subtleCrypto(); +} + +JSC_DEFINE_CUSTOM_GETTER(getterSubtleCrypto, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + return JSValue::encode( + getterSubtleCryptoBody(*lexicalGlobalObject, *reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject))); +} + JSC_DECLARE_HOST_FUNCTION(makeThisTypeErrorForBuiltins); JSC_DECLARE_HOST_FUNCTION(makeGetterTypeErrorForBuiltins); JSC_DECLARE_HOST_FUNCTION(makeDOMExceptionForBuiltins); @@ -1951,6 +1991,15 @@ void GlobalObject::finishCreation(VM& vm) this->initGeneratedLazyClasses(); + m_subtleCryptoObject.initLater( + [](const JSC::LazyProperty<JSC::JSGlobalObject, JSC::JSObject>::Initializer& init) { + auto& global = *reinterpret_cast<Zig::GlobalObject*>(init.owner); + RefPtr<WebCore::SubtleCrypto> crypto = WebCore::SubtleCrypto::create(global.scriptExecutionContext()); + + init.set( + toJSNewlyCreated<IDLInterface<SubtleCrypto>>(*init.owner, global, WTFMove(crypto)).getObject()); + }); + m_NapiClassStructure.initLater( [](LazyClassStructure::Initializer& init) { init.setStructure(Zig::NapiClass::createStructure(init.vm, init.global, init.global->functionPrototype())); @@ -2218,7 +2267,7 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) auto& builtinNames = WebCore::builtinNames(vm); WTF::Vector<GlobalPropertyInfo> extraStaticGlobals; - extraStaticGlobals.reserveCapacity(40); + extraStaticGlobals.reserveCapacity(42); JSC::Identifier queueMicrotaskIdentifier = JSC::Identifier::fromString(vm, "queueMicrotask"_s); extraStaticGlobals.uncheckedAppend( @@ -2272,6 +2321,18 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) "atob"_s, functionATOB, ImplementationVisibility::Public), JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0 }); + JSC::Identifier SubtleCryptoIdentifier = JSC::Identifier::fromString(vm, "SubtleCrypto"_s); + extraStaticGlobals.uncheckedAppend( + GlobalPropertyInfo { SubtleCryptoIdentifier, + JSC::CustomGetterSetter::create(vm, getterSubtleCryptoConstructor, nullptr), + JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0 }); + + JSC::Identifier CryptoKeyIdentifier = JSC::Identifier::fromString(vm, "CryptoKey"_s); + extraStaticGlobals.uncheckedAppend( + GlobalPropertyInfo { CryptoKeyIdentifier, + JSC::CustomGetterSetter::create(vm, getterCryptoKeyConstructor, nullptr), + JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0 }); + JSC::Identifier btoaIdentifier = JSC::Identifier::fromString(vm, "btoa"_s); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { btoaIdentifier, @@ -2598,6 +2659,8 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm Crypto__getRandomValues__put(this, JSValue::encode(object)); Crypto__randomUUID__put(this, JSValue::encode(object)); + object->putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "subtle"_s), JSC::CustomGetterSetter::create(vm, getterSubtleCrypto, nullptr), + JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { JSC::Identifier::fromString(vm, jsClass->className()), JSC::JSValue(object), JSC::PropertyAttribute::DontDelete | 0 }); @@ -2688,6 +2751,7 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) thisObject->m_processObject.visit(visitor); thisObject->m_performanceObject.visit(visitor); thisObject->m_navigatorObject.visit(visitor); + thisObject->m_subtleCryptoObject.visit(visitor); thisObject->m_JSHTTPResponseSinkClassStructure.visit(visitor); thisObject->m_JSHTTPSResponseSinkClassStructure.visit(visitor); @@ -2719,7 +2783,8 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) visitor.addOpaqueRoot(context); } -extern "C" void Bun__queueMicrotask(JSC__JSGlobalObject*, WebCore::EventLoopTask* task); +extern "C" void Bun__queueTask(JSC__JSGlobalObject*, WebCore::EventLoopTask* task); +extern "C" void Bun__queueTaskConcurrently(JSC__JSGlobalObject*, WebCore::EventLoopTask* task); extern "C" void Bun__performTask(Zig::GlobalObject* globalObject, WebCore::EventLoopTask* task) { task->performTask(*globalObject->scriptExecutionContext()); @@ -2727,7 +2792,12 @@ extern "C" void Bun__performTask(Zig::GlobalObject* globalObject, WebCore::Event void GlobalObject::queueTask(WebCore::EventLoopTask* task) { - Bun__queueMicrotask(this, task); + Bun__queueTask(this, task); +} + +void GlobalObject::queueTaskConcurrently(WebCore::EventLoopTask* task) +{ + Bun__queueTaskConcurrently(this, task); } extern "C" void Bun__handleRejectedPromise(Zig::GlobalObject* JSGlobalObject, JSC::JSPromise* promise); |