1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-04 21:50:52 +00:00

[options] Minor optimisation. Store value of "test" option in variable

This commit is contained in:
Witold Filipczyk 2024-04-23 16:07:35 +02:00
parent af20c0e7e8
commit 0f1e056875
7 changed files with 10 additions and 6 deletions

View File

@ -34,6 +34,7 @@
#include "ecmascript/timer.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/main.h"
#include "main/select.h"
#include "main/timer.h"
#include "osdep/osdep.h"
@ -275,7 +276,7 @@ check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %s %d\n", __FILE__, __FUNCTION__, text, interpreter->changed);
#endif
if (interpreter->changed && !get_cmd_opt_bool("test")) {
if (interpreter->changed && !program.testjs) {
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
struct session *ses = doc_view->session;
@ -643,7 +644,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 = get_cmd_opt_bool("test") ? stracpy("/dev/stderr") : straconcat(xdg_config_home, "/console.err", NULL);
console_error_filename = program.testjs ? 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");

View File

@ -103,7 +103,7 @@ mjs_console_exit(js_State *J)
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
if (!get_cmd_opt_bool("test")) {
if (!program.testjs) {
js_pushundefined(J);
return;
}

View File

@ -120,7 +120,7 @@ js_console_exit(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *a
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
if (!get_cmd_opt_bool("test")) {
if (!program.testjs) {
return JS_UNDEFINED;
}
program.retval = JS_ToBool(ctx, argv[0]) ? RET_ERROR : RET_OK;

View File

@ -158,7 +158,7 @@ console_exit(JSContext *ctx, unsigned int argc, JS::Value *vp)
JS::CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setUndefined();
if (!get_cmd_opt_bool("test")) {
if (!program.testjs) {
return true;
}
program.retval = args[0].toBoolean() ? RET_ERROR : RET_OK;

View File

@ -176,6 +176,7 @@ init(void)
free_string_list(&url_list);
return;
}
program.testjs = get_cmd_opt_bool("test");
if (!remote_session_flags) {
check_stdio(&url_list);

View File

@ -20,6 +20,7 @@ struct program {
int terminate;
enum retval retval;
char *path;
unsigned int testjs:1;
};
extern struct program program;

View File

@ -62,6 +62,7 @@
#include "elinks.h"
#include "config/options.h"
#include "main/main.h"
#include "main/select.h"
#include "osdep/osdep.h"
#include "osdep/signals.h"
@ -875,7 +876,7 @@ done_draw(void)
int
get_output_handle(void)
{
if (get_cmd_opt_bool("test")) {
if (program.testjs) {
return open("/dev/null", O_WRONLY);
}