mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[test] Added command line option --test
If --test 1, then elinks is headless. Display is /dev/null. console.exit(0); or console.exit(1); terminates elinks session. console.exit is implemented for spidermonkey only.
This commit is contained in:
parent
e9ad5b4d70
commit
6adca27072
@ -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, "
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<script>
|
||||
console.assert(0 % 2 === 0, "O is not even");
|
||||
console.assert(1 % 2 === 0, "1 is not even");
|
||||
console.exit(0);
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user