Rework external function handlers (#4599)

Instead of a fixed number of arguments, a call info structure is passed
to the handlers, which can be extended in the future without breaknig the
API. This structure holds new.target value, so its getter function is removed.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-02-17 17:52:19 +01:00
committed by GitHub
parent 488a0bf7e8
commit 112ad83aaa
51 changed files with 322 additions and 586 deletions
+6 -10
View File
@@ -214,8 +214,7 @@ The `api-example-4.c` file should contain the following code:
#include "jerryscript.h"
static jerry_value_t
print_handler (const jerry_value_t function_object,
const jerry_value_t function_this,
print_handler (const jerry_call_info_t *call_info_p,
const jerry_value_t arguments[],
const jerry_length_t argument_count)
{
@@ -316,8 +315,7 @@ The `api-example-5.c` file should contain the following code:
#include "jerryscript.h"
static jerry_value_t
print_handler (const jerry_value_t function_object,
const jerry_value_t function_this,
print_handler (const jerry_call_info_t *call_info_p,
const jerry_value_t arguments[],
const jerry_length_t arguments_count)
{
@@ -851,8 +849,7 @@ struct my_struct
* Get a string from a native object
*/
static jerry_value_t
get_msg_handler (const jerry_value_t func_value, /**< function object */
const jerry_value_t this_value, /**< this arg */
get_msg_handler (const jerry_call_info_t *call_info_p, /**< call information */
const jerry_value_t *args_p, /**< function arguments */
const jerry_length_t args_cnt) /**< number of function arguments */
{
@@ -955,8 +952,7 @@ Use the following code for `api-example-10.c`:
* Add param to 'this.x'
*/
static jerry_value_t
add_handler (const jerry_value_t func_value, /**< function object */
const jerry_value_t this_val, /**< this arg */
add_handler (const jerry_call_info_t *call_info_p, /**< call information */
const jerry_value_t args_p[], /**< function arguments */
const jerry_length_t args_cnt) /**< number of function arguments */
{
@@ -965,7 +961,7 @@ add_handler (const jerry_value_t func_value, /**< function object */
/* Get 'this.x' */
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "x");
jerry_value_t x_val = jerry_get_property (this_val, prop_name);
jerry_value_t x_val = jerry_get_property (call_info_p->this_value, prop_name);
if (!jerry_value_is_error (x_val))
{
@@ -977,7 +973,7 @@ add_handler (const jerry_value_t func_value, /**< function object */
jerry_value_t res_val = jerry_create_number (x + d);
/* Set the new value of 'this.x' */
jerry_release_value (jerry_set_property (this_val, prop_name, res_val));
jerry_release_value (jerry_set_property (call_info_p->this_value, prop_name, res_val));
jerry_release_value (res_val);
}