summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/javascript/main.c19
-rw-r--r--ports/javascript/wrapper.js6
2 files changed, 18 insertions, 7 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) {
diff --git a/ports/javascript/wrapper.js b/ports/javascript/wrapper.js
index 84ad2ae3a..ae0f24e7e 100644
--- a/ports/javascript/wrapper.js
+++ b/ports/javascript/wrapper.js
@@ -29,7 +29,7 @@ var Module = {};
var mainProgram = function()
{
mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']);
- mp_js_do_str = Module.cwrap('mp_js_do_str', 'null', ['string']);
+ mp_js_do_str = Module.cwrap('mp_js_do_str', 'number', ['string']);
mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']);
mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number']);
@@ -69,9 +69,9 @@ var mainProgram = function()
}
});
} else {
- mp_js_do_str(contents);
+ process.exitCode = mp_js_do_str(contents);
}
}
}
-Module["onRuntimeInitialized"] = mainProgram; \ No newline at end of file
+Module["onRuntimeInitialized"] = mainProgram;