js/src/tests/ecma_5/extensions/strict-function-statements.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/licenses/publicdomain/
michael@0 4 */
michael@0 5
michael@0 6 // Ordinary function definitions should be unaffected.
michael@0 7 assertEq(testLenientAndStrict("function f() { }",
michael@0 8 parsesSuccessfully,
michael@0 9 parsesSuccessfully),
michael@0 10 true);
michael@0 11
michael@0 12 // Function statements within blocks are forbidden in strict mode code.
michael@0 13 assertEq(testLenientAndStrict("{ function f() { } }",
michael@0 14 parsesSuccessfully,
michael@0 15 parseRaisesException(SyntaxError)),
michael@0 16 true);
michael@0 17
michael@0 18 // Lambdas are always permitted within blocks.
michael@0 19 assertEq(testLenientAndStrict("{ (function f() { }) }",
michael@0 20 parsesSuccessfully,
michael@0 21 parsesSuccessfully),
michael@0 22 true);
michael@0 23
michael@0 24 // Function statements within any sort of statement are forbidden in strict mode code.
michael@0 25 assertEq(testLenientAndStrict("if (true) function f() { }",
michael@0 26 parsesSuccessfully,
michael@0 27 parseRaisesException(SyntaxError)),
michael@0 28 true);
michael@0 29 assertEq(testLenientAndStrict("while (true) function f() { }",
michael@0 30 parsesSuccessfully,
michael@0 31 parseRaisesException(SyntaxError)),
michael@0 32 true);
michael@0 33 assertEq(testLenientAndStrict("do function f() { } while (true);",
michael@0 34 parsesSuccessfully,
michael@0 35 parseRaisesException(SyntaxError)),
michael@0 36 true);
michael@0 37 assertEq(testLenientAndStrict("for(;;) function f() { }",
michael@0 38 parsesSuccessfully,
michael@0 39 parseRaisesException(SyntaxError)),
michael@0 40 true);
michael@0 41 assertEq(testLenientAndStrict("for(x in []) function f() { }",
michael@0 42 parsesSuccessfully,
michael@0 43 parseRaisesException(SyntaxError)),
michael@0 44 true);
michael@0 45 assertEq(testLenientAndStrict("with(o) function f() { }",
michael@0 46 parsesSuccessfully,
michael@0 47 parseRaisesException(SyntaxError)),
michael@0 48 true);
michael@0 49 assertEq(testLenientAndStrict("switch(1) { case 1: function f() { } }",
michael@0 50 parsesSuccessfully,
michael@0 51 parseRaisesException(SyntaxError)),
michael@0 52 true);
michael@0 53 assertEq(testLenientAndStrict("x: function f() { }",
michael@0 54 parsesSuccessfully,
michael@0 55 parseRaisesException(SyntaxError)),
michael@0 56 true);
michael@0 57 assertEq(testLenientAndStrict("try { function f() { } } catch (x) { }",
michael@0 58 parsesSuccessfully,
michael@0 59 parseRaisesException(SyntaxError)),
michael@0 60 true);
michael@0 61
michael@0 62 // Lambdas are always permitted within any sort of statement.
michael@0 63 assertEq(testLenientAndStrict("if (true) (function f() { })",
michael@0 64 parsesSuccessfully,
michael@0 65 parsesSuccessfully),
michael@0 66 true);
michael@0 67
michael@0 68 // Function statements are permitted in blocks within lenient functions.
michael@0 69 assertEq(parsesSuccessfully("function f() { function g() { } }"),
michael@0 70 true);
michael@0 71
michael@0 72 // Function statements are permitted in any statement within lenient functions.
michael@0 73 assertEq(parsesSuccessfully("function f() { if (true) function g() { } }"),
michael@0 74 true);
michael@0 75
michael@0 76 assertEq(parseRaisesException(SyntaxError)
michael@0 77 ("function f() { 'use strict'; if (true) function g() { } }"),
michael@0 78 true);
michael@0 79
michael@0 80 assertEq(parseRaisesException(SyntaxError)
michael@0 81 ("function f() { 'use strict'; { function g() { } } }"),
michael@0 82 true);
michael@0 83
michael@0 84 assertEq(parsesSuccessfully("function f() { 'use strict'; if (true) (function g() { }) }"),
michael@0 85 true);
michael@0 86
michael@0 87 assertEq(parsesSuccessfully("function f() { 'use strict'; { (function g() { }) } }"),
michael@0 88 true);
michael@0 89
michael@0 90 // Eval should behave the same way. (The parse-only tests use the Function constructor.)
michael@0 91 assertEq(testLenientAndStrict("function f() { }",
michael@0 92 completesNormally,
michael@0 93 completesNormally),
michael@0 94 true);
michael@0 95 assertEq(testLenientAndStrict("{ function f() { } }",
michael@0 96 completesNormally,
michael@0 97 raisesException(SyntaxError)),
michael@0 98 true);
michael@0 99
michael@0 100 reportCompare(true, true);

mercurial