diff --git a/dom/workers/DataStore.cpp b/dom/workers/DataStore.cpp index 7a4f162da92a..7489683d2e26 100644 --- a/dom/workers/DataStore.cpp +++ b/dom/workers/DataStore.cpp @@ -285,16 +285,13 @@ protected: { AssertIsOnMainThread(); - // Get the JSContext for the target window - nsCOMPtr sgo = - do_QueryInterface(static_cast - (mBackingStore.get())->GetOwner()); - MOZ_ASSERT(sgo); - - nsCOMPtr scriptContext = sgo->GetContext(); - AutoPushJSContext cx(scriptContext ? scriptContext->GetNativeContext() - : nsContentUtils::GetSafeJSContext()); - MOZ_ASSERT(cx); + // Initialise an AutoJSAPI with the target window. + AutoJSAPI jsapi; + if (NS_WARN_IF(!jsapi.Init(mBackingStore->GetParentObject()))) { + mRv.Throw(NS_ERROR_UNEXPECTED); + return true; + } + JSContext* cx = jsapi.cx(); JS::Rooted value(cx); if (!mObjBuffer.read(cx, &value)) {