diff --git a/src/main.c b/src/main.c index 958bfed9..71825afa 100644 --- a/src/main.c +++ b/src/main.c @@ -516,7 +516,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[]) if (args.count == 1) { - _tf_run_task(&args, 0); + result = _tf_run_task(&args, 0); } if (args.count > 1) { diff --git a/src/task.c b/src/task.c index ba657663..dbf32710 100644 --- a/src/task.c +++ b/src/task.c @@ -113,8 +113,8 @@ typedef struct _tf_task_t bool _trusted; bool _one_proc; bool _killed; - int32_t _exitCode; char _scriptName[256]; + int _global_exception_count; JSRuntime* _runtime; JSContext* _context; @@ -421,11 +421,11 @@ int tf_task_execute(tf_task_t* task, const char* fileName) if (source) { JSValue result = JS_Eval(task->_context, source, strlen(source), fileName, JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_ASYNC); - if (tf_util_report_error(task->_context, result)) + if (tf_util_report_error(task->_context, result) || task->_global_exception_count) { tf_printf("Reported an error.\n"); } - if (!JS_IsError(task->_context, result) && !JS_IsException(result)) + else { executed = true; } @@ -1457,6 +1457,8 @@ static void _tf_task_promise_rejection_tracker(JSContext* context, JSValueConst if (!is_handled) { tf_util_report_error(context, reason); + tf_task_t* task = tf_task_get(context); + task->_global_exception_count++; } } diff --git a/src/tests.c b/src/tests.c index 73abadb2..8081a81a 100644 --- a/src/tests.c +++ b/src/tests.c @@ -58,6 +58,20 @@ static void _test_nop(const tf_test_options_t* options) assert(WEXITSTATUS(result) == 0); } +static void _test_exception(const tf_test_options_t* options) +{ + _write_file("out/test.js", "throw new Error('oops');"); + + char command[256]; + snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path); + tf_printf("%s\n", command); + int result = system(command); + tf_printf("result = %d\n", result); + (void)result; + assert(WIFEXITED(result)); + assert(WEXITSTATUS(result) != 0); +} + #if !defined(__HAIKU__) static void _test_sandbox(const tf_test_options_t* options) { @@ -372,7 +386,7 @@ static void _test_import(const tf_test_options_t* options) result = system(command); tf_printf("returned %d\n", WEXITSTATUS(result)); assert(WIFEXITED(result)); - assert(WEXITSTATUS(result) == 0); + assert(WEXITSTATUS(result) != 0); unlink("out/test.js"); unlink("out/required.js"); @@ -893,6 +907,7 @@ void tf_tests(const tf_test_options_t* options) _tf_test_run(options, "ssb_id", tf_ssb_test_id_conversion, false); _tf_test_run(options, "ssb_following", tf_ssb_test_following, false); _tf_test_run(options, "nop", _test_nop, false); + _tf_test_run(options, "exception", _test_exception, false); #if !defined(__HAIKU__) _tf_test_run(options, "sandbox", _test_sandbox, false); #endif