Bug 1921963 part 1 - Use JS::ReportUncatchableException more outside the JS engine...
[gecko.git] / js / src / tests / non262 / expressions / trailing_comma_getter_setter.js
blob258dd8df61fe3395b0fb5babd334f6ee996ec675
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // Trailing comma is not allowed in getter and setter methods
7 // 14.3 Method Definitions
8 // MethodDefinition[Yield]:
9 //   get PropertyName[?Yield] () { FunctionBody[~Yield] }
10 //   set PropertyName[?Yield] ( PropertySetParameterList ) { FunctionBody[~Yield] }
11 // PropertySetParameterList:
12 //   FormalParameter[~Yield]
14 function objectGetter(argList) {
15     return eval(`({
16         get m(${argList}) {}
17     })`);
20 function objectSetter(argList) {
21     return eval(`({
22         set m(${argList}) {}
23     })`);
26 function classGetter(argList) {
27     return eval(`(class {
28         get m(${argList}) {}
29     })`);
32 function classStaticGetter(argList) {
33     return eval(`(class {
34         static get m(${argList}) {}
35     })`);
38 function classSetter(argList) {
39     return eval(`(class {
40         set m(${argList}) {}
41     })`);
44 function classStaticSetter(argList) {
45     return eval(`(class {
46         static set m(${argList}) {}
47     })`);
50 const tests = [
51     objectGetter,
52     objectSetter,
53     classGetter,
54     classStaticGetter,
55     classSetter,
56     classStaticSetter,
59 for (let test of tests) {
60     // Trailing comma.
61     assertThrowsInstanceOf(() => test("a, "), SyntaxError);
62     assertThrowsInstanceOf(() => test("[], "), SyntaxError);
63     assertThrowsInstanceOf(() => test("{}, "), SyntaxError);
64     assertThrowsInstanceOf(() => test("a = 0, "), SyntaxError);
65     assertThrowsInstanceOf(() => test("[] = [], "), SyntaxError);
66     assertThrowsInstanceOf(() => test("{} = {}, "), SyntaxError);
68     // Trailing comma in empty parameters list.
69     assertThrowsInstanceOf(() => test(","), SyntaxError);
71     // Leading comma.
72     assertThrowsInstanceOf(() => test(", a"), SyntaxError);
73     assertThrowsInstanceOf(() => test(", ...a"), SyntaxError);
75     // Multiple trailing comma.
76     assertThrowsInstanceOf(() => test("a, ,"), SyntaxError);
77     assertThrowsInstanceOf(() => test("a..., ,"), SyntaxError);
79     // Trailing comma after rest parameter.
80     assertThrowsInstanceOf(() => test("...a ,"), SyntaxError);
81     assertThrowsInstanceOf(() => test("a, ...b, "), SyntaxError);
83     // Elision.
84     assertThrowsInstanceOf(() => test("a, , b"), SyntaxError);
87 if (typeof reportCompare === "function")
88     reportCompare(0, 0);