Bug 1037564 Part 1: Replace AutoPushJSContext in nsBindingManager::GetBindingImplementation. r=bholley

This commit is contained in:
Bob Owen 2014-07-14 18:49:18 +01:00
parent c7050c0475
commit 5a72aa1711

View File

@ -46,10 +46,10 @@
#include "nsIScriptContext.h"
#include "xpcpublic.h"
#include "jswrapper.h"
#include "nsCxPusher.h"
#include "nsThreadUtils.h"
#include "mozilla/dom/NodeListBinding.h"
#include "mozilla/dom/ScriptSettings.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -638,21 +638,9 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
// We have never made a wrapper for this implementation.
// Create an XPC wrapper for the script object and hand it back.
nsIDocument* doc = aContent->OwnerDoc();
nsCOMPtr<nsIScriptGlobalObject> global =
do_QueryInterface(doc->GetWindow());
if (!global)
return NS_NOINTERFACE;
nsIScriptContext *context = global->GetContext();
if (!context)
return NS_NOINTERFACE;
AutoPushJSContext cx(context->GetNativeContext());
if (!cx)
return NS_NOINTERFACE;
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
nsIXPConnect *xpConnect = nsContentUtils::XPConnect();
@ -666,8 +654,7 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
// because they're chrome-only and no Xrays are involved.
//
// If there's no separate XBL scope, or if the reflector itself lives in
// the XBL scope, we'll end up with the global of the reflector, and this
// will all be a no-op.
// the XBL scope, we'll end up with the global of the reflector.
JS::Rooted<JSObject*> xblScope(cx, xpc::GetXBLScopeOrGlobal(cx, jsobj));
JSAutoCompartment ac(cx, xblScope);
bool ok = JS_WrapObject(cx, &jsobj);