@@ -879,8 +879,8 @@ jerry_api_set_object_native_handle (jerry_api_object_t *object_p, /**< object to
879
879
* Invoke function specified by a function object
880
880
*
881
881
* Note:
882
- * if invocation was performed successfully, returned value should be freed
883
- * with jerry_api_release_value just when the value becomes unnecessary.
882
+ * returned value should be freed with jerry_api_release_value
883
+ * just when the value becomes unnecessary.
884
884
*
885
885
* Note:
886
886
* If function is invoked as constructor, it should support [[Construct]] method,
@@ -900,8 +900,9 @@ jerry_api_invoke_function (bool is_invoke_as_constructor, /**< true - invoke fun
900
900
* if function is invoked as constructor;
901
901
* in case of simple function call set 'this'
902
902
* binding to the global object) */
903
- jerry_api_value_t *retval_p, /* *< pointer to place for function's return value
904
- * or NULL (to ignore the return value) */
903
+ jerry_api_value_t *retval_p, /* *< pointer to place for function's
904
+ * return value / thrown exception value
905
+ * or NULL (to ignore the values) */
905
906
const jerry_api_value_t args_p[], /* *< function's call arguments
906
907
* (NULL if arguments number is zero) */
907
908
uint16_t args_count) /* *< number of the arguments */
@@ -950,28 +951,20 @@ jerry_api_invoke_function (bool is_invoke_as_constructor, /**< true - invoke fun
950
951
args_count);
951
952
}
952
953
953
- if (ecma_is_completion_value_normal (call_completion))
954
- {
955
- if (retval_p != NULL )
956
- {
957
- jerry_api_convert_ecma_value_to_api_value (retval_p,
958
- ecma_get_completion_value_value (call_completion));
959
- }
960
- }
961
- else
954
+ if (!ecma_is_completion_value_normal (call_completion))
962
955
{
963
956
/* unhandled exception during the function call */
964
-
965
957
JERRY_ASSERT (ecma_is_completion_value_throw (call_completion));
966
958
967
- if (retval_p != NULL )
968
- {
969
- jerry_api_convert_ecma_value_to_api_value (retval_p, ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
970
- }
971
-
972
959
is_successful = false ;
973
960
}
974
961
962
+ if (retval_p != NULL )
963
+ {
964
+ jerry_api_convert_ecma_value_to_api_value (retval_p,
965
+ ecma_get_completion_value_value (call_completion));
966
+ }
967
+
975
968
ecma_free_completion_value (call_completion);
976
969
977
970
for (uint32_t i = 0 ; i < args_count; i++)
@@ -984,24 +977,42 @@ jerry_api_invoke_function (bool is_invoke_as_constructor, /**< true - invoke fun
984
977
return is_successful;
985
978
} /* jerry_api_invoke_function */
986
979
980
+ /* *
981
+ * Construct new TypeError object
982
+ */
983
+ static void
984
+ jerry_api_construct_type_error (jerry_api_value_t *retval_p) /* *< out: value with constructed
985
+ * TypeError object */
986
+ {
987
+ ecma_object_t *type_error_obj_p = ecma_new_standard_error (ECMA_ERROR_TYPE);
988
+ ecma_value_t type_error_value = ecma_make_object_value (type_error_obj_p);
989
+
990
+ jerry_api_convert_ecma_value_to_api_value (retval_p, type_error_value);
991
+
992
+ ecma_deref_object (type_error_obj_p);
993
+ } /* jerry_api_construct_type_error */
994
+
987
995
/* *
988
996
* Call function specified by a function object
989
997
*
990
998
* Note:
991
- * if call was performed successfully, returned value should be freed
992
- * with jerry_api_release_value just when the value becomes unnecessary.
999
+ * returned value should be freed with jerry_api_release_value
1000
+ * just when the value becomes unnecessary.
993
1001
*
994
1002
* @return true, if call was performed successfully, i.e.:
995
1003
* - specified object is a function object (see also jerry_api_is_function);
996
1004
* - no unhandled exceptions were thrown in connection with the call;
997
- * false - otherwise.
1005
+ * false - otherwise, 'retval_p' contains thrown exception:
1006
+ * if called object is not function object - a TypeError instance;
1007
+ * else - exception, thrown during the function call.
998
1008
*/
999
1009
bool
1000
1010
jerry_api_call_function (jerry_api_object_t *function_object_p, /* *< function object to call */
1001
1011
jerry_api_object_t *this_arg_p, /* *< object for 'this' binding
1002
1012
* or NULL (set 'this' binding to the global object) */
1003
- jerry_api_value_t *retval_p, /* *< pointer to place for function's return value
1004
- * or NULL (to ignore the return value) */
1013
+ jerry_api_value_t *retval_p, /* *< pointer to place for function's
1014
+ * return value / thrown exception value
1015
+ * or NULL (to ignore the values) */
1005
1016
const jerry_api_value_t args_p[], /* *< function's call arguments
1006
1017
* (NULL if arguments number is zero) */
1007
1018
uint16_t args_count) /* *< number of the arguments */
@@ -1012,7 +1023,13 @@ jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function ob
1012
1023
{
1013
1024
return jerry_api_invoke_function (false , function_object_p, this_arg_p, retval_p, args_p, args_count);
1014
1025
}
1026
+ else
1015
1027
{
1028
+ if (retval_p != NULL )
1029
+ {
1030
+ jerry_api_construct_type_error (retval_p);
1031
+ }
1032
+
1016
1033
return false ;
1017
1034
}
1018
1035
} /* jerry_api_call_function */
@@ -1021,18 +1038,21 @@ jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function ob
1021
1038
* Construct object invoking specified function object as a constructor
1022
1039
*
1023
1040
* Note:
1024
- * if construction was performed successfully, returned value should be freed
1025
- * with jerry_api_release_value just when the value becomes unnecessary.
1041
+ * returned value should be freed with jerry_api_release_value
1042
+ * just when the value becomes unnecessary.
1026
1043
*
1027
1044
* @return true, if construction was performed successfully, i.e.:
1028
1045
* - specified object is a constructor function object (see also jerry_api_is_constructor);
1029
1046
* - no unhandled exceptions were thrown in connection with the invocation;
1030
- * false - otherwise.
1047
+ * false - otherwise, 'retval_p' contains thrown exception:
1048
+ * if specified object is not a constructor function object - a TypeError instance;
1049
+ * else - exception, thrown during the invocation.
1031
1050
*/
1032
1051
bool
1033
1052
jerry_api_construct_object (jerry_api_object_t *function_object_p, /* *< function object to call */
1034
- jerry_api_value_t *retval_p, /* *< pointer to place for function's return value
1035
- * or NULL (to ignore the return value) */
1053
+ jerry_api_value_t *retval_p, /* *< pointer to place for function's
1054
+ * return value / thrown exception value
1055
+ * or NULL (to ignore the values) */
1036
1056
const jerry_api_value_t args_p[], /* *< function's call arguments
1037
1057
* (NULL if arguments number is zero) */
1038
1058
uint16_t args_count) /* *< number of the arguments */
@@ -1045,6 +1065,11 @@ jerry_api_construct_object (jerry_api_object_t *function_object_p, /**< function
1045
1065
}
1046
1066
else
1047
1067
{
1068
+ if (retval_p != NULL )
1069
+ {
1070
+ jerry_api_construct_type_error (retval_p);
1071
+ }
1072
+
1048
1073
return false ;
1049
1074
}
1050
1075
} /* jerry_api_construct_object */
0 commit comments