-
Notifications
You must be signed in to change notification settings - Fork 683
Check error values in API functions #1167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ static jerry_flag_t jerry_flags; | |
*/ | ||
static bool jerry_api_available; | ||
|
||
static const jerry_char_t *error_value_msg_p = (const jerry_char_t *) "argument cannot have an error flag"; | ||
|
||
/** \addtogroup jerry_extension Jerry engine extension interface | ||
* @{ | ||
*/ | ||
|
@@ -542,13 +544,18 @@ jerry_create_array_object (jerry_size_t size) /**< size of array */ | |
* Set value of field in the specified array object | ||
* | ||
* @return true, if field value was set successfully | ||
* throw exception, otherwise | ||
* false, otherwise | ||
*/ | ||
bool | ||
jerry_set_array_index_value (jerry_object_t *array_obj_p, /**< array object */ | ||
jerry_length_t index, /**< index to be written */ | ||
jerry_value_t value) /**< value to set */ | ||
{ | ||
if (ECMA_IS_VALUE_ERROR (value)) | ||
{ | ||
return false; | ||
} | ||
|
||
ecma_string_t *str_idx_p = ecma_new_ecma_string_from_uint32 ((uint32_t) index); | ||
ecma_value_t set_completion = ecma_op_object_put (array_obj_p, str_idx_p, value, false); | ||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (set_completion)); | ||
|
@@ -857,6 +864,11 @@ jerry_add_object_field (jerry_object_t *object_p, /**< object to add field at */ | |
{ | ||
jerry_assert_api_available (); | ||
|
||
if (ECMA_IS_VALUE_ERROR (field_value)) | ||
{ | ||
return false; | ||
} | ||
|
||
bool is_successful = false; | ||
|
||
if (ecma_get_object_extensible (object_p)) | ||
|
@@ -1053,6 +1065,11 @@ jerry_set_object_field_value_sz (jerry_object_t *object_p, /**< object */ | |
{ | ||
jerry_assert_api_available (); | ||
|
||
if (ECMA_IS_VALUE_ERROR (field_value)) | ||
{ | ||
return false; | ||
} | ||
|
||
bool is_successful = true; | ||
|
||
ecma_string_t *field_name_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) field_name_p, | ||
|
@@ -1235,6 +1252,14 @@ jerry_call_function (jerry_object_t *function_object_p, /**< function object to | |
{ | ||
jerry_assert_api_available (); | ||
|
||
for (uint16_t i = 0; i < args_count; i++) | ||
{ | ||
if (ECMA_IS_VALUE_ERROR (args_p[i])) | ||
{ | ||
return jerry_create_object_value (jerry_create_error (JERRY_ERROR_TYPE, error_value_msg_p)); | ||
} | ||
} | ||
|
||
if (jerry_is_function (function_object_p)) | ||
{ | ||
return jerry_invoke_function (false, function_object_p, this_arg_p, args_p, args_count); | ||
|
@@ -1260,6 +1285,14 @@ jerry_construct_object (jerry_object_t *function_object_p, /**< function object | |
{ | ||
jerry_assert_api_available (); | ||
|
||
for (uint16_t i = 0; i < args_count; i++) | ||
{ | ||
if (ECMA_IS_VALUE_ERROR (args_p[i])) | ||
{ | ||
return jerry_create_object_value (jerry_create_error (JERRY_ERROR_TYPE, error_value_msg_p)); | ||
} | ||
} | ||
|
||
if (jerry_is_constructor (function_object_p)) | ||
{ | ||
return jerry_invoke_function (true, function_object_p, NULL, args_p, args_count); | ||
|
@@ -2115,6 +2148,11 @@ jerry_value_to_boolean (const jerry_value_t value) /**< input value */ | |
{ | ||
jerry_assert_api_available (); | ||
|
||
if (ECMA_IS_VALUE_ERROR (value)) | ||
{ | ||
return false; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a value with error flag has a logical value. Or you do this for consistency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Come to think of it, this is not a conversion, so even the internal api has a wrong name. Hence the value is not converted to boolen (e.g. a Boolean object is always true) so perhaps we need another conversion routine.
I would change this function to jerry_get_logical_value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, this should be ToBoolean function of the standard: http://www.ecma-international.org/ecma-262/5.1/index.html#sec-9.2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
return ecma_op_to_boolean (value); | ||
} /* jerry_value_to_boolean */ | ||
|
||
|
@@ -2132,6 +2170,11 @@ jerry_value_to_number (const jerry_value_t value) /**< input value */ | |
{ | ||
jerry_assert_api_available (); | ||
|
||
if (ECMA_IS_VALUE_ERROR (value)) | ||
{ | ||
return jerry_create_object_value (jerry_create_error (JERRY_ERROR_TYPE, error_value_msg_p)); | ||
} | ||
|
||
return ecma_op_to_number (value); | ||
} /* jerry_value_to_number */ | ||
|
||
|
@@ -2149,6 +2192,11 @@ jerry_value_to_object (const jerry_value_t value) /**< input value */ | |
{ | ||
jerry_assert_api_available (); | ||
|
||
if (ECMA_IS_VALUE_ERROR (value)) | ||
{ | ||
return jerry_create_object_value (jerry_create_error (JERRY_ERROR_TYPE, error_value_msg_p)); | ||
} | ||
|
||
return ecma_op_to_object (value); | ||
} /* jerry_value_to_object */ | ||
|
||
|
@@ -2166,9 +2214,26 @@ jerry_value_to_string (const jerry_value_t value) /**< input value */ | |
{ | ||
jerry_assert_api_available (); | ||
|
||
if (ECMA_IS_VALUE_ERROR (value)) | ||
{ | ||
return jerry_create_object_value (jerry_create_error (JERRY_ERROR_TYPE, error_value_msg_p)); | ||
} | ||
|
||
return ecma_op_to_string (value); | ||
} /* jerry_value_to_string */ | ||
|
||
/** | ||
* Remove the error flag | ||
* | ||
* @return converted normal value, if value is error | ||
* unchanged value otherwise | ||
*/ | ||
jerry_value_t | ||
jerry_value_remove_error_flag (const jerry_value_t value) | ||
{ | ||
return (jerry_value_t) (value & ~ECMA_VALUE_ERROR_FLAG); | ||
} /* jerry_value_remove_error_flag */ | ||
|
||
/** | ||
* Get size of Jerry string | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the "throw exception, otherwise" comment above is incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed