Add testcase that cleanup error throw from javascript properly. (#4581)

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
This commit is contained in:
Yonggang Luo
2024-11-13 04:24:35 +08:00
committed by GitHub
parent 3f314f387d
commit 43f5026eb2
2 changed files with 49 additions and 2 deletions
+20 -1
View File
@@ -21,7 +21,7 @@
#include "test-common.h"
/* Load a module. */
const char eval_string1[] = "require ('my_custom_module');";
const char eval_string1[] = "require ('my_custom_module').number_value;";
/* Load a module using a different resolver. */
const char eval_string2[] = "require ('differently-handled-module');";
@@ -74,6 +74,15 @@ const char eval_string7[] = "(function() {"
" return x !== y ? 1 : 0;"
"}) ();";
/* Make sure the entire cache is cleared. */
const char eval_string8[] =
"(function() {"
" var custom_module = require ('my_custom_module');"
" custom_module.call_function_with_callback(function(){"
" throw '12312391238219423914832091480921834028130948213904812093849023814902183490218394082190348'"
" });"
"}) ();";
/*
* Define a resolver for a module named "differently-handled-module" to check that custom resolvers work.
*/
@@ -155,6 +164,12 @@ assert_number (jerry_value_t js_value, double expected_result)
TEST_ASSERT (jerry_value_as_number (js_value) == expected_result);
} /* assert_number */
static jerry_value_t
eval_string (const char *the_string)
{
return jerry_eval ((const jerry_char_t *) the_string, strlen (the_string), JERRY_PARSE_STRICT_MODE);
} /* eval_string */
static void
eval_one (const char *the_string, double expected_result)
{
@@ -214,5 +229,9 @@ main (int argc, char **argv)
eval_one (eval_string6, 1);
eval_one (eval_string7, 1);
jerry_value_t val_err = eval_string (eval_string8);
TEST_ASSERT (jerry_value_is_exception (val_err));
jerry_value_free (val_err);
jerry_cleanup ();
} /* main */