diff --git a/src/js_realm.hpp b/src/js_realm.hpp index f6cdc13f..b3cb1351 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -63,7 +63,10 @@ class RealmDelegate : public BindingContext { RealmDelegate(std::weak_ptr realm, GlobalContextType ctx) : m_context(ctx), m_realm(realm) {} ~RealmDelegate() { - remove_all_notifications(); + // All protected values need to be unprotected while the context is retained. + m_defaults.clear(); + m_constructors.clear(); + m_notifications.clear(); } void add_notification(FunctionType notification) { diff --git a/src/jsc/jsc_protected.hpp b/src/jsc/jsc_protected.hpp index a330ba3a..39a8e198 100644 --- a/src/jsc/jsc_protected.hpp +++ b/src/jsc/jsc_protected.hpp @@ -32,7 +32,7 @@ class Protected { Protected(Protected &&other) : m_context(other.m_context) { other.m_context = nullptr; } - Protected(JSGlobalContextRef ctx) : m_context(ctx) { + explicit Protected(JSGlobalContextRef ctx) : m_context(ctx) { JSGlobalContextRetain(m_context); } ~Protected() {