Bug 1428072 - 1/3 - Change the implementation of isChromeJSScript so that it doesn't crash for workers r=bz,sfink
In this patch we also expose a script's compartment in jsfriendapi.h
MozReview-Commit-ID: LgoN8ANLgxI
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -193,16 +193,22 @@ JS_SetCompartmentPrincipals(JSCompartmen
}
JS_FRIEND_API(JSPrincipals*)
JS_GetScriptPrincipals(JSScript* script)
{
return script->principals();
}
+JS_FRIEND_API(JSCompartment*)
+js::GetScriptCompartment(JSScript* script)
+{
+ return script->compartment();
+}
+
JS_FRIEND_API(bool)
JS_ScriptHasMutedErrors(JSScript* script)
{
return script->mutedErrors();
}
JS_FRIEND_API(bool)
JS_WrapPropertyDescriptor(JSContext* cx, JS::MutableHandle<js::PropertyDescriptor> desc)
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -189,16 +189,21 @@ extern JS_FRIEND_API(JSPrincipals*)
JS_GetCompartmentPrincipals(JSCompartment* compartment);
extern JS_FRIEND_API(void)
JS_SetCompartmentPrincipals(JSCompartment* compartment, JSPrincipals* principals);
extern JS_FRIEND_API(JSPrincipals*)
JS_GetScriptPrincipals(JSScript* script);
+namespace js {
+extern JS_FRIEND_API(JSCompartment*)
+GetScriptCompartment(JSScript* script);
+} /* namespace js */
+
extern JS_FRIEND_API(bool)
JS_ScriptHasMutedErrors(JSScript* script);
extern JS_FRIEND_API(JSObject*)
JS_CloneObject(JSContext* cx, JS::HandleObject obj, JS::HandleObject proto);
/**
* Copy the own properties of src to dst in a fast way. src and dst must both
--- a/tools/profiler/core/ProfileBuffer.cpp
+++ b/tools/profiler/core/ProfileBuffer.cpp
@@ -136,23 +136,18 @@ ProfileBuffer::SizeOfIncludingThis(mozil
}
/* ProfileBufferCollector */
static bool
IsChromeJSScript(JSScript* aScript)
{
// WARNING: this function runs within the profiler's "critical section".
-
- nsIScriptSecurityManager* const secman =
- nsScriptSecurityManager::GetScriptSecurityManager();
- NS_ENSURE_TRUE(secman, false);
-
- JSPrincipals* const principals = JS_GetScriptPrincipals(aScript);
- return secman->IsSystemPrincipal(nsJSPrincipals::get(principals));
+ auto compartment = js::GetScriptCompartment(aScript);
+ return js::IsSystemCompartment(compartment);
}
void
ProfileBufferCollector::CollectNativeLeafAddr(void* aAddr)
{
mBuf.AddEntry(ProfileBufferEntry::NativeLeafAddr(aAddr));
}