зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1111101 - Add a test. (This was fixed by another bug since its filing, woo.) r=test
--HG-- extra : rebase_source : 5e2fca4e1f1f84e38634af7090c222330c4a42e7
This commit is contained in:
Родитель
d6dbb2722c
Коммит
cfc0f2faad
|
@ -0,0 +1,76 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 1111101;
|
||||
var summary =
|
||||
"delete (foo), delete ((foo)), and so on are strict mode early errors";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
function checkSyntaxError(code)
|
||||
{
|
||||
function helper(maker)
|
||||
{
|
||||
var earlyError = false;
|
||||
try
|
||||
{
|
||||
var f = maker(code);
|
||||
|
||||
var error = "no early error, created a function with code <" + code + ">";
|
||||
try
|
||||
{
|
||||
f();
|
||||
error += ", and the function can be called without error";
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
error +=", and calling the function throws " + e;
|
||||
}
|
||||
|
||||
throw new Error(error);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
assertEq(e instanceof SyntaxError, true,
|
||||
"expected syntax error, got " + e);
|
||||
}
|
||||
}
|
||||
|
||||
helper(Function);
|
||||
helper(eval);
|
||||
}
|
||||
|
||||
checkSyntaxError("function f() { 'use strict'; delete escape; } f();");
|
||||
checkSyntaxError("function f() { 'use strict'; delete escape; }");
|
||||
checkSyntaxError("function f() { 'use strict'; delete (escape); } f();");
|
||||
checkSyntaxError("function f() { 'use strict'; delete (escape); }");
|
||||
checkSyntaxError("function f() { 'use strict'; delete ((escape)); } f();");
|
||||
checkSyntaxError("function f() { 'use strict'; delete ((escape)); }");
|
||||
|
||||
// Meanwhile, non-strict all of these should work
|
||||
|
||||
function checkFine(code)
|
||||
{
|
||||
Function(code);
|
||||
(1, eval)(code); // indirect, to be consistent w/above
|
||||
}
|
||||
|
||||
checkFine("function f() { delete escape; } f();");
|
||||
checkFine("function f() { delete escape; }");
|
||||
checkFine("function f() { delete (escape); } f();");
|
||||
checkFine("function f() { delete (escape); }");
|
||||
checkFine("function f() { delete ((escape)); } f();");
|
||||
checkFine("function f() { delete ((escape)); }");
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
Загрузка…
Ссылка в новой задаче