@@ -866,8 +866,8 @@ jerry_api_set_object_native_handle (jerry_api_object_t *object_p, /**< object to
866
866
* Invoke function specified by a function object
867
867
*
868
868
* Note:
869
- * if invocation was performed successfully, returned value should be freed
870
- * with jerry_api_release_value just when the value becomes unnecessary.
869
+ * returned value should be freed with jerry_api_release_value
870
+ * just when the value becomes unnecessary.
871
871
*
872
872
* Note:
873
873
* If function is invoked as constructor, it should support [[Construct]] method,
@@ -887,8 +887,9 @@ jerry_api_invoke_function (bool is_invoke_as_constructor, /**< true - invoke fun
887
887
* if function is invoked as constructor;
888
888
* in case of simple function call set 'this'
889
889
* binding to the global object) */
890
- jerry_api_value_t *retval_p, /* *< pointer to place for function's return value
891
- * or NULL (to ignore the return value) */
890
+ jerry_api_value_t *retval_p, /* *< pointer to place for function's
891
+ * return value / thrown exception value
892
+ * or NULL (to ignore the values) */
892
893
const jerry_api_value_t args_p[], /* *< function's call arguments
893
894
* (NULL if arguments number is zero) */
894
895
uint16_t args_count) /* *< number of the arguments */
@@ -937,28 +938,20 @@ jerry_api_invoke_function (bool is_invoke_as_constructor, /**< true - invoke fun
937
938
args_count);
938
939
}
939
940
940
- if (ecma_is_completion_value_normal (call_completion))
941
- {
942
- if (retval_p != NULL )
943
- {
944
- jerry_api_convert_ecma_value_to_api_value (retval_p,
945
- ecma_get_completion_value_value (call_completion));
946
- }
947
- }
948
- else
941
+ if (!ecma_is_completion_value_normal (call_completion))
949
942
{
950
943
/* unhandled exception during the function call */
951
-
952
944
JERRY_ASSERT (ecma_is_completion_value_throw (call_completion));
953
945
954
- if (retval_p != NULL )
955
- {
956
- jerry_api_convert_ecma_value_to_api_value (retval_p, ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
957
- }
958
-
959
946
is_successful = false ;
960
947
}
961
948
949
+ if (retval_p != NULL )
950
+ {
951
+ jerry_api_convert_ecma_value_to_api_value (retval_p,
952
+ ecma_get_completion_value_value (call_completion));
953
+ }
954
+
962
955
ecma_free_completion_value (call_completion);
963
956
964
957
for (uint32_t i = 0 ; i < args_count; i++)
@@ -971,24 +964,42 @@ jerry_api_invoke_function (bool is_invoke_as_constructor, /**< true - invoke fun
971
964
return is_successful;
972
965
} /* jerry_api_invoke_function */
973
966
967
+ /* *
968
+ * Construct new TypeError object
969
+ */
970
+ static void
971
+ jerry_api_construct_type_error (jerry_api_value_t *retval_p) /* *< out: value with constructed
972
+ * TypeError object */
973
+ {
974
+ ecma_object_t *type_error_obj_p = ecma_new_standard_error (ECMA_ERROR_TYPE);
975
+ ecma_value_t type_error_value = ecma_make_object_value (type_error_obj_p);
976
+
977
+ jerry_api_convert_ecma_value_to_api_value (retval_p, type_error_value);
978
+
979
+ ecma_deref_object (type_error_obj_p);
980
+ } /* jerry_api_throw_type_error */
981
+
974
982
/* *
975
983
* Call function specified by a function object
976
984
*
977
985
* Note:
978
- * if call was performed successfully, returned value should be freed
979
- * with jerry_api_release_value just when the value becomes unnecessary.
986
+ * returned value should be freed with jerry_api_release_value
987
+ * just when the value becomes unnecessary.
980
988
*
981
989
* @return true, if call was performed successfully, i.e.:
982
990
* - specified object is a function object (see also jerry_api_is_function);
983
991
* - no unhandled exceptions were thrown in connection with the call;
984
- * false - otherwise.
992
+ * false - otherwise, 'retval_p' contains thrown exception:
993
+ * if called object is not function object - a TypeError instance;
994
+ * else - exception, thrown during the function call.
985
995
*/
986
996
bool
987
997
jerry_api_call_function (jerry_api_object_t *function_object_p, /* *< function object to call */
988
998
jerry_api_object_t *this_arg_p, /* *< object for 'this' binding
989
999
* or NULL (set 'this' binding to the global object) */
990
- jerry_api_value_t *retval_p, /* *< pointer to place for function's return value
991
- * or NULL (to ignore the return value) */
1000
+ jerry_api_value_t *retval_p, /* *< pointer to place for function's
1001
+ * return value / thrown exception value
1002
+ * or NULL (to ignore the values) */
992
1003
const jerry_api_value_t args_p[], /* *< function's call arguments
993
1004
* (NULL if arguments number is zero) */
994
1005
uint16_t args_count) /* *< number of the arguments */
@@ -999,7 +1010,13 @@ jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function ob
999
1010
{
1000
1011
return jerry_api_invoke_function (false , function_object_p, this_arg_p, retval_p, args_p, args_count);
1001
1012
}
1013
+ else
1002
1014
{
1015
+ if (retval_p != NULL )
1016
+ {
1017
+ jerry_api_construct_type_error (retval_p);
1018
+ }
1019
+
1003
1020
return false ;
1004
1021
}
1005
1022
} /* jerry_api_call_function */
@@ -1008,18 +1025,21 @@ jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function ob
1008
1025
* Construct object invoking specified function object as a constructor
1009
1026
*
1010
1027
* Note:
1011
- * if construction was performed successfully, returned value should be freed
1012
- * with jerry_api_release_value just when the value becomes unnecessary.
1028
+ * returned value should be freed with jerry_api_release_value
1029
+ * just when the value becomes unnecessary.
1013
1030
*
1014
1031
* @return true, if construction was performed successfully, i.e.:
1015
1032
* - specified object is a constructor function object (see also jerry_api_is_constructor);
1016
1033
* - no unhandled exceptions were thrown in connection with the invocation;
1017
- * false - otherwise.
1034
+ * false - otherwise, 'retval_p' contains thrown exception:
1035
+ * if specified object is not a constructor function object - a TypeError instance;
1036
+ * else - exception, thrown during the invocation.
1018
1037
*/
1019
1038
bool
1020
1039
jerry_api_construct_object (jerry_api_object_t *function_object_p, /* *< function object to call */
1021
- jerry_api_value_t *retval_p, /* *< pointer to place for function's return value
1022
- * or NULL (to ignore the return value) */
1040
+ jerry_api_value_t *retval_p, /* *< pointer to place for function's
1041
+ * return value / thrown exception value
1042
+ * or NULL (to ignore the values) */
1023
1043
const jerry_api_value_t args_p[], /* *< function's call arguments
1024
1044
* (NULL if arguments number is zero) */
1025
1045
uint16_t args_count) /* *< number of the arguments */
@@ -1032,6 +1052,11 @@ jerry_api_construct_object (jerry_api_object_t *function_object_p, /**< function
1032
1052
}
1033
1053
else
1034
1054
{
1055
+ if (retval_p != NULL )
1056
+ {
1057
+ jerry_api_construct_type_error (retval_p);
1058
+ }
1059
+
1035
1060
return false ;
1036
1061
}
1037
1062
} /* jerry_api_construct_object */
0 commit comments