diff --git a/src/ecmascript/libdom/mujs/keyboard.c b/src/ecmascript/libdom/mujs/keyboard.c index ca252e56..7dc814b5 100644 --- a/src/ecmascript/libdom/mujs/keyboard.c +++ b/src/ecmascript/libdom/mujs/keyboard.c @@ -25,6 +25,8 @@ struct keyboard { unicode_val_T keyCode; }; +extern struct term_event last_event; + static void mjs_keyboardEvent_finalizer(js_State *J, void *val) { @@ -44,7 +46,7 @@ mjs_push_keyboardEvent(js_State *J, struct term_event *ev) js_error(J, "out of memory"); return; } - keyCode = keyb->keyCode = get_kbd_key(ev); + keyCode = keyb->keyCode = ev ? get_kbd_key(ev) : 0; js_newobject(J); { @@ -79,10 +81,12 @@ mjs_keyboardEvent_get_property_keyCode(js_State *J) fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); #endif struct keyboard *keyb = (struct keyboard *)js_touserdata(J, 0, "event"); + unicode_val_T code; if (!keyb) { js_pushnull(J); return; } - js_pushnumber(J, keyb->keyCode); + code = keyb->keyCode ?: get_kbd_key(&last_event); + js_pushnumber(J, code); } diff --git a/src/ecmascript/libdom/mujs/window.c b/src/ecmascript/libdom/mujs/window.c index 6f937101..4ecad329 100644 --- a/src/ecmascript/libdom/mujs/window.c +++ b/src/ecmascript/libdom/mujs/window.c @@ -64,8 +64,6 @@ struct el_message { struct el_window *elwin; }; -extern struct term_event last_event; - static void mjs_window_finalizer(js_State *J, void *val) { @@ -100,7 +98,7 @@ mjs_window_get_property_event(js_State *J) #ifdef ECMASCRIPT_DEBUG fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); #endif - mjs_push_keyboardEvent(J, &last_event); + mjs_push_keyboardEvent(J, NULL); } static void @@ -650,9 +648,9 @@ mjs_window_init(js_State *J) addproperty(J, "top", mjs_window_get_property_top, NULL); addproperty(J, "window", mjs_window_get_property_self, NULL); } - js_defglobal(J, "window", JS_DONTENUM); + js_defglobal(J, "window", 0); - js_dostring(J, "function alert(text) { return window.alert(text); }\n" + js_dostring(J, "var event = window.event; function alert(text) { return window.alert(text); }\n" "function clearTimeout(h) { return window.clearTimeout(h); }\n" "function open(a, b, c) { return window.open(a, b, c); }\n" "function setTimeout(a, b) { return window.setTimeout(a, b); }\n" diff --git a/src/ecmascript/quickjs.cpp b/src/ecmascript/quickjs.cpp index a6644a9b..8cd41c0c 100644 --- a/src/ecmascript/quickjs.cpp +++ b/src/ecmascript/quickjs.cpp @@ -404,6 +404,7 @@ quickjs_eval_boolback(struct ecmascript_interpreter *interpreter, JS_ToInt32(ctx, &ret, r); + return ret; } diff --git a/src/viewer/text/link.cpp b/src/viewer/text/link.cpp index 88c7db90..35b0a300 100644 --- a/src/viewer/text/link.cpp +++ b/src/viewer/text/link.cpp @@ -86,7 +86,6 @@ current_link_evhook(struct document_view *doc_view, enum script_event_hook_type if (!link) return -1; if (!doc_view->vs->ecmascript) return -1; -#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS) void *mapa = (void *)doc_view->document->element_map; if (mapa) { @@ -97,7 +96,7 @@ current_link_evhook(struct document_view *doc_view, enum script_event_hook_type check_element_event(doc_view->vs->ecmascript, elem, event_name, NULL); } } -#endif + if (!link->event_hooks) return -1; foreach (evhook, *link->event_hooks) {