Skip to content
Snippets Groups Projects
Commit c3b47aca authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Save/restore js.scope property value in sbbs_t::js_execfile()

This solves the problem of exit() values (e.g. non-zero return codes) not
getting propagated to callers when nest-called (e.g. via bbs.exec()).

I think it was kk4qbn that pointed this out via IRC: an exit(1) call from
prextrn.js did not stop the external program from running (as it should, for
any non-zero exit code). This only happened when the prextrn.js called another
JS script (e.g. via bbs.exec() or as was the case here, indirectly via "EXEC"
@-code in the YesNoBar text.dat string (which executed yesnobar.js). This
nested JS script invocation via sbbs_t::js_execfile() would clobber the stored
js.scope property value (where the "exit_code" property is written).

Script invoked in their own context (e.g. via js.exec()) wouldn't have this
issue in the first place.
parent f7771613
No related branches found
No related tags found
1 merge request!455Update branch with changes from master
Pipeline #6318 passed
......@@ -544,6 +544,7 @@ int sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* scop
jsval old_js_exec_path = JSVAL_VOID;
jsval old_js_exec_file = JSVAL_VOID;
jsval old_js_exec_dir = JSVAL_VOID;
jsval old_js_scope = JSVAL_VOID;
jsval val;
jsval rval;
int32 result=0;
......@@ -676,6 +677,8 @@ int sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* scop
JS_AddValueRoot(js_cx, &old_js_exec_file);
if(JS_GetProperty(js_cx, js, "exec_dir", &old_js_exec_dir))
JS_AddValueRoot(js_cx, &old_js_exec_dir);
if(JS_GetProperty(js_cx, js, "scope", &old_js_scope))
JS_AddValueRoot(js_cx, &old_js_scope);
}
js_PrepareToExecute(js_cx, js_glob, path, startup_dir, js_scope);
......@@ -728,6 +731,9 @@ int sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* scop
JS_DefineProperty(js_cx, js, "exec_dir", old_js_exec_dir
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
JS_RemoveValueRoot(js_cx, &old_js_exec_dir);
JS_DefineProperty(js_cx, js, "scope", old_js_scope
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
JS_RemoveValueRoot(js_cx, &old_js_scope);
}
JS_GC(js_cx);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment