...
 
Commits (1)
  • Rob Swindell's avatar
    Fix JS global object corruption when invoking JS global hotkey handlers · cb5188bd
    Rob Swindell authored
    As reported by Ragnarok and The Lizard Master, invoking a JS global
    hot-key handler (e.g. hitting Ctrl-U or Ctrl-P with the privatemsg
    or nodelist modules installed as handlers) would lead to the global
    object being cleared/corrupted so other scripts would then fail to
    run correctly (e.g. Error: can't open sbbsdefs.js: No such file or directory)
    
    This probably explains the JS_GC/JS_ENDREQUEST change needed when
    the hotkey-specific JS runtime/context/scope was introduced last year.
    Should revisit that too.
    cb5188bd
......@@ -563,7 +563,7 @@ js_OperationCallback(JSContext *cx)
return ret;
}
long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* scope, JSContext* js_cx)
long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* scope, JSContext* js_cx, JSObject* js_glob)
{
char* p;
char* args=NULL;
......@@ -580,6 +580,8 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* sco
if(js_cx == NULL)
js_cx = this->js_cx;
if(js_glob == NULL)
js_glob = this->js_glob;
if(js_cx==NULL) {
errormsg(WHERE,ERR_CHK,"JavaScript support",0);
......
......@@ -195,7 +195,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode)
js_hotkey_cx = js_init(&js_hotkey_runtime, &js_hotkey_glob, "HotKey");
js_create_user_objects(js_hotkey_cx, js_hotkey_glob);
}
js_execfile(cmdstr(cfg.hotkey[i]->cmd+1,nulstr,nulstr,tmp), /* startup_dir: */NULL, /* scope: */js_hotkey_glob, js_hotkey_cx);
js_execfile(cmdstr(cfg.hotkey[i]->cmd+1,nulstr,nulstr,tmp), /* startup_dir: */NULL, /* scope: */js_hotkey_glob, js_hotkey_cx, js_hotkey_glob);
} else
external(cmdstr(cfg.hotkey[i]->cmd,nulstr,nulstr,tmp),0);
if(!(sys_status&SS_SPLITP)) {
......
......@@ -406,7 +406,7 @@ public:
JSContext* js_hotkey_cx;
JSObject* js_hotkey_glob;
js_callback_t js_callback;
long js_execfile(const char *fname, const char* startup_dir, JSObject* scope = NULL, JSContext* cx = NULL);
long js_execfile(const char *fname, const char* startup_dir, JSObject* scope = NULL, JSContext* cx = NULL, JSObject* glob = NULL);
long js_execmodule(const char *fname, long mode, const char* startup_dir);
JSContext* js_init(JSRuntime**, JSObject**, const char* desc);
void js_cleanup(void);
......