Repository: jerryscript-project/jerryscript
File: tests/jerry/es.next/class.js (JavaScript)

Code before:
  }

  must_throw_strict(str);
}

function must_throw_strict(str) {
  try {
    eval ("'use strict'; switch (1) { default: " + str + "}");
    assert (false);
  } catch (e) {
  }

  try {
    eval("'use strict'; " + str);
    assert(false);
  } catch (e) {
  }
}

must_throw("class {}");
must_throw("class class {}");
must_throw("class A { constructor() {} this.a = 5 }");
must_throw("class A { constructor() {} constructor() {} }");
must_throw("class A { static prototype() {} }");
must_throw("class A { static get prototype() {} }");
must_throw("class A { static set prototype() {} }");
must_throw("class A { static prototyp\u{0065}() {} }");
must_throw("class A { static get prototyp\u{0065}() {} }");
must_throw("class A { static set prototyp\u{0065}() {} }");
must_throw("class A { get constructor() {} }");
must_throw("class A { set constructor() {} }");
must_throw("class A {}; A()");
must_throw("class X {}; var o = {}; Object.defineProperty(o, 'p', { get: X, set: X }); o.p;");
must_throw("var a = new A; class A {};");
must_throw("class A { g\\u0065t e() {} }");
must_throw('class A { "static" e() {} }');
must_throw('class A { *constructor() {} }');

assert(eval("class A {}") === undefined);
assert(eval("var a = class A {}") === undefined);
assert(eval("var a = class {}") === undefined);
assert(eval("class A { ; ; ; ;;;;;;;;;;;; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;; }") === undefined);
assert(eval('class A {"constructor"() {} }') === undefined);
assert(isNaN (eval('switch(1) { default: (class A{} % 1) }')));

class A1 {
  ["constructor"]() {
    return 5;
  }
}


Review comment (suggestion):
I would add some testcases for the string variant as well:
Example: `must_throw("class A { static get 'prototype'() {} }");`

Code after:
  }

  must_throw_strict(str);
}

function must_throw_strict(str) {
  try {
    eval ("'use strict'; switch (1) { default: " + str + "}");
    assert (false);
  } catch (e) {
  }

  try {
    eval("'use strict'; " + str);
    assert(false);
  } catch (e) {
  }
}

must_throw("class {}");
must_throw("class class {}");
must_throw("class A { constructor() {} this.a = 5 }");
must_throw("class A { constructor() {} constructor() {} }");
must_throw("class A { static prototype() {} }");
must_throw("class A { static get prototype() {} }");
must_throw("class A { static set prototype() {} }");
must_throw("class A { static prototyp\u{0065}() {} }");
must_throw("class A { static get prototyp\u{0065}() {} }");
must_throw("class A { static set prototyp\u{0065}() {} }");
must_throw("class A { static 'prototype'() {} }");
must_throw("class A { static get 'prototype'() {} }");
must_throw("class A { static set 'prototype'() {} }");
must_throw("class A { static 'prototyp\u{0065}'() {} }");
must_throw("class A { static get 'prototyp\u{0065}'() {} }");
must_throw("class A { static set 'prototyp\u{0065}'() {} }");
must_throw("class A { get constructor() {} }");
must_throw("class A { set constructor() {} }");
must_throw("class A {}; A()");
must_throw("class X {}; var o = {}; Object.defineProperty(o, 'p', { get: X, set: X }); o.p;");
must_throw("var a = new A; class A {};");
must_throw("class A { g\\u0065t e() {} }");
must_throw('class A { "static" e() {} }');
must_throw('class A { *constructor() {} }');

assert(eval("class A {}") === undefined);
assert(eval("var a = class A {}") === undefined);
assert(eval("var a = class {}") === undefined);
assert(eval("class A { ; ; ; ;;;;;;;;;;;; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;; }") === undefined);
assert(eval('class A {"constructor"() {} }') === undefined);
assert(isNaN (eval('switch(1) { default: (class A{} % 1) }')));