Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try-catch throw in eval function #182

Closed
seanshpark opened this issue Jun 15, 2015 · 2 comments
Closed

try-catch throw in eval function #182

seanshpark opened this issue Jun 15, 2015 · 2 comments

Comments

@seanshpark
Copy link
Contributor

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 seanshpark changed the title throw in eval function try-catch throw in eval function Jun 15, 2015
@ILyoan
Copy link
Contributor

ILyoan commented Jun 15, 2015

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)} }";

@seanshpark
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants