Check for prototype bound name in class static accessors (#4257)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
Dániel Bátyai 2020-10-16 17:02:17 +02:00 committed by GitHub
parent d8955552d7
commit 080abb94ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 7 deletions

View File

@ -621,8 +621,17 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
{
is_computed = true;
}
else if (!is_static && parser_is_constructor_literal (context_p))
else if (is_static)
{
if (LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type)
&& lexer_compare_identifier_to_string (&context_p->token.lit_location, (uint8_t *) "prototype", 9))
{
parser_raise_error (context_p, PARSER_ERR_CLASS_STATIC_PROTOTYPE);
}
}
else if (parser_is_constructor_literal (context_p))
{
JERRY_ASSERT (!is_static);
parser_raise_error (context_p, PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR);
}
@ -705,7 +714,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
{
if (is_static)
{
if (lexer_compare_literal_to_string (context_p, "prototype", 9))
if (lexer_compare_identifier_to_string (&context_p->token.lit_location, (uint8_t *) "prototype", 9))
{
parser_raise_error (context_p, PARSER_ERR_CLASS_STATIC_PROTOTYPE);
}

View File

@ -49,6 +49,17 @@ 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()");

View File

@ -301,7 +301,6 @@
<test id="language/expressions/tagged-template/cache-identical-source-new-function.js"><reason></reason></test>
<test id="language/line-terminators/S7.3_A2.3.js"><reason>No longer a SyntaxError in ES11</reason></test>
<test id="language/line-terminators/S7.3_A2.4.js"><reason>No longer a SyntaxError in ES11</reason></test>
<test id="language/statements/class/syntax/early-errors/class-body-static-method-get-propname-prototype.js"><reason></reason></test>
<test id="language/statements/for-of/iterator-next-reference.js"><reason>ES2018 change: next method must be cached</reason></test>
<test id="language/statements/for/S12.6.3_A9.1.js"><reason></reason></test>
<test id="language/statements/for/S12.6.3_A9.js"><reason></reason></test>

View File

@ -604,8 +604,6 @@
<test id="language/expressions/class/dstr/meth-dflt-ary-init-iter-no-close.js"><reason></reason></test>
<test id="language/expressions/class/dstr/meth-static-ary-init-iter-no-close.js"><reason></reason></test>
<test id="language/expressions/class/dstr/meth-static-dflt-ary-init-iter-no-close.js"><reason></reason></test>
<test id="language/expressions/class/elements/syntax/early-errors/grammar-static-get-meth-prototype.js"><reason></reason></test>
<test id="language/expressions/class/elements/syntax/early-errors/grammar-static-set-meth-prototype.js"><reason></reason></test>
<test id="language/expressions/class/gen-method-length-dflt.js"><reason></reason></test>
<test id="language/expressions/class/gen-method-static/dflt-params-trailing-comma.js"><reason></reason></test>
<test id="language/expressions/class/gen-method/dflt-params-trailing-comma.js"><reason></reason></test>
@ -882,8 +880,6 @@
<test id="language/statements/class/dstr/meth-dflt-ary-init-iter-no-close.js"><reason></reason></test>
<test id="language/statements/class/dstr/meth-static-ary-init-iter-no-close.js"><reason></reason></test>
<test id="language/statements/class/dstr/meth-static-dflt-ary-init-iter-no-close.js"><reason></reason></test>
<test id="language/statements/class/elements/syntax/early-errors/grammar-static-get-meth-prototype.js"><reason></reason></test>
<test id="language/statements/class/elements/syntax/early-errors/grammar-static-set-meth-prototype.js"><reason></reason></test>
<test id="language/statements/class/gen-method-length-dflt.js"><reason></reason></test>
<test id="language/statements/class/gen-method-static/dflt-params-trailing-comma.js"><reason></reason></test>
<test id="language/statements/class/gen-method/dflt-params-trailing-comma.js"><reason></reason></test>