Methods shouldn't have prototype property (#3964)

JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác csaba.osztrogonac@h-lab.eu
This commit is contained in:
Csaba Osztrogonác 2020-08-05 14:01:58 +02:00 committed by GitHub
parent b82bd76175
commit c76736eadf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 15 deletions

View File

@ -1324,6 +1324,11 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
message_p = ECMA_ERR_MSG ("Async arrow functions cannot be invoked with 'new'.");
break;
}
case CBC_FUNCTION_METHOD:
{
message_p = ECMA_ERR_MSG ("Methods cannot be invoked with 'new'.");
break;
}
default:
{
JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (byte_code_p->status_flags) == CBC_FUNCTION_ACCESSOR);

View File

@ -880,6 +880,7 @@ typedef enum
/* The following functions has no prototype (see CBC_FUNCTION_HAS_PROTOTYPE) */
CBC_FUNCTION_ACCESSOR, /**< property accessor function */
CBC_FUNCTION_METHOD, /**< method */
/* The following functions are arrow function (see CBC_FUNCTION_IS_ARROW) */
CBC_FUNCTION_ARROW, /**< arrow function */

View File

@ -743,7 +743,7 @@ parser_parse_class_literal (parser_context_t *context_p, /**< context */
parse_class_method:
; /* Empty statement to make compiler happy. */
uint16_t literal_index = context_p->lit_object.index;
uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags);
uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags | PARSER_IS_METHOD);
parser_emit_cbc_literal (context_p,
CBC_PUSH_LITERAL,
@ -915,7 +915,8 @@ parser_parse_object_method (parser_context_t *context_p) /**< context */
context_p->source_p--;
context_p->column--;
uint16_t function_literal_index = lexer_construct_function_object (context_p, (PARSER_FUNCTION_CLOSURE
| PARSER_ALLOW_SUPER));
| PARSER_ALLOW_SUPER
| PARSER_IS_METHOD));
parser_emit_cbc_literal (context_p,
CBC_PUSH_LITERAL,

View File

@ -74,11 +74,11 @@ typedef enum
PARSER_ALLOW_SUPER_CALL = (1u << 22), /**< allow super constructor call
* Note: PARSER_CLASS_CONSTRUCTOR must be present */
PARSER_ALLOW_NEW_TARGET = (1u << 23), /**< allow new.target parsing in the current context */
PARSER_IS_METHOD = (1u << 24), /**< method is parsed */
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_MODULE_SYSTEM)
PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 24), /**< parsing a function or class default export */
PARSER_MODULE_STORE_IDENT = (1u << 25), /**< store identifier of the current export statement */
PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 25), /**< parsing a function or class default export */
PARSER_MODULE_STORE_IDENT = (1u << 26), /**< store identifier of the current export statement */
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
PARSER_HAS_LATE_LIT_INIT = (1u << 30), /**< there are identifier or string literals which construction
* is postponed after the local parser data is freed */

View File

@ -1405,6 +1405,10 @@ parser_post_processing (parser_context_t *context_p) /**< context */
{
function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_CONSTRUCTOR);
}
else if (context_p->status_flags & PARSER_IS_METHOD)
{
function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_METHOD);
}
else
{
function_type = CBC_FUNCTION_TO_TYPE_BITS (CBC_FUNCTION_NORMAL);

View File

@ -18,4 +18,8 @@ class MyNonArray extends Array {
static [Symbol.species] () {}
}
(() => MyNonArray)().prototype.slice.call(new MyNonArray((0) === 1))
try {
(() => MyNonArray)().prototype.slice.call(new MyNonArray((0) === 1))
} catch (e) {
assert (e instanceof TypeError);
}

View File

@ -286,9 +286,7 @@
<test id="language/expressions/equals/coerce-symbol-to-prim-return-prim.js"><reason></reason></test>
<test id="language/expressions/generators/has-instance.js"><reason></reason></test>
<test id="language/expressions/generators/prototype-value.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/generator-invoke-ctor.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/name-invoke-ctor.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/name-prototype-prop.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/generator-invoke-ctor.js"><reason>ES2016 change: Generator methods isn't constructor - https://github.com/tc39/ecma262/pull/171 </reason></test>
<test id="language/expressions/postfix-decrement/S11.3.2_A5_T1.js"><reason></reason></test>
<test id="language/expressions/postfix-decrement/S11.3.2_A5_T2.js"><reason></reason></test>
<test id="language/expressions/postfix-decrement/S11.3.2_A5_T3.js"><reason></reason></test>
@ -324,8 +322,6 @@
<test id="language/line-terminators/S7.3_A2.4.js"><reason>No longer a SyntaxError in ES11</reason></test>
<test id="language/literals/string/7.8.4-1-s.js"><reason></reason></test>
<test id="language/module-code/export-unresolvable.js"><reason></reason></test>
<test id="language/statements/class/definition/methods.js"><reason></reason></test>
<test id="language/statements/class/definition/numeric-property-names.js"><reason></reason></test>
<test id="language/statements/class/definition/this-access-restriction.js"><reason></reason></test>
<test id="language/statements/class/definition/this-check-ordering.js"><reason></reason></test>
<test id="language/statements/class/name-binding/in-extends-expression-assigned.js"><reason></reason></test>

View File

@ -6779,9 +6779,7 @@
<test id="language/expressions/object/method-definition/generator-length-dflt.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/meth-dflt-params-trailing-comma.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/meth-eval-var-scope-syntax-err.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/name-invoke-ctor.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/name-length-dflt.js"><reason></reason></test>
<test id="language/expressions/object/method-definition/name-prototype-prop.js"><reason></reason></test>
<test id="language/expressions/object/object-spread-proxy-ownkeys-returned-keys-order.js"><reason></reason></test>
<test id="language/expressions/object/setter-length-dflt.js"><reason></reason></test>
<test id="language/expressions/optional-chaining/call-expression.js"><reason></reason></test>
@ -7413,8 +7411,6 @@
<test id="language/statements/class/class-name-ident-yield.js"><reason></reason></test>
<test id="language/statements/class/classelementname-abrupt-completion.js"><reason></reason></test>
<test id="language/statements/class/constructor-inferred-observable-iteration.js"><reason></reason></test>
<test id="language/statements/class/definition/methods.js"><reason></reason></test>
<test id="language/statements/class/definition/numeric-property-names.js"><reason></reason></test>
<test id="language/statements/class/definition/this-access-restriction.js"><reason></reason></test>
<test id="language/statements/class/definition/this-check-ordering.js"><reason></reason></test>
<test id="language/statements/class/dstr/async-gen-meth-ary-init-iter-no-close.js"><reason></reason></test>