Add support for new.target (#3469)

Notable changes:
* Extracted the pure JS/builtin and external C method invocations
  into two new methods (`ecma_op_function_call_{simple, external}`).
* Updated parser/scanner to handle "new.target" correctly.
* Added JS test case.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
This commit is contained in:
Péter Gál
2020-01-14 13:34:19 +01:00
committed by Robert Fancsik
parent be8ae3aae8
commit 0fd1ed6f27
22 changed files with 841 additions and 124 deletions
+5
View File
@@ -665,8 +665,13 @@ opfunc_resume_executable_object (vm_executable_object_t *executable_object_p, /*
executable_object_p->frame_ctx.prev_context_p = JERRY_CONTEXT (vm_top_context_p);
JERRY_CONTEXT (vm_top_context_p) = &executable_object_p->frame_ctx;
/* inside the generators the "new.target" is always "undefined" as it can't be invoked with "new" */
ecma_object_t *old_new_target = JERRY_CONTEXT (current_new_target);
JERRY_CONTEXT (current_new_target) = NULL;
ecma_value_t result = vm_execute (&executable_object_p->frame_ctx);
JERRY_CONTEXT (current_new_target) = old_new_target;
executable_object_p->extended_object.u.class_prop.extra_info &= (uint16_t) ~ECMA_EXECUTABLE_OBJECT_RUNNING;
if (executable_object_p->frame_ctx.call_operation != VM_EXEC_RETURN)
+15
View File
@@ -2137,6 +2137,21 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
*stack_top_p++ = ecma_copy_value (collection_p->buffer_p[tagged_idx]);
continue;
}
case VM_OC_PUSH_NEW_TARGET:
{
ecma_object_t *new_target_object = JERRY_CONTEXT (current_new_target);
if (new_target_object == NULL)
{
*stack_top_p++ = ECMA_VALUE_UNDEFINED;
}
else
{
JERRY_ASSERT (new_target_object != JERRY_CONTEXT_INVALID_NEW_TARGET);
ecma_ref_object (new_target_object);
*stack_top_p++ = ecma_make_object_value (new_target_object);
}
continue;
}
#endif /* ENABLED (JERRY_ES2015) */
case VM_OC_PUSH_ELISON:
{
+2
View File
@@ -261,6 +261,7 @@ typedef enum
VM_OC_RETURN_PROMISE, /**< return from an async function */
VM_OC_STRING_CONCAT, /**< string concatenation */
VM_OC_GET_TEMPLATE_OBJECT, /**< GetTemplateObject operation */
VM_OC_PUSH_NEW_TARGET, /**< push new.target onto the stack */
#endif /* ENABLED (JERRY_ES2015) */
VM_OC_NONE, /**< a special opcode for unsupported byte codes */
} vm_oc_types;
@@ -317,6 +318,7 @@ typedef enum
VM_OC_RETURN_PROMISE = VM_OC_NONE, /**< return from an async function */
VM_OC_STRING_CONCAT = VM_OC_NONE, /**< string concatenation */
VM_OC_GET_TEMPLATE_OBJECT = VM_OC_NONE, /**< GetTemplateObject operation */
VM_OC_PUSH_NEW_TARGET = VM_OC_NONE, /**< push new.target onto the stack */
#endif /* !ENABLED (JERRY_ES2015) */
VM_OC_UNUSED = VM_OC_NONE /**< placeholder if the list is empty */