Throw error for generator function class constructor (#3489)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -569,11 +569,20 @@ parser_parse_class_literal (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
is_computed = true;
|
||||
}
|
||||
else if ((status_flags & PARSER_CLASS_STATIC_FUNCTION)
|
||||
&& LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type)
|
||||
&& lexer_compare_literal_to_string (context_p, "prototype", 9))
|
||||
else if (LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_CLASS_STATIC_PROTOTYPE);
|
||||
if (status_flags & PARSER_CLASS_STATIC_FUNCTION)
|
||||
{
|
||||
if (lexer_compare_literal_to_string (context_p, "prototype", 9))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_CLASS_STATIC_PROTOTYPE);
|
||||
}
|
||||
}
|
||||
else if ((status_flags & PARSER_IS_GENERATOR_FUNCTION)
|
||||
&& lexer_compare_literal_to_string (context_p, "constructor", 11))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_CLASS_CONSTRUCTOR_AS_GENERATOR);
|
||||
}
|
||||
}
|
||||
|
||||
parse_class_method:
|
||||
|
||||
@@ -1133,6 +1133,10 @@ parser_error_to_string (parser_error_t error) /**< error code */
|
||||
{
|
||||
return "Class constructor may not be an accessor.";
|
||||
}
|
||||
case PARSER_ERR_CLASS_CONSTRUCTOR_AS_GENERATOR:
|
||||
{
|
||||
return "Class constructor may not be a generator.";
|
||||
}
|
||||
case PARSER_ERR_CLASS_STATIC_PROTOTYPE:
|
||||
{
|
||||
return "Classes may not have a static property called 'prototype'.";
|
||||
|
||||
@@ -130,6 +130,7 @@ typedef enum
|
||||
|
||||
PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS, /**< multiple class constructor */
|
||||
PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR, /**< class constructor cannot be an accessor */
|
||||
PARSER_ERR_CLASS_CONSTRUCTOR_AS_GENERATOR, /**< class constructor cannot be a generator */
|
||||
PARSER_ERR_CLASS_STATIC_PROTOTYPE, /**< static method name 'prototype' is not allowed */
|
||||
PARSER_ERR_UNEXPECTED_SUPER_REFERENCE, /**< unexpected super keyword */
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ must_throw("class X {}; var o = {}; Object.defineProperty(o, 'p', { get: X, set:
|
||||
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);
|
||||
@@ -64,6 +65,22 @@ assert(eval("class A { ; ; ; ;;;;;;;;;;;; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;; }") ===
|
||||
assert(eval('class A {"constructor"() {} }') === undefined);
|
||||
assert(isNaN (eval('switch(1) { default: (class A{} % 1) }')));
|
||||
|
||||
class A1 {
|
||||
["constructor"]() {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
assert ((new A1).constructor() === 5);
|
||||
|
||||
class A2 {
|
||||
*["constructor"]() {
|
||||
yield 5;
|
||||
}
|
||||
}
|
||||
|
||||
assert ((new A2).constructor().next().value === 5);
|
||||
|
||||
class B {
|
||||
}
|
||||
|
||||
@@ -90,6 +107,10 @@ class C {
|
||||
return() {
|
||||
return 43;
|
||||
}
|
||||
|
||||
static *constructor() {
|
||||
return 44;
|
||||
}
|
||||
}
|
||||
|
||||
var c = new C;
|
||||
@@ -99,6 +120,7 @@ assert (c["3"]() === 3);
|
||||
assert (c.super() === 42);
|
||||
assert (c.return() === 43);
|
||||
assert (c.constructor === C);
|
||||
assert (C.constructor().next().value === 44);
|
||||
|
||||
class D {
|
||||
constructor(d) {
|
||||
|
||||
Reference in New Issue
Block a user