diff --git a/js/xpconnect/src/XPCJSID.cpp b/js/xpconnect/src/XPCJSID.cpp index ec367198762b..0defedc5ae27 100644 --- a/js/xpconnect/src/XPCJSID.cpp +++ b/js/xpconnect/src/XPCJSID.cpp @@ -10,6 +10,7 @@ #include "mozilla/dom/BindingUtils.h" #include "mozilla/Attributes.h" #include "JavaScriptParent.h" +#include "mozilla/StaticPtr.h" using namespace mozilla::dom; using namespace JS; @@ -223,14 +224,13 @@ NS_IMPL_RELEASE(SharedScriptableHelperForJSIID) nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE #include "xpc_map_end.h" /* This will #undef the above */ -static nsIXPCScriptable* gSharedScriptableHelperForJSIID; +static StaticRefPtr gSharedScriptableHelperForJSIID; static bool gClassObjectsWereInited = false; static void EnsureClassObjectsInitialized() { if (!gClassObjectsWereInited) { gSharedScriptableHelperForJSIID = new SharedScriptableHelperForJSIID(); - NS_ADDREF(gSharedScriptableHelperForJSIID); gClassObjectsWereInited = true; } @@ -241,8 +241,8 @@ NS_METHOD GetSharedScriptableHelperForJSIID(uint32_t language, { EnsureClassObjectsInitialized(); if (language == nsIProgrammingLanguage::JAVASCRIPT) { - NS_IF_ADDREF(gSharedScriptableHelperForJSIID); - *helper = gSharedScriptableHelperForJSIID; + nsCOMPtr temp = gSharedScriptableHelperForJSIID.get(); + temp.forget(helper); } else *helper = nullptr; return NS_OK; @@ -268,7 +268,7 @@ void xpc_DestroyJSxIDClassObjects() if (gClassObjectsWereInited) { NS_IF_RELEASE(NS_CLASSINFO_NAME(nsJSIID)); NS_IF_RELEASE(NS_CLASSINFO_NAME(nsJSCID)); - NS_IF_RELEASE(gSharedScriptableHelperForJSIID); + gSharedScriptableHelperForJSIID = nullptr; gClassObjectsWereInited = false; }