jerryscript icon indicating copy to clipboard operation
jerryscript copied to clipboard

try-catch throw in eval function

Open seanshpark opened this issue 11 years ago • 2 comments

I'm not good at the spec. but seems that try-catch is not working correct. test code added to test-api.cpp

diff --git a/tests/unit/test-api.cpp b/tests/unit/test-api.cpp
index 9636fd0..405aec5 100644
--- a/tests/unit/test-api.cpp
+++ b/tests/unit/test-api.cpp
@@ -456,6 +456,25 @@ main (void)

   jerry_api_release_value (&val_t);

+  // eval throw
+  const char *eval_code_err_p = "try{ throw new Error('error'); } catch(e) {print(e)}";
+  status = jerry_api_eval (eval_code_err_p,
+                           strlen (eval_code_err_p),
+                           false,
+                           true,
+                           &val_t);
+  JERRY_ASSERT (status == JERRY_COMPLETION_CODE_OK);
+
+  is_ok = jerry_api_call_function (val_t.v_object,
+                                   NULL,
+                                   &res,
+                                   NULL, 0);
+  JERRY_ASSERT (is_ok);
+  jerry_api_release_value (&res);
+
+  jerry_api_release_value (&val_t);
+
+
   // cleanup.
   jerry_api_release_object (global_obj_p);

expect is_ok to be true.

seanshpark avatar Jun 15 '15 06:06 seanshpark

I think val_t is not a function. You may try with

const char *eval_code_err_p = "function() { try{ throw new Error('error'); } catch(e) {print(e)} }";

ILyoan avatar Jun 15 '15 06:06 ILyoan

thank you for pointing the problem. what I wanted to test is

diff --git a/tests/unit/test-api.cpp b/tests/unit/test-api.cpp
index 9636fd0..7a5d36a 100644
--- a/tests/unit/test-api.cpp
+++ b/tests/unit/test-api.cpp
@@ -456,6 +456,17 @@ main (void)

   jerry_api_release_value (&val_t);

+  // eval throw
+  const char *eval_code_err_p = "try { throw new Error('error'); } catch(e) { print(e); }";
+  status = jerry_api_eval (eval_code_err_p,
+                           strlen (eval_code_err_p),
+                           false,
+                           true,
+                           &val_t);
+  JERRY_ASSERT (status == JERRY_COMPLETION_CODE_OK);
+
+  jerry_api_release_value (&val_t);
+

and it's working ok.

seanshpark avatar Jun 15 '15 07:06 seanshpark