Bug 745661 - Make TI assertion handle safe mode, too. r=khuey

This commit is contained in:
Bobby Holley 2012-04-16 16:57:36 -07:00
Родитель af71c28b04
Коммит 26bad0fb53
1 изменённых файлов: 41 добавлений и 11 удалений

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

@ -45,7 +45,6 @@
#include "mozilla/Assertions.h"
#include "mozilla/Base64.h"
#include "mozilla/Util.h"
#include "mozilla/Preferences.h"
#include "xpcprivate.h"
#include "XPCWrapper.h"
@ -1194,6 +1193,46 @@ TraceXPCGlobal(JSTracer *trc, JSObject *obj)
scope->TraceDOMPrototypes(trc);
}
#ifdef DEBUG
#include "mozilla/Preferences.h"
#include "nsIXULRuntime.h"
static void
CheckTypeInference(JSContext *cx, JSClass *clasp, nsIPrincipal *principal)
{
// Check that the global class isn't whitelisted.
if (strcmp(clasp->name, "Sandbox") ||
strcmp(clasp->name, "nsXBLPrototypeScript compilation scope") ||
strcmp(clasp->name, "nsXULPrototypeScript compilation scope"))
return;
// Check that the pref is on.
if (!mozilla::Preferences::GetBool("javascript.options.typeinference"))
return;
// Check that we're not chrome.
bool isSystem;
nsIScriptSecurityManager* ssm;
ssm = XPCWrapper::GetSecurityManager();
if (NS_FAILED(ssm->IsSystemPrincipal(principal, &isSystem)) || !isSystem)
return;
// Check that safe mode isn't on.
bool safeMode;
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (!xr) {
NS_WARNING("Couldn't get XUL runtime!");
return;
}
if (NS_FAILED(xr->GetInSafeMode(&safeMode)) || safeMode)
return;
// Finally, do the damn assert.
MOZ_ASSERT(JS_GetOptions(cx) & JSOPTION_TYPE_INFERENCE);
}
#else
#define CheckTypeInference(cx, clasp, principal) {}
#endif
nsresult
xpc_CreateGlobalObject(JSContext *cx, JSClass *clasp,
nsIPrincipal *principal, nsISupports *ptr,
@ -1202,16 +1241,7 @@ xpc_CreateGlobalObject(JSContext *cx, JSClass *clasp,
{
// Make sure that Type Inference is enabled for everything non-chrome.
// Sandboxes and compilation scopes are exceptions. See bug 744034.
mozilla::DebugOnly<bool> isSystem;
mozilla::DebugOnly<nsIScriptSecurityManager*> ssm;
MOZ_ASSERT_IF(strcmp(clasp->name, "Sandbox") &&
strcmp(clasp->name, "nsXBLPrototypeScript compilation scope") &&
strcmp(clasp->name, "nsXULPrototypeScript compilation scope") &&
mozilla::Preferences::GetBool("javascript.options.typeinference") &&
(ssm = XPCWrapper::GetSecurityManager()) &&
NS_SUCCEEDED(ssm->IsSystemPrincipal(principal, &isSystem.value)) &&
!isSystem.value,
JS_GetOptions(cx) & JSOPTION_TYPE_INFERENCE);
CheckTypeInference(cx, clasp, principal);
NS_ABORT_IF_FALSE(NS_IsMainThread(), "using a principal off the main thread?");
NS_ABORT_IF_FALSE(principal, "bad key");