Support parsing async modifiers for functions. (#3460)
Only parsing is implemented, so the async functions currently behave like normal function except they return with a resolved Promise object when the function is terminated correctly. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "ecma-iterator-object.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-promise-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jcontext.h"
|
||||
#include "opcodes.h"
|
||||
@@ -706,6 +707,21 @@ opfunc_resume_executable_object (vm_executable_object_t *executable_object_p, /*
|
||||
return result;
|
||||
} /* opfunc_resume_executable_object */
|
||||
|
||||
/**
|
||||
* Create a Promise object if needed and resolve it with a value
|
||||
*
|
||||
* @return Promise object
|
||||
*/
|
||||
ecma_value_t
|
||||
opfunc_return_promise (ecma_value_t value) /**< value */
|
||||
{
|
||||
ecma_value_t promise = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_PROMISE));
|
||||
ecma_value_t result = ecma_promise_reject_or_resolve (promise, value, true);
|
||||
|
||||
ecma_free_value (value);
|
||||
return result;
|
||||
} /* opfunc_return_promise */
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
|
||||
@@ -115,6 +115,9 @@ opfunc_create_executable_object (vm_frame_ctx_t *frame_ctx_p);
|
||||
|
||||
ecma_value_t
|
||||
opfunc_resume_executable_object (vm_executable_object_t *executable_object_p, ecma_value_t value);
|
||||
|
||||
ecma_value_t
|
||||
opfunc_return_promise (ecma_value_t value);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
|
||||
+7
-1
@@ -2098,6 +2098,12 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
|
||||
goto error;
|
||||
}
|
||||
case VM_OC_RETURN_PROMISE:
|
||||
{
|
||||
result = opfunc_return_promise (left_value);
|
||||
left_value = ECMA_VALUE_UNDEFINED;
|
||||
goto error;
|
||||
}
|
||||
case VM_OC_STRING_CONCAT:
|
||||
{
|
||||
ecma_string_t *left_str_p = ecma_op_to_string (left_value);
|
||||
@@ -2131,7 +2137,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
*stack_top_p++ = ecma_copy_value (collection_p->buffer_p[tagged_idx]);
|
||||
continue;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
case VM_OC_PUSH_ELISON:
|
||||
{
|
||||
*stack_top_p++ = ECMA_VALUE_ARRAY_HOLE;
|
||||
|
||||
@@ -258,6 +258,7 @@ typedef enum
|
||||
VM_OC_CREATE_GENERATOR, /**< create a generator object */
|
||||
VM_OC_YIELD, /**< yield operation */
|
||||
VM_OC_EXT_RETURN, /**< return which also clears the stack */
|
||||
VM_OC_RETURN_PROMISE, /**< return from an async function */
|
||||
VM_OC_STRING_CONCAT, /**< string concatenation */
|
||||
VM_OC_GET_TEMPLATE_OBJECT, /**< GetTemplateObject operation */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
@@ -313,6 +314,7 @@ typedef enum
|
||||
VM_OC_CREATE_GENERATOR = VM_OC_NONE, /**< create a generator object */
|
||||
VM_OC_YIELD = VM_OC_NONE, /**< yield operation */
|
||||
VM_OC_EXT_RETURN = VM_OC_NONE, /**< return which also clears the stack */
|
||||
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 */
|
||||
#endif /* !ENABLED (JERRY_ES2015) */
|
||||
|
||||
Reference in New Issue
Block a user