aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-14 19:55:48 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-14 19:55:48 -0800
commit9c3b2f7ad6549f1c86832bb9027278fcce9b80b5 (patch)
tree4327980446f0fec4a2e15f77ceeedb7cac728e5f
parent436b8e14611e346fdb2c581a7c137f1dde10f1b0 (diff)
downloadbun-9c3b2f7ad6549f1c86832bb9027278fcce9b80b5.tar.gz
bun-9c3b2f7ad6549f1c86832bb9027278fcce9b80b5.tar.zst
bun-9c3b2f7ad6549f1c86832bb9027278fcce9b80b5.zip
Fix crash in web crypto. caused by refptr
Diffstat (limited to '')
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp9
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.h7
-rw-r--r--src/bun.js/bindings/webcrypto/SubtleCrypto.h1
3 files changed, 15 insertions, 2 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index 052295bd2..abf1ecb72 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -435,6 +435,9 @@ GlobalObject::GlobalObject(JSC::VM& vm, JSC::Structure* structure)
GlobalObject::~GlobalObject()
{
+ if (crypto) {
+ delete crypto;
+ }
scriptExecutionContext()->removeFromContextsMap();
}
@@ -2374,10 +2377,12 @@ void GlobalObject::finishCreation(VM& vm)
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());
+ if (global.crypto == nullptr) {
+ global.crypto = WebCore::SubtleCrypto::createPtr(global.scriptExecutionContext());
+ }
init.set(
- toJSNewlyCreated<IDLInterface<SubtleCrypto>>(*init.owner, global, WTFMove(crypto)).getObject());
+ toJS<IDLInterface<SubtleCrypto>>(*init.owner, global, global.crypto).getObject());
});
m_primordialsObject.initLater(
diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h
index 9c37eb145..142065e35 100644
--- a/src/bun.js/bindings/ZigGlobalObject.h
+++ b/src/bun.js/bindings/ZigGlobalObject.h
@@ -38,6 +38,10 @@ class EventLoopTask;
#include "CallSite.h"
#include "CallSitePrototype.h"
+namespace WebCore {
+class SubtleCrypto;
+}
+
extern "C" void Bun__reportError(JSC__JSGlobalObject*, JSC__JSValue);
// defined in ModuleLoader.cpp
extern "C" JSC::EncodedJSValue jsFunctionOnLoadObjectResultResolve(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame);
@@ -488,6 +492,9 @@ private:
DOMGuardedObjectSet m_guardedObjects WTF_GUARDED_BY_LOCK(m_gcLock);
void* m_bunVM;
+
+ WebCore::SubtleCrypto* crypto = nullptr;
+
WTF::Vector<JSC::Strong<JSC::JSPromise>> m_aboutToBeNotifiedRejectedPromises;
WTF::Vector<JSC::Strong<JSC::JSFunction>> m_ffiFunctions;
};
diff --git a/src/bun.js/bindings/webcrypto/SubtleCrypto.h b/src/bun.js/bindings/webcrypto/SubtleCrypto.h
index 5ee622250..e9ef23e6a 100644
--- a/src/bun.js/bindings/webcrypto/SubtleCrypto.h
+++ b/src/bun.js/bindings/webcrypto/SubtleCrypto.h
@@ -56,6 +56,7 @@ enum class CryptoKeyUsage;
class SubtleCrypto : public ContextDestructionObserver, public RefCounted<SubtleCrypto>, public CanMakeWeakPtr<SubtleCrypto> {
public:
static Ref<SubtleCrypto> create(ScriptExecutionContext* context) { return adoptRef(*new SubtleCrypto(context)); }
+ static SubtleCrypto* createPtr(ScriptExecutionContext* context) { return new SubtleCrypto(context); }
~SubtleCrypto();
using KeyFormat = CryptoKeyFormat;