Improve support for built-in native handlers (#4184)

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-09-17 18:35:11 +02:00
committed by GitHub
parent f4af997935
commit 74f66879c2
18 changed files with 552 additions and 351 deletions
@@ -0,0 +1,61 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecma-globals.h"
#if ENABLED (JERRY_ESNEXT)
#include "ecma-builtin-handlers.h"
#include "ecma-promise-object.h"
static const ecma_native_handler_t ecma_native_handlers[] =
{
#define ECMA_NATIVE_HANDLER(id, handler, length) handler,
#include "ecma-builtin-handlers.inc.h"
#undef ECMA_NATIVE_HANDLER
};
static const uint8_t ecma_native_handler_lengths[] =
{
#define ECMA_NATIVE_HANDLER(id, handler, length) length,
#include "ecma-builtin-handlers.inc.h"
#undef ECMA_NATIVE_HANDLER
};
/**
* Get the native handler of a built-in handler type.
*
* return Function pointer of the handler
*/
ecma_native_handler_t
ecma_builtin_handler_get (ecma_native_handler_id_t id) /**< handler id */
{
JERRY_ASSERT (id < ECMA_NATIVE_HANDLER__COUNT);
return ecma_native_handlers[id];
} /* ecma_builtin_handler_get */
/**
* Get the initial 'length' value of a built-in handler type.
*
* return 'length' value of the handler
*/
uint8_t
ecma_builtin_handler_get_length (ecma_native_handler_id_t id) /**< handler id */
{
JERRY_ASSERT (id < ECMA_NATIVE_HANDLER__COUNT);
return ecma_native_handler_lengths[id];
} /* ecma_builtin_handler_get_length */
#endif /* ENABLED (JERRY_ESNEXT) */
@@ -0,0 +1,51 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ECMA_BUILTIN_HANDLERS_H
#define ECMA_BUILTIN_HANDLERS_H
#include "ecma-globals.h"
#if ENABLED (JERRY_ESNEXT)
#include "ecma-helpers.h"
#include "ecma-builtins.h"
#include "ecma-promise-object.h"
#include "ecma-proxy-object.h"
typedef enum
{
#define ECMA_NATIVE_HANDLER(id, handler, length) id,
#include "ecma-builtin-handlers.inc.h"
#undef ECMA_NATIVE_HANDLER
ECMA_NATIVE_HANDLER__COUNT
} ecma_native_handler_id_t;
typedef enum
{
ECMA_NATIVE_HANDLER_FLAGS_NONE = 0,
ECMA_NATIVE_HANDLER_FLAGS_NAME_INITIALIZED = (1 << 0),
ECMA_NATIVE_HANDLER_FLAGS_LENGTH_INITIALIZED = (1 << 1),
ECMA_NATIVE_HANDLER_FLAGS_PROMISE_ALREADY_RESOLVED = (1 << 2),
} ecma_native_handler_flags_t;
ecma_native_handler_t
ecma_builtin_handler_get (ecma_native_handler_id_t id);
uint8_t
ecma_builtin_handler_get_length (ecma_native_handler_id_t id);
#endif /* ENABLED (JERRY_ESNEXT) */
#endif /* !ECMA_BUILTIN_HANDLERS_H */
@@ -0,0 +1,24 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_RESOLVE, ecma_promise_resolve_handler, 1)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_REJECT, ecma_promise_reject_handler, 1)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_THEN_FINALLY, ecma_promise_then_finally_cb, 1)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_CATCH_FINALLY, ecma_promise_catch_finally_cb, 1)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER, ecma_promise_all_handler_cb, 1)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROMISE_CAPABILITY_EXECUTOR, ecma_op_get_capabilities_executor_cb, 2)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_PROXY_REVOKE, ecma_proxy_revoke_cb, 0)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_VALUE_THUNK, ecma_value_thunk_helper_cb, 0)
ECMA_NATIVE_HANDLER (ECMA_NATIVE_HANDLER_VALUE_THROWER, ecma_value_thunk_thrower_cb, 0)
@@ -16,6 +16,7 @@
#include "ecma-alloc.h"
#include "ecma-array-object.h"
#include "ecma-builtin-helpers.h"
#include "ecma-builtin-handlers.h"
#include "ecma-exceptions.h"
#include "ecma-function-object.h"
#include "ecma-gc.h"
@@ -294,22 +295,18 @@ ecma_builtin_promise_perform_all (ecma_value_t iterator, /**< iteratorRecord */
break;
}
/* k. */
ecma_object_t *executor_func_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE),
sizeof (ecma_promise_all_executor_t),
ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION);
ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) executor_func_p;
executor_p->header.u.external_handler_cb = ecma_promise_all_handler_cb;
/* l. */
if (JERRY_UNLIKELY (idx == UINT32_MAX - 1))
{
ecma_deref_object (executor_func_p);
ecma_raise_range_error (ECMA_ERR_MSG ("Promise.all remaining elements limit reached."));
break;
}
/* k. */
ecma_object_t *executor_func_p = ecma_op_create_native_handler (ECMA_NATIVE_HANDLER_PROMISE_ALL_HELPER,
sizeof (ecma_promise_all_executor_t));
ecma_promise_all_executor_t *executor_p = (ecma_promise_all_executor_t *) executor_func_p;
/* m. + t. */
executor_p->index = ++idx;