Bug 1428072 - 1/3 - Change the implementation of isChromeJSScript so that it doesn't crash for workers r=bz,sfink draft
authorJulien Wajsberg <felash@gmail.com>
Thu, 18 Jan 2018 17:14:09 +0100
changeset 752022 5a509fbb25f199ad0dfad9afd44e618f40041467
parent 752021 4fe6f6560083f8c8257282bef1d4e0ced9d1b975
child 752023 a3f41959123bd0fb0655c65d7cdc9a56f5f748b0
push id98134
push userbmo:felash@gmail.com
push dateWed, 07 Feb 2018 12:23:55 +0000
reviewersbz, sfink
bugs1428072
milestone60.0a1
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
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
tools/profiler/core/ProfileBuffer.cpp
--- 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));
 }