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:
@@ -26,10 +26,9 @@
|
||||
|
||||
#define DELCARE_HANDLER(NAME) \
|
||||
static jerry_value_t \
|
||||
NAME ## _handler (const jerry_value_t function_obj_val __UNUSED__, \
|
||||
const jerry_value_t this_val __UNUSED__, \
|
||||
const jerry_value_t args_p[], \
|
||||
const jerry_length_t args_cnt)
|
||||
NAME ## _handler (const jerry_call_info_t *call_info_p __UNUSED__, \
|
||||
const jerry_value_t args_p[], \
|
||||
const jerry_length_t args_cnt)
|
||||
|
||||
#define REGISTER_HANDLER(NAME) \
|
||||
register_native_function ( # NAME, NAME ## _handler)
|
||||
|
||||
@@ -47,7 +47,7 @@ DECLARE_CLASS_FUNCTION(AnalogIn, read) {
|
||||
|
||||
// Extract native AnalogIn pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -72,7 +72,7 @@ DECLARE_CLASS_FUNCTION(AnalogIn, read_u16) {
|
||||
|
||||
// Extract native AnalogIn pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
|
||||
@@ -50,7 +50,7 @@ DECLARE_CLASS_FUNCTION(DigitalOut, write) {
|
||||
|
||||
// Extract native DigitalOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -77,7 +77,7 @@ DECLARE_CLASS_FUNCTION(DigitalOut, read) {
|
||||
|
||||
// Extract native DigitalOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -101,7 +101,7 @@ DECLARE_CLASS_FUNCTION(DigitalOut, is_connected) {
|
||||
|
||||
// Extract native DigitalOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
|
||||
@@ -49,7 +49,7 @@ DECLARE_CLASS_FUNCTION(I2C, frequency) {
|
||||
|
||||
// Unwrap native I2C object
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -91,7 +91,7 @@ DECLARE_CLASS_FUNCTION(I2C, read) {
|
||||
if (args_count == 1) {
|
||||
CHECK_ARGUMENT_TYPE_ALWAYS(I2C, read, 0, number);
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -112,7 +112,7 @@ DECLARE_CLASS_FUNCTION(I2C, read) {
|
||||
CHECK_ARGUMENT_TYPE_ON_CONDITION(I2C, read, 3, boolean, (args_count == 4));
|
||||
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -186,7 +186,7 @@ DECLARE_CLASS_FUNCTION(I2C, write) {
|
||||
|
||||
// Extract native I2C object
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -209,7 +209,7 @@ DECLARE_CLASS_FUNCTION(I2C, write) {
|
||||
|
||||
// Extract native I2C object
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -249,7 +249,7 @@ DECLARE_CLASS_FUNCTION(I2C, start) {
|
||||
|
||||
// Extract native I2C object
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -272,7 +272,7 @@ DECLARE_CLASS_FUNCTION(I2C, stop) {
|
||||
|
||||
// Extract native I2C object
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
|
||||
+11
-11
@@ -53,7 +53,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, rise) {
|
||||
// Detach the rise callback when InterruptIn::rise(null) is called
|
||||
if (jerry_value_is_null(args[0])) {
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -63,7 +63,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, rise) {
|
||||
InterruptIn *native_ptr = static_cast<InterruptIn*>(void_ptr);
|
||||
|
||||
jerry_value_t property_name = jerry_create_string((const jerry_char_t*)"cb_rise");
|
||||
jerry_value_t cb_func = jerry_get_property(this_obj, property_name);
|
||||
jerry_value_t cb_func = jerry_get_property(call_info_p->this_value, property_name);
|
||||
jerry_release_value(property_name);
|
||||
|
||||
// Only drop the callback if it exists
|
||||
@@ -82,7 +82,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, rise) {
|
||||
CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, rise, 0, function);
|
||||
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -99,7 +99,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, rise) {
|
||||
|
||||
// Keep track of our callback internally.
|
||||
jerry_value_t property_name = jerry_create_string((const jerry_char_t*)"cb_rise");
|
||||
jerry_release_value(jerry_set_property(this_obj, property_name, f));
|
||||
jerry_release_value(jerry_set_property(call_info_p->this_value, property_name, f));
|
||||
jerry_release_value(property_name);
|
||||
|
||||
return jerry_create_undefined();
|
||||
@@ -118,7 +118,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, fall) {
|
||||
// Detach the fall callback when InterruptIn::fall(null) is called
|
||||
if (jerry_value_is_null(args[0])) {
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -128,7 +128,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, fall) {
|
||||
InterruptIn *native_ptr = static_cast<InterruptIn*>(void_ptr);
|
||||
|
||||
jerry_value_t property_name = jerry_create_string((const jerry_char_t*)"cb_fall");
|
||||
jerry_value_t cb_func = jerry_get_property(this_obj, property_name);
|
||||
jerry_value_t cb_func = jerry_get_property(call_info_p->this_value, property_name);
|
||||
jerry_release_value(property_name);
|
||||
|
||||
// Only drop the callback if it exists
|
||||
@@ -147,7 +147,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, fall) {
|
||||
CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, fall, 0, function);
|
||||
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -164,7 +164,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, fall) {
|
||||
|
||||
// Keep track of our callback internally.
|
||||
jerry_value_t property_name = jerry_create_string((const jerry_char_t*)"cb_fall");
|
||||
jerry_release_value(jerry_set_property(this_obj, property_name, f));
|
||||
jerry_release_value(jerry_set_property(call_info_p->this_value, property_name, f));
|
||||
jerry_release_value(property_name);
|
||||
|
||||
return jerry_create_undefined();
|
||||
@@ -182,7 +182,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, mode) {
|
||||
CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, mode, 0, number);
|
||||
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -206,7 +206,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, disable_irq) {
|
||||
CHECK_ARGUMENT_COUNT(InterruptIn, disable_irq, (args_count == 0));
|
||||
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -228,7 +228,7 @@ DECLARE_CLASS_FUNCTION(InterruptIn, enable_irq) {
|
||||
CHECK_ARGUMENT_COUNT(InterruptIn, enable_irq, (args_count == 0));
|
||||
|
||||
void *void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
|
||||
@@ -52,7 +52,7 @@ DECLARE_CLASS_FUNCTION(PwmOut, write) {
|
||||
|
||||
// Extract native PwmOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -85,7 +85,7 @@ DECLARE_CLASS_FUNCTION(PwmOut, read) {
|
||||
|
||||
// Extract native PwmOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -113,7 +113,7 @@ DECLARE_CLASS_FUNCTION(PwmOut, period) {
|
||||
|
||||
// Extract native PwmOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -139,7 +139,7 @@ DECLARE_CLASS_FUNCTION(PwmOut, period_ms) {
|
||||
|
||||
// Extract native PwmOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -165,7 +165,7 @@ DECLARE_CLASS_FUNCTION(PwmOut, period_us) {
|
||||
|
||||
// Extract native PwmOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -191,7 +191,7 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth) {
|
||||
|
||||
// Extract native PwmOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -217,7 +217,7 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth_ms) {
|
||||
|
||||
// Extract native PwmOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
@@ -243,7 +243,7 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth_us) {
|
||||
|
||||
// Extract native PwmOut pointer
|
||||
void* void_ptr;
|
||||
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
|
||||
bool has_ptr = jerry_get_object_native_pointer(call_info_p->this_value, &void_ptr, &native_obj_type_info);
|
||||
|
||||
if (!has_ptr) {
|
||||
return jerry_create_error(JERRY_ERROR_TYPE,
|
||||
|
||||
@@ -32,7 +32,7 @@ DECLARE_GLOBAL_FUNCTION(setInterval) {
|
||||
|
||||
int id = mbed::js::EventLoop::getInstance().getQueue().call_every(interval, jerry_call_function, args[0], jerry_create_null(), (jerry_value_t*)NULL, 0);
|
||||
|
||||
jerry_value_t result = jerry_set_property_by_index(function_obj_p, id, args[0]);
|
||||
jerry_value_t result = jerry_set_property_by_index(call_info_p->function, id, args[0]);
|
||||
|
||||
if (jerry_value_is_error(result)) {
|
||||
jerry_release_value(result);
|
||||
|
||||
@@ -32,7 +32,7 @@ DECLARE_GLOBAL_FUNCTION(setTimeout) {
|
||||
|
||||
int id = mbed::js::EventLoop::getInstance().getQueue().call_in(interval, jerry_call_function, args[0], jerry_create_null(), (jerry_value_t*)NULL, 0);
|
||||
|
||||
jerry_value_t result = jerry_set_property_by_index(function_obj_p, id, args[0]);
|
||||
jerry_value_t result = jerry_set_property_by_index(call_info_p->function, id, args[0]);
|
||||
|
||||
if (jerry_value_is_error(result)) {
|
||||
jerry_release_value(result);
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
// Global functions
|
||||
#define DECLARE_GLOBAL_FUNCTION(NAME) \
|
||||
jerry_value_t \
|
||||
NAME_FOR_GLOBAL_FUNCTION(NAME) (const jerry_value_t function_obj_p, \
|
||||
const jerry_value_t this_obj, \
|
||||
NAME_FOR_GLOBAL_FUNCTION(NAME) (const jerry_call_info_t *call_info_p, \
|
||||
const jerry_value_t args[], \
|
||||
const jerry_length_t args_count)
|
||||
|
||||
@@ -43,8 +42,7 @@ NAME_FOR_GLOBAL_FUNCTION(NAME) (const jerry_value_t function_obj_p, \
|
||||
// Class constructors
|
||||
#define DECLARE_CLASS_CONSTRUCTOR(CLASS) \
|
||||
jerry_value_t \
|
||||
NAME_FOR_CLASS_CONSTRUCTOR(CLASS) (const jerry_value_t function_obj, \
|
||||
const jerry_value_t this_obj, \
|
||||
NAME_FOR_CLASS_CONSTRUCTOR(CLASS) (const jerry_call_info_t *call_info_p, \
|
||||
const jerry_value_t args[], \
|
||||
const jerry_length_t args_count)
|
||||
|
||||
@@ -54,8 +52,7 @@ NAME_FOR_CLASS_CONSTRUCTOR(CLASS) (const jerry_value_t function_obj, \
|
||||
// Class functions
|
||||
#define DECLARE_CLASS_FUNCTION(CLASS, NAME) \
|
||||
jerry_value_t \
|
||||
NAME_FOR_CLASS_FUNCTION(CLASS, NAME) (const jerry_value_t function_obj, \
|
||||
const jerry_value_t this_obj, \
|
||||
NAME_FOR_CLASS_FUNCTION(CLASS, NAME) (const jerry_call_info_t *call_info_p, \
|
||||
const jerry_value_t args[], \
|
||||
const jerry_length_t args_count)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user