Skip to content

Commit 43f5026

Browse files
authored
Add testcase that cleanup error throw from javascript properly. (jerryscript-project#4581)
JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent 3f314f3 commit 43f5026

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

tests/unit-ext/module/jerry-module-test.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "test-common.h"
2222

2323
/* Load a module. */
24-
const char eval_string1[] = "require ('my_custom_module');";
24+
const char eval_string1[] = "require ('my_custom_module').number_value;";
2525

2626
/* Load a module using a different resolver. */
2727
const char eval_string2[] = "require ('differently-handled-module');";
@@ -74,6 +74,15 @@ const char eval_string7[] = "(function() {"
7474
" return x !== y ? 1 : 0;"
7575
"}) ();";
7676

77+
/* Make sure the entire cache is cleared. */
78+
const char eval_string8[] =
79+
"(function() {"
80+
" var custom_module = require ('my_custom_module');"
81+
" custom_module.call_function_with_callback(function(){"
82+
" throw '12312391238219423914832091480921834028130948213904812093849023814902183490218394082190348'"
83+
" });"
84+
"}) ();";
85+
7786
/*
7887
* Define a resolver for a module named "differently-handled-module" to check that custom resolvers work.
7988
*/
@@ -155,6 +164,12 @@ assert_number (jerry_value_t js_value, double expected_result)
155164
TEST_ASSERT (jerry_value_as_number (js_value) == expected_result);
156165
} /* assert_number */
157166

167+
static jerry_value_t
168+
eval_string (const char *the_string)
169+
{
170+
return jerry_eval ((const jerry_char_t *) the_string, strlen (the_string), JERRY_PARSE_STRICT_MODE);
171+
} /* eval_string */
172+
158173
static void
159174
eval_one (const char *the_string, double expected_result)
160175
{
@@ -214,5 +229,9 @@ main (int argc, char **argv)
214229
eval_one (eval_string6, 1);
215230
eval_one (eval_string7, 1);
216231

232+
jerry_value_t val_err = eval_string (eval_string8);
233+
TEST_ASSERT (jerry_value_is_exception (val_err));
234+
jerry_value_free (val_err);
235+
217236
jerry_cleanup ();
218237
} /* main */

tests/unit-ext/module/my-custom-module.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,38 @@
1919

2020
#define MODULE_NAME my_custom_module
2121

22+
static void
23+
jobject_set_property_jval (jerry_value_t jobj, const char *name, jerry_value_t value)
24+
{
25+
jerry_value_t prop_name = jerry_string_sz (name);
26+
jerry_value_t ret_val = jerry_object_set (jobj, prop_name, value);
27+
jerry_value_free (prop_name);
28+
jerry_value_free (ret_val);
29+
} /* jobject_set_property_jval */
30+
31+
static jerry_value_t
32+
call_function_with_callback (const jerry_call_info_t *call_info_p,
33+
const jerry_value_t jargv[],
34+
const jerry_length_t jargc)
35+
{
36+
(void) jargc;
37+
jerry_value_t jval_func = jargv[0];
38+
return jerry_call (jval_func, call_info_p->this_value, NULL, 0);
39+
} /* call_function_with_callback */
40+
2241
static jerry_value_t
2342
my_custom_module_on_resolve (void)
2443
{
25-
return jerry_number (42);
44+
jerry_value_t mymodule = jerry_object ();
45+
jerry_value_t val = jerry_number (42);
46+
jobject_set_property_jval (mymodule, "number_value", val);
47+
jerry_value_free (val);
48+
49+
jerry_value_t jfunc = jerry_function_external (call_function_with_callback);
50+
jobject_set_property_jval (mymodule, "call_function_with_callback", jfunc);
51+
jerry_value_free (jfunc);
52+
53+
return mymodule;
2654
} /* my_custom_module_on_resolve */
2755

2856
JERRYX_NATIVE_MODULE (MODULE_NAME, my_custom_module_on_resolve)

0 commit comments

Comments
 (0)