Bug 790905 - Replace no-op principal check with something real. r=luke

This would have caught this bug.
This commit is contained in:
Bobby Holley 2012-09-19 11:15:24 +02:00
parent 501866d7d9
commit 9307d49238
3 changed files with 14 additions and 5 deletions

View File

@ -9,6 +9,7 @@
#include "tests.h" #include "tests.h"
#include "jsscript.h" #include "jsscript.h"
#include "jsstr.h" #include "jsstr.h"
#include "jsfriendapi.h"
static JSScript * static JSScript *
CompileScriptForPrincipalsVersionOrigin(JSContext *cx, JS::HandleObject obj, CompileScriptForPrincipalsVersionOrigin(JSContext *cx, JS::HandleObject obj,
@ -78,6 +79,7 @@ static JSPrincipals testPrincipals[] = {
BEGIN_TEST(testXDR_principals) BEGIN_TEST(testXDR_principals)
{ {
JSScript *script; JSScript *script;
JSCompartment *compartment = js::GetContextCompartment(cx);
for (int i = TEST_FIRST; i != TEST_END; ++i) { for (int i = TEST_FIRST; i != TEST_END; ++i) {
script = createScriptViaXDR(NULL, NULL, i); script = createScriptViaXDR(NULL, NULL, i);
CHECK(script); CHECK(script);
@ -89,6 +91,10 @@ BEGIN_TEST(testXDR_principals)
CHECK(!JS_GetScriptPrincipals(script)); CHECK(!JS_GetScriptPrincipals(script));
CHECK(!JS_GetScriptOriginPrincipals(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); script = createScriptViaXDR(&testPrincipals[0], NULL, i);
CHECK(script); CHECK(script);
CHECK(JS_GetScriptPrincipals(script) == &testPrincipals[0]); CHECK(JS_GetScriptPrincipals(script) == &testPrincipals[0]);
@ -108,6 +114,7 @@ BEGIN_TEST(testXDR_principals)
CHECK(script); CHECK(script);
CHECK(!JS_GetScriptPrincipals(script)); CHECK(!JS_GetScriptPrincipals(script));
CHECK(JS_GetScriptOriginPrincipals(script) == &testPrincipals[1]); CHECK(JS_GetScriptOriginPrincipals(script) == &testPrincipals[1]);
JS_SetCompartmentPrincipals(compartment, old);
} }
return true; return true;

View File

@ -5173,7 +5173,8 @@ JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment); JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
CHECK_REQUEST(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); AutoLastFrameCheck lfc(cx);
return frontend::CompileScript(cx, obj, NULL, options, chars, length); return frontend::CompileScript(cx, obj, NULL, options, chars, length);
@ -5436,7 +5437,8 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options,
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment); JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
CHECK_REQUEST(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); AutoLastFrameCheck lfc(cx);
RootedAtom funAtom(cx); RootedAtom funAtom(cx);
@ -5653,7 +5655,9 @@ JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options,
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment); JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
CHECK_REQUEST(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); AutoLastFrameCheck lfc(cx);
options.setCompileAndGo(true); options.setCompileAndGo(true);

View File

@ -227,8 +227,6 @@ class CompartmentChecker
} }
} }
void check(JSPrincipals *) { /* nothing for now */ }
void check(JSObject *obj) { void check(JSObject *obj) {
if (obj) if (obj)
check(obj->compartment()); check(obj->compartment());