aboutsummaryrefslogtreecommitdiff
path: root/ports/javascript/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'ports/javascript/main.c')
-rw-r--r--ports/javascript/main.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/ports/javascript/main.c b/ports/javascript/main.c
index 65bae98b4..f8ef0e7c5 100644
--- a/ports/javascript/main.c
+++ b/ports/javascript/main.c
@@ -39,7 +39,8 @@
#include "library.h"
#if MICROPY_ENABLE_COMPILER
-void do_str(const char *src, mp_parse_input_kind_t input_kind) {
+int do_str(const char *src, mp_parse_input_kind_t input_kind) {
+ int ret = 0;
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
@@ -51,18 +52,28 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
} else {
// uncaught exception
if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), &mp_type_SystemExit)) {
- // at the moment, the value of SystemExit is unused
+ mp_obj_t exit_val = mp_obj_exception_get_value(MP_OBJ_FROM_PTR(nlr.ret_val));
+ if (exit_val != mp_const_none) {
+ mp_int_t int_val;
+ if (mp_obj_get_int_maybe(exit_val, &int_val)) {
+ ret = int_val & 255;
+ } else {
+ ret = 1;
+ }
+ }
} else {
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
+ ret = 1;
}
}
+ return ret;
}
#endif
static char *stack_top;
-void mp_js_do_str(const char *code) {
- do_str(code, MP_PARSE_FILE_INPUT);
+int mp_js_do_str(const char *code) {
+ return do_str(code, MP_PARSE_FILE_INPUT);
}
int mp_js_process_char(int c) {