Backed out changeset 3dd4a5d6bef6 (bug 1814880) for causing SM bustages CLOSED TREE

This commit is contained in:
Norisz Fay 2023-02-09 08:09:47 +02:00
parent ed2a64e98a
commit 13450d0c30
4 changed files with 14 additions and 23 deletions

View File

@ -1,5 +1,3 @@
load(libdir + "asserts.js");
// Test with envChainObject in current global.
{
let global = newGlobal();
@ -14,12 +12,3 @@ load(libdir + "asserts.js");
assertEq(envChainObject.a, "test2");
assertEq(evaluate("a", { global, envChainObject }), "test2");
}
// Unqualified variable objects are not allowed.
assertThrowsInstanceOf(() => {
evaluate("10", { envChainObject: evalcx("") });
}, Error);
assertThrowsInstanceOf(() => {
evaluate("10", { envChainObject: evalReturningScope("1") });
}, Error);

View File

@ -2336,18 +2336,12 @@ static bool Evaluate(JSContext* cx, unsigned argc, Value* vp) {
cx, GetErrorMessage, nullptr, JSMSG_UNEXPECTED_TYPE,
"\"envChainObject\" passed to evaluate()", "not an object");
return false;
}
JSObject* obj = &v.toObject();
if (obj->isUnqualifiedVarObj()) {
} else if (v.toObject().is<GlobalObject>()) {
JS_ReportErrorASCII(
cx,
"\"envChainObject\" passed to evaluate() should not be an "
"unqualified variables object");
"\"envChainObject\" passed to evaluate() should not be a global");
return false;
}
if (!envChain.append(obj)) {
} else if (!envChain.append(&v.toObject())) {
return false;
}
}

View File

@ -33,7 +33,14 @@ evaluate("(function() { assertEq(someVar, 2);})()", evalOpt);
evaluate("(function() { assertEq(this !== alsoSomeObject, true);})()", evalOpt);
evaluate("(function() { assertEq(this.someVar, 1);})()", evalOpt);
// `this` is ShellWindowProxy instead of GlobalObject, and it's allowed.
evaluate("assertEq(someVar, 1);", { envChainObject: this });
var globalEvalOpt = {
envChainObject: this
};
try {
evaluate("assertEq(someVar, 1);", globalEvalOpt);
throw new Error("Globals aren't allowed as a envChainObject argument to evaluate");
} catch (e) {
}
reportCompare(true, true);

View File

@ -3324,7 +3324,8 @@ bool js::CreateObjectsForEnvironmentChain(JSContext* cx,
#ifdef DEBUG
for (size_t i = 0; i < chain.length(); ++i) {
cx->check(chain[i]);
MOZ_ASSERT(!chain[i]->isUnqualifiedVarObj());
MOZ_ASSERT(!chain[i]->is<GlobalObject>() &&
!chain[i]->is<NonSyntacticVariablesObject>());
}
#endif