michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: // Ordinary function definitions should be unaffected. michael@0: assertEq(testLenientAndStrict("function f() { }", michael@0: parsesSuccessfully, michael@0: parsesSuccessfully), michael@0: true); michael@0: michael@0: // Function statements within blocks are forbidden in strict mode code. michael@0: assertEq(testLenientAndStrict("{ function f() { } }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: michael@0: // Lambdas are always permitted within blocks. michael@0: assertEq(testLenientAndStrict("{ (function f() { }) }", michael@0: parsesSuccessfully, michael@0: parsesSuccessfully), michael@0: true); michael@0: michael@0: // Function statements within any sort of statement are forbidden in strict mode code. michael@0: assertEq(testLenientAndStrict("if (true) function f() { }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: assertEq(testLenientAndStrict("while (true) function f() { }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: assertEq(testLenientAndStrict("do function f() { } while (true);", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: assertEq(testLenientAndStrict("for(;;) function f() { }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: assertEq(testLenientAndStrict("for(x in []) function f() { }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: assertEq(testLenientAndStrict("with(o) function f() { }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: assertEq(testLenientAndStrict("switch(1) { case 1: function f() { } }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: assertEq(testLenientAndStrict("x: function f() { }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: assertEq(testLenientAndStrict("try { function f() { } } catch (x) { }", michael@0: parsesSuccessfully, michael@0: parseRaisesException(SyntaxError)), michael@0: true); michael@0: michael@0: // Lambdas are always permitted within any sort of statement. michael@0: assertEq(testLenientAndStrict("if (true) (function f() { })", michael@0: parsesSuccessfully, michael@0: parsesSuccessfully), michael@0: true); michael@0: michael@0: // Function statements are permitted in blocks within lenient functions. michael@0: assertEq(parsesSuccessfully("function f() { function g() { } }"), michael@0: true); michael@0: michael@0: // Function statements are permitted in any statement within lenient functions. michael@0: assertEq(parsesSuccessfully("function f() { if (true) function g() { } }"), michael@0: true); michael@0: michael@0: assertEq(parseRaisesException(SyntaxError) michael@0: ("function f() { 'use strict'; if (true) function g() { } }"), michael@0: true); michael@0: michael@0: assertEq(parseRaisesException(SyntaxError) michael@0: ("function f() { 'use strict'; { function g() { } } }"), michael@0: true); michael@0: michael@0: assertEq(parsesSuccessfully("function f() { 'use strict'; if (true) (function g() { }) }"), michael@0: true); michael@0: michael@0: assertEq(parsesSuccessfully("function f() { 'use strict'; { (function g() { }) } }"), michael@0: true); michael@0: michael@0: // Eval should behave the same way. (The parse-only tests use the Function constructor.) michael@0: assertEq(testLenientAndStrict("function f() { }", michael@0: completesNormally, michael@0: completesNormally), michael@0: true); michael@0: assertEq(testLenientAndStrict("{ function f() { } }", michael@0: completesNormally, michael@0: raisesException(SyntaxError)), michael@0: true); michael@0: michael@0: reportCompare(true, true);