diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/syntax/statement-versus-statementlistitem.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/syntax/statement-versus-statementlistitem.js')
-rw-r--r-- | js/src/tests/non262/syntax/statement-versus-statementlistitem.js | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/js/src/tests/non262/syntax/statement-versus-statementlistitem.js b/js/src/tests/non262/syntax/statement-versus-statementlistitem.js new file mode 100644 index 0000000000..d0565353dd --- /dev/null +++ b/js/src/tests/non262/syntax/statement-versus-statementlistitem.js @@ -0,0 +1,148 @@ +// |reftest| skip-if(!xulRuntime.shell) -- needs evaluate, parseModule +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 1288459; +var summary = + "Properly implement the spec's distinctions between StatementListItem and " + + "Statement grammar productions and their uses"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +var counter = 0; + +// Test all the different contexts that expect a Statement. + +function contextAcceptsStatement(pat) +{ + var goodCode = +`function f${counter++}() +{ + ${pat.replace("@@@", "let \n {} \n ;")} +} +`; + + evaluate(goodCode); + + var badCode = +`function f${counter++}() +{ + ${pat.replace("@@@", "let {} \n ;")} +} +`; + + try + { + evaluate(badCode); + throw new Error("didn't throw"); + } + catch (e) + { + assertEq(e instanceof SyntaxError, true, + "didn't get a syntax error, instead got: " + e); + } +} + +contextAcceptsStatement("if (0) @@@"); +contextAcceptsStatement("if (0) ; else @@@"); +contextAcceptsStatement("if (0) ; else if (0) @@@"); +contextAcceptsStatement("if (0) ; else if (0) ; else @@@"); +// Can't test do-while loops this way because the Statement isn't in trailing +// position, so 'let' followed by newline *must* be followed by 'while'. +contextAcceptsStatement("while (1) @@@"); +contextAcceptsStatement("for (1; 1; 0) @@@"); +contextAcceptsStatement("for (var x; 1; 0) @@@"); +contextAcceptsStatement("for (let x; 1; 0) @@@"); +contextAcceptsStatement("for (const x = 1; 1; 0) @@@"); +contextAcceptsStatement("for (x in 0) @@@"); +contextAcceptsStatement("for (var x in 0) @@@"); +contextAcceptsStatement("for (let x in 0) @@@"); +contextAcceptsStatement("for (const x in 0) @@@"); +contextAcceptsStatement("for (x of []) @@@"); +contextAcceptsStatement("for (var x of []) @@@"); +contextAcceptsStatement("for (let x of []) @@@"); +contextAcceptsStatement("for (const x of []) @@@"); +contextAcceptsStatement("with (1) @@@"); +contextAcceptsStatement("foo: @@@"); + +// Test all the different contexts that expect a StatementListItem. + +function contextAcceptsStatementListItem(pat) +{ + var goodCode = +`function f${counter++}() +{ + ${pat.replace("@@@", "let \n [] = [] ;")} +} +`; + + evaluate(goodCode); + + var moarGoodCode = pat.replace("@@@", "let \n [] = [] ;"); + evaluate(moarGoodCode); + + var goodModuleCode = pat.replace("@@@", "let \n [] = [] ;"); + parseModule(goodModuleCode); + + var badCode = +`function f${counter++}() +{ + ${pat.replace("@@@", "let \n let = 3 ;")} +} +`; + + try + { + evaluate(badCode); + throw new Error("didn't throw"); + } + catch (e) + { + assertEq(e instanceof SyntaxError, true, + "didn't get a syntax error, instead got: " + e); + } +} + +contextAcceptsStatementListItem("{ @@@ }"); +contextAcceptsStatementListItem("switch (1) { case 1: @@@ }"); +contextAcceptsStatementListItem("switch (1) { default: @@@ }"); +contextAcceptsStatementListItem("switch (1) { case 0: case 1: @@@ }"); +contextAcceptsStatementListItem("switch (1) { case 0: break; case 1: @@@ }"); +contextAcceptsStatementListItem("switch (1) { default: @@@ case 2: }"); +contextAcceptsStatementListItem("try { @@@ } catch (e) { }"); +contextAcceptsStatementListItem("try { @@@ } finally { }"); +contextAcceptsStatementListItem("try { @@@ } catch (e) { } finally { }"); +contextAcceptsStatementListItem("try { } catch (e) { @@@ }"); +contextAcceptsStatementListItem("try { } finally { @@@ }"); +contextAcceptsStatementListItem("try { } catch (e) { @@@ } finally { }"); +contextAcceptsStatementListItem("try { } catch (e) { } finally { @@@ }"); +contextAcceptsStatementListItem("_ => { @@@ }"); +contextAcceptsStatementListItem("function q() { @@@ }"); +contextAcceptsStatementListItem("function* q() { @@@ }"); +contextAcceptsStatementListItem("(function() { @@@ })"); +contextAcceptsStatementListItem("(function*() { @@@ })"); +contextAcceptsStatementListItem("({ *q() { @@@ } })"); +contextAcceptsStatementListItem("({ q() { @@@ } })"); +contextAcceptsStatementListItem("({ get q() { @@@ } })"); +contextAcceptsStatementListItem("({ set q(v) { @@@ } })"); +contextAcceptsStatementListItem("(class { f() { @@@ } })"); +contextAcceptsStatementListItem("(class { static f() { @@@ } })"); +contextAcceptsStatementListItem("(class { static *f() { @@@ } })"); +contextAcceptsStatementListItem("(class { static get f() { @@@ } })"); +contextAcceptsStatementListItem("(class { static set f(v) { @@@ } })"); +contextAcceptsStatementListItem("(class { static() { @@@ } })"); +contextAcceptsStatementListItem("@@@"); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests complete"); |