@@ -124,6 +124,15 @@ jerry_make_api_unavailable (void)
124
124
jerry_api_available = false;
125
125
} /* jerry_make_api_unavailable */
126
126
127
+ /**
128
+ * Returns whether the given jerry_value_t is error.
129
+ */
130
+ bool
131
+ jerry_value_is_error (const jerry_value_t value ) /**< api value */
132
+ {
133
+ return ECMA_IS_VALUE_ERROR (value );
134
+ } /* jerry_value_is_error */
135
+
127
136
/**
128
137
* Returns whether the given jerry_value_t is null.
129
138
*/
@@ -310,10 +319,10 @@ jerry_create_string_value (jerry_string_t *str_p) /**< jerry_string_t from which
310
319
*
311
320
* @return completion code
312
321
*/
313
- inline static jerry_completion_code_t __attr_always_inline___
314
- jerry_convert_eval_completion_to_retval (jerry_value_t * retval_p , /**< [out] api value */
315
- ecma_value_t completion ) /**< completion of 'eval'-mode
322
+ static inline jerry_completion_code_t __attr_always_inline___
323
+ jerry_convert_eval_completion_to_retval (ecma_value_t completion , /**< completion of 'eval'-mode
316
324
* code execution */
325
+ jerry_value_t * retval_p ) /**< [out] api value */
317
326
{
318
327
* retval_p = completion ;
319
328
@@ -698,11 +707,9 @@ jerry_create_external_function (jerry_external_handler_t handler_p) /**< pointer
698
707
* Dispatch call to specified external function using the native handler
699
708
*
700
709
* Note:
701
- * if called native handler returns true, then dispatcher just returns value received
702
- * through 'return value' output argument, otherwise - throws the value as an exception.
710
+ * returned value should be freed with jerry_release_value.
703
711
*
704
- * @return ecma value
705
- * Returned value must be freed with ecma_free_value
712
+ * @return returned jerry value of the given function object
706
713
*/
707
714
ecma_value_t
708
715
jerry_dispatch_external_function (ecma_object_t * function_object_p , /**< external function object */
@@ -717,9 +724,9 @@ jerry_dispatch_external_function (ecma_object_t *function_object_p, /**< externa
717
724
718
725
bool is_successful = ((jerry_external_handler_t ) handler_p ) (function_object_p ,
719
726
this_arg_value ,
720
- & ret_value ,
721
727
arguments_list_p ,
722
- arguments_list_len );
728
+ arguments_list_len ,
729
+ & ret_value );
723
730
724
731
if (!is_successful )
725
732
{
@@ -879,14 +886,13 @@ jerry_delete_object_field (jerry_object_t *object_p, /**< object to delete field
879
886
* - there is field with specified name in the object;
880
887
* false - otherwise.
881
888
*/
882
- bool jerry_get_object_field_value ( jerry_object_t * object_p , /**< object */
883
- const jerry_char_t * field_name_p , /**< field name */
884
- jerry_value_t * field_value_p ) /**< [out] field value */
889
+ jerry_value_t
890
+ jerry_get_object_field_value ( jerry_object_t * object_p , /**< object */
891
+ const jerry_char_t * field_name_p ) /**< field name */
885
892
{
886
893
return jerry_get_object_field_value_sz (object_p ,
887
894
field_name_p ,
888
- lit_zt_utf8_string_size (field_name_p ),
889
- field_value_p );
895
+ lit_zt_utf8_string_size (field_name_p ));
890
896
} /* jerry_get_object_field_value */
891
897
892
898
/**
@@ -945,38 +951,32 @@ jerry_foreach_object_field (jerry_object_t *object_p, /**< object */
945
951
* Get value of field in the specified object
946
952
*
947
953
* Note:
948
- * if value was retrieved successfully, it should be freed
949
- * with jerry_release_value just when it becomes unnecessary.
954
+ * returned value should be freed with jerry_release_value.
950
955
*
951
- * @return true, if field value was retrieved successfully, i.e. upon the call:
952
- * - there is field with specified name in the object;
953
- * false - otherwise.
956
+ * @return jerry value of the given field
954
957
*/
955
- bool
958
+ jerry_value_t
956
959
jerry_get_object_field_value_sz (jerry_object_t * object_p , /**< object */
957
960
const jerry_char_t * field_name_p , /**< name of the field */
958
- jerry_size_t field_name_size , /**< size of field name in bytes */
959
- jerry_value_t * field_value_p ) /**< [out] field value, if retrieved successfully */
961
+ jerry_size_t field_name_size ) /**< size of field name in bytes */
960
962
{
961
963
jerry_assert_api_available ();
962
964
963
965
ecma_string_t * field_name_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t * ) field_name_p ,
964
966
(lit_utf8_size_t ) field_name_size );
965
967
966
- * field_value_p = ecma_op_object_get (object_p , field_name_str_p );
968
+ ecma_value_t field_value = ecma_op_object_get (object_p , field_name_str_p );
967
969
968
970
ecma_deref_ecma_string (field_name_str_p );
969
971
970
- return (!ECMA_IS_VALUE_ERROR (* field_value_p )
971
- && !ecma_is_value_undefined (* field_value_p ));
972
+ return field_value ;
972
973
} /* jerry_get_object_field_value_sz */
973
974
974
975
/**
975
976
* Set value of field in the specified object
976
977
*
977
- * @return true, if field value was set successfully, i.e. upon the call:
978
- * - field value is writable;
979
- * false - otherwise.
978
+ * @return true - if field value was set successfully
979
+ * false - otherwise
980
980
*/
981
981
bool
982
982
jerry_set_object_field_value (jerry_object_t * object_p , /**< object */
@@ -1100,11 +1100,9 @@ jerry_set_object_native_handle (jerry_object_t *object_p, /**< object to set han
1100
1100
* If function is invoked as constructor, it should support [[Construct]] method,
1101
1101
* otherwise, if function is simply called - it should support [[Call]] method.
1102
1102
*
1103
- * @return true, if invocation was performed successfully, i.e.:
1104
- * - no unhandled exceptions were thrown in connection with the call;
1105
- * false - otherwise.
1103
+ * @return returned jerry value of the given function object
1106
1104
*/
1107
- static bool
1105
+ static jerry_value_t
1108
1106
jerry_invoke_function (bool is_invoke_as_constructor , /**< true - invoke function as constructor
1109
1107
* (this_arg_p should be NULL, as it is ignored),
1110
1108
* false - perform function call */
@@ -1114,9 +1112,6 @@ jerry_invoke_function (bool is_invoke_as_constructor, /**< true - invoke functio
1114
1112
* if function is invoked as constructor;
1115
1113
* in case of simple function call set 'this'
1116
1114
* binding to the global object) */
1117
- jerry_value_t * retval_p , /**< pointer to place for function's
1118
- * return value / thrown exception value
1119
- * or NULL (to ignore the values) */
1120
1115
const jerry_value_t args_p [], /**< function's call arguments
1121
1116
* (NULL if arguments number is zero) */
1122
1117
jerry_length_t args_count ) /**< number of the arguments */
@@ -1125,8 +1120,6 @@ jerry_invoke_function (bool is_invoke_as_constructor, /**< true - invoke functio
1125
1120
JERRY_STATIC_ASSERT (sizeof (args_count ) == sizeof (ecma_length_t ),
1126
1121
size_of_args_count_must_be_equal_to_size_of_ecma_length_t );
1127
1122
1128
- bool is_successful = true;
1129
-
1130
1123
ecma_value_t call_completion ;
1131
1124
1132
1125
if (is_invoke_as_constructor )
@@ -1159,29 +1152,19 @@ jerry_invoke_function (bool is_invoke_as_constructor, /**< true - invoke functio
1159
1152
args_count );
1160
1153
}
1161
1154
1162
- if (ECMA_IS_VALUE_ERROR (call_completion ))
1163
- {
1164
- /* unhandled exception during the function call */
1165
- is_successful = false;
1166
- }
1167
-
1168
- if (retval_p != NULL )
1169
- {
1170
- * retval_p = call_completion ;
1171
- }
1172
-
1173
- return is_successful ;
1155
+ return call_completion ;
1174
1156
} /* jerry_invoke_function */
1175
1157
1176
1158
/**
1177
1159
* Construct new TypeError object
1160
+ *
1161
+ * @return TypeError object value
1178
1162
*/
1179
- static void
1180
- jerry_construct_type_error (jerry_value_t * retval_p ) /**< [out] value with constructed
1181
- * TypeError object */
1163
+ static jerry_value_t __attr_always_inline___
1164
+ jerry_construct_type_error (void )
1182
1165
{
1183
1166
ecma_object_t * type_error_obj_p = ecma_new_standard_error (ECMA_ERROR_TYPE );
1184
- * retval_p = ecma_make_object_value (type_error_obj_p );
1167
+ return ecma_make_error_obj_value (type_error_obj_p );
1185
1168
} /* jerry_construct_type_error */
1186
1169
1187
1170
/**
@@ -1191,20 +1174,12 @@ jerry_construct_type_error (jerry_value_t *retval_p) /**< [out] value with const
1191
1174
* returned value should be freed with jerry_release_value
1192
1175
* just when the value becomes unnecessary.
1193
1176
*
1194
- * @return true, if call was performed successfully, i.e.:
1195
- * - specified object is a function object (see also jerry_is_function);
1196
- * - no unhandled exceptions were thrown in connection with the call;
1197
- * false - otherwise, 'retval_p' contains thrown exception:
1198
- * if called object is not function object - a TypeError instance;
1199
- * else - exception, thrown during the function call.
1177
+ * @return returned jerry value of the given function object
1200
1178
*/
1201
- bool
1179
+ jerry_value_t
1202
1180
jerry_call_function (jerry_object_t * function_object_p , /**< function object to call */
1203
1181
jerry_object_t * this_arg_p , /**< object for 'this' binding
1204
1182
* or NULL (set 'this' binding to the global object) */
1205
- jerry_value_t * retval_p , /**< pointer to place for function's
1206
- * return value / thrown exception value
1207
- * or NULL (to ignore the values) */
1208
1183
const jerry_value_t args_p [], /**< function's call arguments
1209
1184
* (NULL if arguments number is zero) */
1210
1185
uint16_t args_count ) /**< number of the arguments */
@@ -1213,17 +1188,10 @@ jerry_call_function (jerry_object_t *function_object_p, /**< function object to
1213
1188
1214
1189
if (jerry_is_function (function_object_p ))
1215
1190
{
1216
- return jerry_invoke_function (false, function_object_p , this_arg_p , retval_p , args_p , args_count );
1191
+ return jerry_invoke_function (false, function_object_p , this_arg_p , args_p , args_count );
1217
1192
}
1218
- else
1219
- {
1220
- if (retval_p != NULL )
1221
- {
1222
- jerry_construct_type_error (retval_p );
1223
- }
1224
1193
1225
- return false;
1226
- }
1194
+ return jerry_construct_type_error ();
1227
1195
} /* jerry_call_function */
1228
1196
1229
1197
/**
@@ -1233,18 +1201,10 @@ jerry_call_function (jerry_object_t *function_object_p, /**< function object to
1233
1201
* returned value should be freed with jerry_release_value
1234
1202
* just when the value becomes unnecessary.
1235
1203
*
1236
- * @return true, if construction was performed successfully, i.e.:
1237
- * - specified object is a constructor function object (see also jerry_is_constructor);
1238
- * - no unhandled exceptions were thrown in connection with the invocation;
1239
- * false - otherwise, 'retval_p' contains thrown exception:
1240
- * if specified object is not a constructor function object - a TypeError instance;
1241
- * else - exception, thrown during the invocation.
1204
+ * @return returned jerry value of the given constructor
1242
1205
*/
1243
- bool
1206
+ jerry_value_t
1244
1207
jerry_construct_object (jerry_object_t * function_object_p , /**< function object to call */
1245
- jerry_value_t * retval_p , /**< pointer to place for function's
1246
- * return value / thrown exception value
1247
- * or NULL (to ignore the values) */
1248
1208
const jerry_value_t args_p [], /**< function's call arguments
1249
1209
* (NULL if arguments number is zero) */
1250
1210
uint16_t args_count ) /**< number of the arguments */
@@ -1253,17 +1213,10 @@ jerry_construct_object (jerry_object_t *function_object_p, /**< function object
1253
1213
1254
1214
if (jerry_is_constructor (function_object_p ))
1255
1215
{
1256
- return jerry_invoke_function (true, function_object_p , NULL , retval_p , args_p , args_count );
1216
+ return jerry_invoke_function (true, function_object_p , NULL , args_p , args_count );
1257
1217
}
1258
- else
1259
- {
1260
- if (retval_p != NULL )
1261
- {
1262
- jerry_construct_type_error (retval_p );
1263
- }
1264
1218
1265
- return false;
1266
- }
1219
+ return jerry_construct_type_error ();
1267
1220
} /* jerry_construct_object */
1268
1221
1269
1222
/**
@@ -1308,7 +1261,7 @@ jerry_eval (const jerry_char_t *source_p, /**< source code */
1308
1261
is_direct ,
1309
1262
is_strict );
1310
1263
1311
- status = jerry_convert_eval_completion_to_retval (retval_p , completion );
1264
+ status = jerry_convert_eval_completion_to_retval (completion , retval_p );
1312
1265
1313
1266
return status ;
1314
1267
} /* jerry_eval */
@@ -2088,7 +2041,7 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
2088
2041
/* vm should be already initialized */
2089
2042
ecma_value_t completion = vm_run_eval (bytecode_p , false);
2090
2043
2091
- ret_code = jerry_convert_eval_completion_to_retval (retval_p , completion );
2044
+ ret_code = jerry_convert_eval_completion_to_retval (completion , retval_p );
2092
2045
2093
2046
ecma_free_value (completion );
2094
2047
}
0 commit comments