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:
committed by
László Langó
parent
c818930cdc
commit
b3f4aa6816
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user