Bug 884245 - Simplify nsContentUtils::GetDocumentFromCaller. r=bz

The first three lines of this function are an obvious bug. But the behavior in
general is also worrisome, because it's using antiquated XPConnect machinery
that will be less and less correct as we move to the new DOM bindings. Let's
just infer our global from the active compartment.
This commit is contained in:
Bobby Holley 2013-06-20 11:05:32 -07:00
Родитель e5be960066
Коммит 32f134148b
3 изменённых файлов: 3 добавлений и 24 удалений

Просмотреть файл

@ -1671,15 +1671,10 @@ nsContentUtils::GetWindowFromCaller()
nsIDocument* nsIDocument*
nsContentUtils::GetDocumentFromCaller() nsContentUtils::GetDocumentFromCaller()
{ {
JSContext *cx = nullptr; AutoJSContext cx;
JS::Rooted<JSObject*> obj(cx);
sXPConnect->GetCaller(&cx, obj.address());
NS_ASSERTION(cx && obj, "Caller ensures something is running");
JSAutoCompartment ac(cx, obj);
nsCOMPtr<nsPIDOMWindow> win = nsCOMPtr<nsPIDOMWindow> win =
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(obj)); do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(JS_GetGlobalForScopeChain(cx)));
if (!win) { if (!win) {
return nullptr; return nullptr;
} }

Просмотреть файл

@ -291,7 +291,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
%} %}
[uuid(4498aa26-62df-4a4f-8a45-7ddfd7f84834)] [uuid(dee6f80b-7ec5-4690-8622-a48af6a1ce52)]
interface nsIXPConnect : nsISupports interface nsIXPConnect : nsISupports
{ {
%{ C++ %{ C++
@ -609,12 +609,6 @@ interface nsIXPConnect : nsISupports
nsIXPConnectJSObjectHolder holdObject(in JSContextPtr aJSContext, nsIXPConnectJSObjectHolder holdObject(in JSContextPtr aJSContext,
in JSObjectPtr aObject); in JSObjectPtr aObject);
/**
* Return the caller object of the current call from JS.
*/
[noscript,notxpcom] void getCaller(out JSContextPtr aJSContext,
out JSObjectPtr aObject);
/** /**
* When we place the browser in JS debug mode, there can't be any * When we place the browser in JS debug mode, there can't be any
* JS on the stack. This is because we currently activate debugMode * JS on the stack. This is because we currently activate debugMode

Просмотреть файл

@ -1346,16 +1346,6 @@ nsXPConnect::HoldObject(JSContext *aJSContext, JSObject *aObjectArg,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP_(void)
nsXPConnect::GetCaller(JSContext **aJSContext, JSObject **aObj)
{
XPCCallContext *ccx = XPCJSRuntime::Get()->GetCallContext();
*aJSContext = ccx->GetJSContext();
// Set to the caller in XPC_WN_Helper_{Call,Construct}
*aObj = ccx->GetFlattenedJSObject();
}
namespace xpc { namespace xpc {
bool bool