Bug 951991 - Implement GetEntryGlobal. r=smaug

This commit is contained in:
Bobby Holley
2014-08-19 12:02:05 -07:00
parent 41099b29ec
commit a3eec0372f
5 changed files with 66 additions and 29 deletions

View File

@@ -122,28 +122,12 @@ ScriptSettingsStackEntry::~ScriptSettingsStackEntry()
ScriptSettingsStack::Pop(this);
}
// This mostly gets the entry global, but doesn't entirely match the spec in
// certain edge cases. It's good enough for some purposes, but not others. If
// you want to call this function, ping bholley and describe your use-case.
nsIGlobalObject*
BrokenGetEntryGlobal()
GetEntryGlobal()
{
// We need the current JSContext in order to check the JS for
// scripted frames that may have appeared since anyone last
// manipulated the stack. If it's null, that means that there
// must be no entry global on the stack.
JSContext *cx = nsContentUtils::GetCurrentJSContextForThread();
if (!cx) {
MOZ_ASSERT(ScriptSettingsStack::EntryGlobal() == nullptr);
return nullptr;
}
return nsJSUtils::GetDynamicScriptGlobal(cx);
return ScriptSettingsStack::EntryGlobal();
}
// Note: When we're ready to expose it, GetEntryGlobal will look similar to
// GetIncumbentGlobal below.
nsIGlobalObject*
GetIncumbentGlobal()
{
@@ -171,6 +155,22 @@ GetIncumbentGlobal()
return ScriptSettingsStack::IncumbentGlobal();
}
nsIGlobalObject*
GetCurrentGlobal()
{
JSContext *cx = nsContentUtils::GetCurrentJSContextForThread();
if (!cx) {
return nullptr;
}
JSObject *global = JS::CurrentGlobalOrNull(cx);
if (!global) {
return nullptr;
}
return xpc::GetNativeForGlobal(global);
}
nsIPrincipal*
GetWebIDLCallerPrincipal()
{