diff --git a/src/config/cmdline.c b/src/config/cmdline.c index a37e946f..5c4492d6 100644 --- a/src/config/cmdline.c +++ b/src/config/cmdline.c @@ -1009,6 +1009,10 @@ union option_info cmdline_options_info[] = { N_("When enabled, terminfo ncurses functions will be used " "instead of hardcoded sequences.")), + INIT_OPT_BOOL("", N_("Test js"), + "test", OPT_ZERO, 0, + N_("When enabled, helps to test js.")), + INIT_OPT_BOOL("", N_("Touch files in ~/.config/elinks when running with -no-connect/-session-ring"), "touch-files", OPT_ZERO, 0, N_("When enabled, runtime state files (bookmarks, history, " diff --git a/src/ecmascript/ecmascript.c b/src/ecmascript/ecmascript.c index 8c436f21..90f0f90c 100644 --- a/src/ecmascript/ecmascript.c +++ b/src/ecmascript/ecmascript.c @@ -643,7 +643,7 @@ init_ecmascript_module(struct module *module) if (xdg_config_home) { /* ecmascript console log */ console_log_filename = straconcat(xdg_config_home, "/console.log", NULL); - console_error_filename = straconcat(xdg_config_home, "/console.err", NULL); + console_error_filename = get_cmd_opt_bool("test") ? stracpy("/dev/stderr") : straconcat(xdg_config_home, "/console.err", NULL); /* ecmascript local storage db location */ #ifdef CONFIG_OS_DOS local_storage_filename = stracpy("elinks_ls.db"); diff --git a/src/ecmascript/spidermonkey/console.cpp b/src/ecmascript/spidermonkey/console.cpp index 8d0e0e5c..51321d9b 100644 --- a/src/ecmascript/spidermonkey/console.cpp +++ b/src/ecmascript/spidermonkey/console.cpp @@ -20,6 +20,7 @@ #include "ecmascript/ecmascript.h" #include "ecmascript/spidermonkey/console.h" #include "intl/libintl.h" +#include "main/main.h" #include "osdep/newwin.h" #include "osdep/sysname.h" #include "util/conv.h" @@ -55,12 +56,14 @@ const JSClass console_class = { static bool console_assert(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool console_error(JSContext *ctx, unsigned int argc, JS::Value *vp); +static bool console_exit(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool console_log(JSContext *ctx, unsigned int argc, JS::Value *vp); const spidermonkeyFunctionSpec console_funcs[] = { { "assert", console_assert, 2 }, { "log", console_log, 1 }, { "error", console_error, 1 }, + { "exit", console_exit, 1 }, { NULL } }; @@ -145,3 +148,20 @@ console_error(JSContext *ctx, unsigned int argc, JS::Value *vp) #endif return console_log_common(ctx, argc, vp, console_error_filename); } + +static bool +console_exit(JSContext *ctx, unsigned int argc, JS::Value *vp) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + JS::CallArgs args = CallArgsFromVp(argc, vp); + args.rval().setUndefined(); + + if (!get_cmd_opt_bool("test")) { + return true; + } + program.retval = args[0].toBoolean() ? RET_ERROR : RET_OK; + program.terminate = 1; + return true; +} diff --git a/src/osdep/osdep.c b/src/osdep/osdep.c index 172d7341..4f5948ec 100644 --- a/src/osdep/osdep.c +++ b/src/osdep/osdep.c @@ -875,6 +875,10 @@ done_draw(void) int get_output_handle(void) { + if (get_cmd_opt_bool("test")) { + return open("/dev/null", O_WRONLY); + } + return 1; } diff --git a/test/ecmascript/console.assert.html b/test/ecmascript/console.assert.html index 5750944a..6cc00b38 100644 --- a/test/ecmascript/console.assert.html +++ b/test/ecmascript/console.assert.html @@ -1,4 +1,5 @@