Skip to content

Commit 26cedb4

Browse files
lygstateRobert Sipka
authored andcommitted
Add testcase that cleanup error throw from javascript properly.
JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent bd0d391 commit 26cedb4

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

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

Lines changed: 22 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,14 @@ 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,
171+
strlen (the_string),
172+
JERRY_PARSE_STRICT_MODE);
173+
} /* eval_string */
174+
158175
static void
159176
eval_one (const char *the_string, double expected_result)
160177
{
@@ -214,5 +231,9 @@ main (int argc, char **argv)
214231
eval_one (eval_string6, 1);
215232
eval_one (eval_string7, 1);
216233

234+
jerry_value_t val_err = eval_string (eval_string8);
235+
TEST_ASSERT (jerry_value_is_error (val_err));
236+
jerry_release_value (val_err);
237+
217238
jerry_cleanup ();
218239
} /* main */

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

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

2020
#define MODULE_NAME my_custom_module
2121

22+
static void
23+
jobject_set_property_jval (
24+
jerry_value_t jobj, const char *name,
25+
jerry_value_t value)
26+
{
27+
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) (name));
28+
jerry_value_t ret_val = jerry_set_property (jobj, prop_name, value);
29+
jerry_release_value (prop_name);
30+
jerry_release_value (ret_val);
31+
} /* jobject_set_property_jval */
32+
33+
static jerry_value_t
34+
call_function_with_callback (
35+
const jerry_value_t jfunc,
36+
const jerry_value_t jthis,
37+
const jerry_value_t jargv[],
38+
const jerry_length_t jargc)
39+
{
40+
(void) jfunc;
41+
(void) jargc;
42+
jerry_value_t jval_func = jargv[0];
43+
return jerry_call_function (jval_func, jthis, NULL, 0);
44+
} /* call_function_with_callback */
45+
2246
static jerry_value_t
2347
my_custom_module_on_resolve (void)
2448
{
25-
return jerry_number (42);
49+
jerry_value_t mymodule = jerry_create_object ();
50+
jerry_value_t val = jerry_create_number (42);
51+
jobject_set_property_jval (mymodule, "number_value", val);
52+
jerry_release_value (val);
53+
54+
jerry_value_t jfunc = jerry_create_external_function (call_function_with_callback);
55+
jobject_set_property_jval (mymodule, "call_function_with_callback", jfunc);
56+
jerry_release_value (jfunc);
57+
58+
return mymodule;
2659
} /* my_custom_module_on_resolve */
2760

2861
JERRYX_NATIVE_MODULE (MODULE_NAME, my_custom_module_on_resolve)

0 commit comments

Comments
 (0)