Bug 745661 - Make TI assertion handle safe mode, too. r=khuey
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -40,17 +40,16 @@
*
* ***** END LICENSE BLOCK ***** */
/* High level class and public functions implementation. */
#include "mozilla/Assertions.h"
#include "mozilla/Base64.h"
#include "mozilla/Util.h"
-#include "mozilla/Preferences.h"
#include "xpcprivate.h"
#include "XPCWrapper.h"
#include "nsBaseHashtable.h"
#include "nsHashKeys.h"
#include "jsatom.h"
#include "jsfriendapi.h"
#include "jsgc.h"
@@ -1189,34 +1188,65 @@ TraceXPCGlobal(JSTracer *trc, JSObject *
return;
}
#endif
if (XPCWrappedNativeScope *scope = XPCWrappedNativeScope::GetNativeScope(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,
bool wantXrays, JSObject **global,
JSCompartment **compartment)
{
// 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");
XPCCompartmentMap& map = nsXPConnect::GetRuntimeInstance()->GetCompartmentMap();
xpc::PtrAndPrincipalHashKey key(ptr, principal);
if (!map.Get(&key, compartment)) {
xpc::PtrAndPrincipalHashKey *priv_key =