1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-27 01:25:34 +00:00

[console.log] Global variable to store console_log_filename

This commit is contained in:
Witold Filipczyk 2021-02-22 15:55:12 +01:00
parent 4db2b42799
commit bc7a1ae6ad
3 changed files with 12 additions and 8 deletions

View File

@ -71,6 +71,8 @@ static int interpreter_count;
static INIT_LIST_OF(struct string_list_item, allowed_urls);
char *console_log_filename;
static int
is_prefix(char *prefix, char *url, int dl)
{
@ -449,12 +451,17 @@ static void
init_ecmascript_module(struct module *module)
{
read_url_list();
if (elinks_home) {
console_log_filename = straconcat(elinks_home, "/console.log", NULL);
}
}
static void
done_ecmascript_module(struct module *module)
{
free_string_list(&allowed_urls);
mem_free_if(console_log_filename);
}
static struct module *ecmascript_modules[] = {
@ -464,8 +471,6 @@ static struct module *ecmascript_modules[] = {
NULL,
};
struct module ecmascript_module = struct_module(
/* name: */ N_("ECMAScript"),
/* options: */ ecmascript_options,

View File

@ -109,6 +109,7 @@ void ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::Han
int get_ecmascript_enable(struct ecmascript_interpreter *interpreter);
extern char *console_log_filename;
extern struct module ecmascript_module;
#endif

View File

@ -78,19 +78,17 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
JS::CallArgs args = CallArgsFromVp(argc, vp);
if (argc != 1)
if (argc != 1 || !console_log_filename)
{
args.rval().setBoolean(false);
return(true);
}
unsigned char *key= JS_EncodeString(ctx, args[0].toString());
unsigned char *key = JS_EncodeString(ctx, args[0].toString());
char *log_fname = stracpy(elinks_home);
add_to_strn(&log_fname,"console.log");
FILE *f = fopen(console_log_filename, "a");
FILE *f = fopen(log_fname,"a");
if (f)
if (f)
{
fprintf(f, "%s\n", key);
fclose(f);