From 27314790c8d238bcf887126431baf171c2b5ac3a Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 27 May 2016 13:30:10 -0400 Subject: [PATCH] Bug 1276286. Remove the unused JSContext stuff in nsJSObjWrapper::GetNewOrUsed. r=mccr8 --- dom/plugins/base/nsJSNPRuntime.cpp | 26 ++------------------------ dom/plugins/base/nsJSNPRuntime.h | 3 +-- dom/plugins/base/nsNPAPIPlugin.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/dom/plugins/base/nsJSNPRuntime.cpp b/dom/plugins/base/nsJSNPRuntime.cpp index 0c594148ccf8..44b0cc35117b 100644 --- a/dom/plugins/base/nsJSNPRuntime.cpp +++ b/dom/plugins/base/nsJSNPRuntime.cpp @@ -472,18 +472,6 @@ GetGlobalObject(NPP npp) return doc->GetScopeObject(); } -JSContext * -GetJSContext(NPP npp) -{ - nsCOMPtr sgo = do_QueryInterface(GetGlobalObject(npp)); - NS_ENSURE_TRUE(sgo, nullptr); - - nsIScriptContext *scx = sgo->GetContext(); - NS_ENSURE_TRUE(scx, nullptr); - - return scx->GetNativeContext(); -} - } // namespace parent } // namespace plugins } // namespace mozilla @@ -610,7 +598,7 @@ JSValToNPVariant(NPP npp, JSContext *cx, JS::Value val, NPVariant *variant) obj = val.toObjectOrNull(); } - NPObject *npobj = nsJSObjWrapper::GetNewOrUsed(npp, cx, obj); + NPObject* npobj = nsJSObjWrapper::GetNewOrUsed(npp, obj); if (!npobj) { return false; } @@ -1103,7 +1091,7 @@ nsJSObjWrapper::NP_Construct(NPObject *npobj, const NPVariant *args, // static NPObject * -nsJSObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, JS::Handle obj) +nsJSObjWrapper::GetNewOrUsed(NPP npp, JS::Handle obj) { if (!npp) { NS_ERROR("Null NPP passed to nsJSObjWrapper::GetNewOrUsed()!"); @@ -1122,16 +1110,6 @@ nsJSObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, JS::Handle obj) } } - if (!cx) { - cx = GetJSContext(npp); - - if (!cx) { - NS_ERROR("Unable to find a JSContext in nsJSObjWrapper::GetNewOrUsed()!"); - - return nullptr; - } - } - // No need to enter the right compartment here as we only get the // class and private from the JSObject, neither of which cares about // compartments. diff --git a/dom/plugins/base/nsJSNPRuntime.h b/dom/plugins/base/nsJSNPRuntime.h index a745e8ff8f77..355d6e23af34 100644 --- a/dom/plugins/base/nsJSNPRuntime.h +++ b/dom/plugins/base/nsJSNPRuntime.h @@ -58,8 +58,7 @@ public: const NPP mNpp; bool mDestroyPending; - static NPObject *GetNewOrUsed(NPP npp, JSContext *cx, - JS::Handle obj); + static NPObject* GetNewOrUsed(NPP npp, JS::Handle obj); static bool HasOwnProperty(NPObject* npobj, NPIdentifier npid); void trace(JSTracer* trc) { diff --git a/dom/plugins/base/nsNPAPIPlugin.cpp b/dom/plugins/base/nsNPAPIPlugin.cpp index edcc007d7c74..4198c6b77dd4 100644 --- a/dom/plugins/base/nsNPAPIPlugin.cpp +++ b/dom/plugins/base/nsNPAPIPlugin.cpp @@ -1062,9 +1062,9 @@ _getwindowobject(NPP npp) nsCOMPtr outer = doc->GetWindow(); NS_ENSURE_TRUE(outer, nullptr); - AutoJSContext cx; - JS::Rooted global(cx, nsGlobalWindow::Cast(outer)->GetGlobalJSObject()); - return nsJSObjWrapper::GetNewOrUsed(npp, cx, global); + JS::Rooted global(nsContentUtils::RootingCx(), + nsGlobalWindow::Cast(outer)->GetGlobalJSObject()); + return nsJSObjWrapper::GetNewOrUsed(npp, global); } NPObject* @@ -1104,7 +1104,7 @@ _getpluginelement(NPP npp) NS_GET_IID(nsIDOMElement), obj.address()); NS_ENSURE_TRUE(obj, nullptr); - return nsJSObjWrapper::GetNewOrUsed(npp, cx, obj); + return nsJSObjWrapper::GetNewOrUsed(npp, obj); } NPIdentifier