Implement Object.prototype.__proto__ accessor property (#3546)

We are using the already existing Object.getPrototypeOf and
Object.setProtoypeOf methods

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam
2020-03-27 14:46:51 +01:00
committed by GitHub
parent 94b8b4bb7b
commit 4240b740aa
13 changed files with 205 additions and 7 deletions
+18
View File
@@ -847,6 +847,10 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
parser_stack_push_uint8 (context_p, PARSER_OBJECT_PROPERTY_START);
#endif /* !ENABLED (JERRY_ES2015) */
#if ENABLED (JERRY_ES2015)
bool proto_seen = false;
#endif /* ENABLED (JERRY_ES2015) */
while (true)
{
lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_NO_OPTS);
@@ -991,6 +995,20 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
#endif /* ENABLED (JERRY_ES2015) */
default:
{
#if ENABLED (JERRY_ES2015)
if ((context_p->token.lit_location.type == LEXER_IDENT_LITERAL
|| context_p->token.lit_location.type == LEXER_STRING_LITERAL)
&& lexer_compare_literal_to_string (context_p, "__proto__", 9))
{
if (proto_seen)
{
parser_raise_error (context_p, PARSER_ERR_DUPLICATED_PROTO);
}
proto_seen = true;
}
#endif /* ENABLED (JERRY_ES2015) */
uint16_t literal_index = context_p->lit_object.index;
#if ENABLED (JERRY_ES2015)
+4
View File
@@ -966,6 +966,10 @@ parser_error_to_string (parser_error_t error) /**< error code */
{
return "for in-of loop variable declaration may not have an initializer.";
}
case PARSER_ERR_DUPLICATED_PROTO:
{
return "Duplicate __proto__ fields are not allowed in object literals.";
}
#endif /* ENABLED (JERRY_ES2015) */
case PARSER_ERR_DELETE_IDENT_NOT_ALLOWED:
{
+1
View File
@@ -81,6 +81,7 @@ typedef enum
PARSER_ERR_USE_STRICT_NOT_ALLOWED, /**< use strict directive is not allowed */
PARSER_ERR_YIELD_NOT_ALLOWED, /**< yield keyword is not allowed */
PARSER_ERR_FOR_IN_OF_DECLARATION, /**< variable declaration in for-in or for-of loop */
PARSER_ERR_DUPLICATED_PROTO, /**< duplicated __proto__ fields are not allowed */
#endif /* ENABLED (JERRY_ES2015) */
PARSER_ERR_DELETE_IDENT_NOT_ALLOWED, /**< identifier delete is not allowed in strict mode */
PARSER_ERR_EVAL_CANNOT_ASSIGNED, /**< eval cannot be assigned in strict mode */