Bug 1071646 - Forgot to commit tests on backout and relanding cycle. (r=me)

This commit is contained in:
Shu-yu Guo 2015-12-28 18:52:59 -08:00 committed by Cameron Kaiser
parent 2ec542b5a3
commit 069a26bf9a
8 changed files with 242 additions and 0 deletions

View File

@ -0,0 +1,38 @@
var log = "";
function f() {
log += g();
function g() { return "outer-g"; }
var o = { g: function () { return "with-g"; } };
with (o) {
// Annex B.3.3.3 says g should be set on the nearest VariableEnvironment,
// and so should not change o.g.
eval(`{
function g() { return "eval-g"; }
}`);
}
log += g();
log += o.g();
}
f();
function h() {
eval(`
// Should return true, as var bindings introduced by eval are configurable.
log += (delete q);
{
function q() { log += "q"; }
// Should return false, as lexical bindings introduced by eval are not
// configurable.
log += (delete q);
}
`);
return q;
}
h()();
reportCompare(log, "outer-geval-gwith-gtruefalseq");

View File

@ -0,0 +1,42 @@
var log = "";
function f(x) {
if (x)
function g() { return "g0"; }
else
function g() { return "g1"; }
log += g();
if (x)
function g() { return "g2"; }
else {
}
log += g();
if (x) {
} else
function g() { return "g3"; }
log += g();
if (x)
function g() { return "g4"; }
log += g();
}
f(true);
f(false);
try {
eval(`
if (1)
l: function foo() {}
`);
} catch (e) {
log += "e";
}
reportCompare(log, "g0g2g2g4g1g1g3g3e");

View File

@ -0,0 +1,43 @@
function expectSyntaxError(str) {
var threwSyntaxError;
try {
eval(str);
} catch (e) {
threwSyntaxError = e instanceof SyntaxError;
}
assertEq(threwSyntaxError, true);
try {
eval('"use strict";' + str);
} catch (e) {
threwSyntaxError = e instanceof SyntaxError;
}
assertEq(threwSyntaxError, true);
}
function expectSloppyPass(str) {
eval(str);
try {
eval('"use strict";' + str);
} catch (e) {
threwSyntaxError = e instanceof SyntaxError;
}
assertEq(threwSyntaxError, true);
}
expectSloppyPass(`l: function f1() {}`);
expectSloppyPass(`l0: l: function f1() {}`);
expectSloppyPass(`{ f1(); l: function f1() {} }`);
expectSloppyPass(`{ f1(); l0: l: function f1() {} }`);
expectSloppyPass(`{ f1(); l: function f1() { return 42; } } assertEq(f1(), 42);`);
expectSloppyPass(`eval("fe(); l: function fe() {}")`);
expectSyntaxError(`if (1) l: function f2() {}`);
expectSyntaxError(`if (1) {} else l: function f3() {}`);
expectSyntaxError(`do l: function f4() {} while (0)`);
expectSyntaxError(`while (0) l: function f5() {}`);
expectSyntaxError(`for (;;) l: function f6() {}`);
expectSloppyPass(`switch (1) { case 1: l: function f7() {} }`);
expectSloppyPass(`switch (1) { case 1: assertEq(f8(), 'f8'); case 2: l: function f8() { return 'f8'; } } assertEq(f8(), 'f8');`);
reportCompare(0, 0);

View File

@ -0,0 +1,18 @@
// |reftest| skip-if(!xulRuntime.shell)
// Define a global getter without a setter.
Object.defineProperty(this, "x", {
get: function () { return "get-x"; },
configurable: true
});
// Simulate loading a 2nd script with evaluate, else we would DEFVAR the x and
// the above defineProperty would fail in trying to redefine a non-configurable
// property on the global.
evaluate(`{
function x() { return "fun-x"; }
}`);
// Annex B is supposed to be like an assignment. Should not blow away the
// existing setter-less getter.
reportCompare(x, "get-x");

View File

@ -0,0 +1,7 @@
{
function f() { return "inner"; }
}
function f() { return "outer"; }
reportCompare(f(), "inner");

View File

@ -0,0 +1,18 @@
var o = { f: "string-f" };
with (o) {
var desc = Object.getOwnPropertyDescriptor(this, "f");
assertEq(desc.value, undefined);
assertEq(desc.writable, true);
assertEq(desc.enumerable, true);
assertEq(desc.configurable, false);
function f() {
return "fun-f";
}
}
// Annex B explicitly assigns to the nearest VariableEnvironment, so the
// with-object "o" should have its property unchanged.
assertEq(o.f, "string-f");
assertEq(f(), "fun-f");
reportCompare(true, true)

View File

@ -0,0 +1,31 @@
var log = "";
log += typeof f;
{
log += f();
function f() {
return "f1";
}
}
log += f();
function g() {
log += typeof h;
{
log += h();
function h() {
return "h1";
}
}
log += h();
}
g();
reportCompare(log, "undefinedf1f1undefinedh1h1");

View File

@ -0,0 +1,45 @@
"use strict"
var log = "";
function f() {
return "f0";
}
log += f();
{
log += f();
function f() {
return "f1";
}
log += f();
}
log += f();
function g() {
function h() {
return "h0";
}
log += h();
{
log += h();
function h() {
return "h1";
}
log += h();
}
log += h();
}
g();
reportCompare(log, "f0f1f1f0h0h1h1h0");