Bug 790905 - Replace no-op principal check with something real. r=luke
authorBobby Holley <bobbyholley@gmail.com>
Wed, 19 Sep 2012 11:15:24 +0200
changeset 107465 acec40170961cea7d91c3f58fab338e6f01e1939
parent 107464 ef528ae38f048cb638a6f8c51eb9b795e11b588c
child 107466 2f54fc19d5a393b764ef7d4da1773574ad5ce365
child 107482 0c8ac138706ebf11ed4dcce231f45a5942efc567
push id15053
push userbobbyholley@gmail.com
push dateWed, 19 Sep 2012 09:16:00 +0000
treeherdermozilla-inbound@acec40170961 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs790905
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 790905 - Replace no-op principal check with something real. r=luke This would have caught this bug.
js/src/jsapi-tests/testXDR.cpp
js/src/jsapi.cpp
js/src/jscntxtinlines.h
--- a/js/src/jsapi-tests/testXDR.cpp
+++ b/js/src/jsapi-tests/testXDR.cpp
@@ -4,16 +4,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 #include "tests.h"
 #include "jsscript.h"
 #include "jsstr.h"
+#include "jsfriendapi.h"
 
 static JSScript *
 CompileScriptForPrincipalsVersionOrigin(JSContext *cx, JS::HandleObject obj,
                                         JSPrincipals *principals, JSPrincipals *originPrincipals,
                                         const char *bytes, size_t nbytes,
                                         const char *filename, unsigned lineno,
                                         JSVersion version)
 {
@@ -73,27 +74,32 @@ FreezeThaw(JSContext *cx, JS::HandleObje
 static JSPrincipals testPrincipals[] = {
     { 1 },
     { 1 },
 };
 
 BEGIN_TEST(testXDR_principals)
 {
     JSScript *script;
+    JSCompartment *compartment = js::GetContextCompartment(cx);
     for (int i = TEST_FIRST; i != TEST_END; ++i) {
         script = createScriptViaXDR(NULL, NULL, i);
         CHECK(script);
         CHECK(!JS_GetScriptPrincipals(script));
         CHECK(!JS_GetScriptOriginPrincipals(script));
 
         script = createScriptViaXDR(NULL, NULL, i);
         CHECK(script);
         CHECK(!JS_GetScriptPrincipals(script));
         CHECK(!JS_GetScriptOriginPrincipals(script));
 
+        // Appease the new JSAPI assertions. The stuff being tested here is
+        // going away anyway.
+        JSPrincipals *old = JS_GetCompartmentPrincipals(compartment);
+        JS_SetCompartmentPrincipals(compartment, &testPrincipals[0]);
         script = createScriptViaXDR(&testPrincipals[0], NULL, i);
         CHECK(script);
         CHECK(JS_GetScriptPrincipals(script) == &testPrincipals[0]);
         CHECK(JS_GetScriptOriginPrincipals(script) == &testPrincipals[0]);
 
         script = createScriptViaXDR(&testPrincipals[0], &testPrincipals[0], i);
         CHECK(script);
         CHECK(JS_GetScriptPrincipals(script) == &testPrincipals[0]);
@@ -103,16 +109,17 @@ BEGIN_TEST(testXDR_principals)
         CHECK(script);
         CHECK(JS_GetScriptPrincipals(script) == &testPrincipals[0]);
         CHECK(JS_GetScriptOriginPrincipals(script) == &testPrincipals[1]);
 
         script = createScriptViaXDR(NULL, &testPrincipals[1], i);
         CHECK(script);
         CHECK(!JS_GetScriptPrincipals(script));
         CHECK(JS_GetScriptOriginPrincipals(script) == &testPrincipals[1]);
+        JS_SetCompartmentPrincipals(compartment, old);
     }
 
     return true;
 }
 
 enum TestCase {
     TEST_FIRST,
     TEST_SCRIPT = TEST_FIRST,
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -5168,17 +5168,18 @@ JS::Compile(JSContext *cx, HandleObject 
         mava.construct(cx, options.version);
         // AutoVersionAPI propagates some compilation flags through.
         options.version = mava.ref().version();
     }
 
     JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
-    assertSameCompartment(cx, obj, options.principals, options.originPrincipals);
+    assertSameCompartment(cx, obj);
+    JS_ASSERT_IF(options.principals, cx->compartment->principals == options.principals);
     AutoLastFrameCheck lfc(cx);
 
     return frontend::CompileScript(cx, obj, NULL, options, chars, length);
 }
 
 JSScript *
 JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
             const char *bytes, size_t length)
@@ -5431,17 +5432,18 @@ JS::CompileFunction(JSContext *cx, Handl
         mava.construct(cx, options.version);
         // AutoVersionAPI propagates some compilation flags through.
         options.version = mava.ref().version();
     }
 
     JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
-    assertSameCompartment(cx, obj, options.principals, options.originPrincipals);
+    assertSameCompartment(cx, obj);
+    JS_ASSERT_IF(options.principals, cx->compartment->principals == options.principals);
     AutoLastFrameCheck lfc(cx);
 
     RootedAtom funAtom(cx);
     if (name) {
         funAtom = Atomize(cx, name, strlen(name));
         if (!funAtom)
             return NULL;
     }
@@ -5648,17 +5650,19 @@ JS::Evaluate(JSContext *cx, HandleObject
         mava.construct(cx, options.version);
         // AutoVersionAPI propagates some compilation flags through.
         options.version = mava.ref().version();
     }
 
     JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
-    assertSameCompartment(cx, obj, options.principals, options.originPrincipals);
+    assertSameCompartment(cx, obj);
+    JS_ASSERT_IF(options.principals, cx->compartment->principals == options.principals);
+
     AutoLastFrameCheck lfc(cx);
 
     options.setCompileAndGo(true);
     options.setNoScriptRval(!rval);
     RootedScript script(cx, frontend::CompileScript(cx, obj, NULL, options, chars, length));
     if (!script)
         return false;
 
--- a/js/src/jscntxtinlines.h
+++ b/js/src/jscntxtinlines.h
@@ -222,18 +222,16 @@ class CompartmentChecker
         if (c && c != context->runtime->atomsCompartment) {
             if (!compartment)
                 compartment = c;
             else if (c != compartment)
                 fail(compartment, c);
         }
     }
 
-    void check(JSPrincipals *) { /* nothing for now */ }
-
     void check(JSObject *obj) {
         if (obj)
             check(obj->compartment());
     }
 
     template<typename T>
     void check(Handle<T> handle) {
         check(handle.get());