Allow the JS objects to have more than one native pointer data (#2814)

Currently JS objects can only have one native pointer data which could be a limitation in special cases.
This patch allows to register multiple native infos, which can be accessed/associated with the corresponding `jerry_object_native_info_t`.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2019-04-16 07:50:49 +02:00
committed by László Langó
parent c818930cdc
commit b3f4aa6816
14 changed files with 436 additions and 180 deletions
@@ -47,10 +47,9 @@ DECLARE_CLASS_FUNCTION(AnalogIn, read) {
// Extract native AnalogIn pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native AnalogIn pointer");
}
@@ -73,10 +72,9 @@ DECLARE_CLASS_FUNCTION(AnalogIn, read_u16) {
// Extract native AnalogIn pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native AnalogIn pointer");
}
@@ -50,10 +50,9 @@ DECLARE_CLASS_FUNCTION(DigitalOut, write) {
// Extract native DigitalOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native DigitalOut pointer");
}
@@ -78,10 +77,9 @@ DECLARE_CLASS_FUNCTION(DigitalOut, read) {
// Extract native DigitalOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native DigitalOut pointer");
}
@@ -103,10 +101,9 @@ DECLARE_CLASS_FUNCTION(DigitalOut, is_connected) {
// Extract native DigitalOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native DigitalOut pointer");
}
@@ -49,10 +49,9 @@ DECLARE_CLASS_FUNCTION(I2C, frequency) {
// Unwrap native I2C object
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native I2C pointer");
}
@@ -92,10 +91,9 @@ DECLARE_CLASS_FUNCTION(I2C, read) {
if (args_count == 1) {
CHECK_ARGUMENT_TYPE_ALWAYS(I2C, read, 0, number);
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native I2C pointer");
}
@@ -114,10 +112,9 @@ DECLARE_CLASS_FUNCTION(I2C, read) {
CHECK_ARGUMENT_TYPE_ON_CONDITION(I2C, read, 3, boolean, (args_count == 4));
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native I2C pointer");
}
@@ -189,10 +186,9 @@ DECLARE_CLASS_FUNCTION(I2C, write) {
// Extract native I2C object
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native I2C pointer");
}
@@ -213,10 +209,9 @@ DECLARE_CLASS_FUNCTION(I2C, write) {
// Extract native I2C object
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native I2C pointer");
}
@@ -254,10 +249,9 @@ DECLARE_CLASS_FUNCTION(I2C, start) {
// Extract native I2C object
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native I2C pointer");
}
@@ -278,10 +272,9 @@ DECLARE_CLASS_FUNCTION(I2C, stop) {
// Extract native I2C object
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native I2C pointer");
}
@@ -53,10 +53,9 @@ 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;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native InterruptIn pointer");
}
@@ -83,10 +82,9 @@ DECLARE_CLASS_FUNCTION(InterruptIn, rise) {
CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, rise, 0, function);
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native InterruptIn pointer");
}
@@ -120,10 +118,9 @@ 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;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native InterruptIn pointer");
}
@@ -150,10 +147,9 @@ DECLARE_CLASS_FUNCTION(InterruptIn, fall) {
CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, fall, 0, function);
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native InterruptIn pointer");
}
@@ -186,10 +182,9 @@ DECLARE_CLASS_FUNCTION(InterruptIn, mode) {
CHECK_ARGUMENT_TYPE_ALWAYS(InterruptIn, mode, 0, number);
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native InterruptIn pointer");
}
@@ -211,10 +206,9 @@ DECLARE_CLASS_FUNCTION(InterruptIn, disable_irq) {
CHECK_ARGUMENT_COUNT(InterruptIn, disable_irq, (args_count == 0));
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native InterruptIn pointer");
}
@@ -234,10 +228,9 @@ DECLARE_CLASS_FUNCTION(InterruptIn, enable_irq) {
CHECK_ARGUMENT_COUNT(InterruptIn, enable_irq, (args_count == 0));
void *void_ptr;
const jerry_object_native_info_t *type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native InterruptIn pointer");
}
@@ -52,10 +52,9 @@ DECLARE_CLASS_FUNCTION(PwmOut, write) {
// Extract native PwmOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native PwmOut pointer");
}
@@ -86,10 +85,9 @@ DECLARE_CLASS_FUNCTION(PwmOut, read) {
// Extract native PwmOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native PwmOut pointer");
}
@@ -115,10 +113,9 @@ DECLARE_CLASS_FUNCTION(PwmOut, period) {
// Extract native PwmOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native PwmOut pointer");
}
@@ -142,10 +139,9 @@ DECLARE_CLASS_FUNCTION(PwmOut, period_ms) {
// Extract native PwmOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native PwmOut pointer");
}
@@ -169,10 +165,9 @@ DECLARE_CLASS_FUNCTION(PwmOut, period_us) {
// Extract native PwmOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native PwmOut pointer");
}
@@ -196,10 +191,9 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth) {
// Extract native PwmOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native PwmOut pointer");
}
@@ -223,10 +217,9 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth_ms) {
// Extract native PwmOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native PwmOut pointer");
}
@@ -250,10 +243,9 @@ DECLARE_CLASS_FUNCTION(PwmOut, pulsewidth_us) {
// Extract native PwmOut pointer
void* void_ptr;
const jerry_object_native_info_t* type_ptr;
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr);
bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &native_obj_type_info);
if (!has_ptr || type_ptr != &native_obj_type_info) {
if (!has_ptr) {
return jerry_create_error(JERRY_ERROR_TYPE,
(const jerry_char_t *) "Failed to get native PwmOut pointer");
}