diff --git a/src/ecmascript/ecmascript.c b/src/ecmascript/ecmascript.c index fc647d4d..3cddefc1 100644 --- a/src/ecmascript/ecmascript.c +++ b/src/ecmascript/ecmascript.c @@ -81,6 +81,7 @@ static int interpreter_count; static INIT_LIST_OF(struct string_list_item, allowed_urls); static INIT_LIST_OF(struct string_list_item, disallowed_urls); +char *console_error_filename; char *console_log_filename; char *local_storage_filename; @@ -542,13 +543,11 @@ init_ecmascript_module(struct module *module) { read_url_list(); - /* ecmascript console log */ if (elinks_home) { + /* ecmascript console log */ console_log_filename = straconcat(elinks_home, "/console.log", NULL); - } - - /* ecmascript local storage db location */ - if (elinks_home) { + console_error_filename = straconcat(elinks_home, "/console.err", NULL); + /* ecmascript local storage db location */ local_storage_filename = straconcat(elinks_home, "/elinks_ls.db", NULL); } } diff --git a/src/ecmascript/ecmascript.h b/src/ecmascript/ecmascript.h index c9a6e50e..56f32657 100644 --- a/src/ecmascript/ecmascript.h +++ b/src/ecmascript/ecmascript.h @@ -119,6 +119,7 @@ int get_ecmascript_enable(struct ecmascript_interpreter *interpreter); void check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text); +extern char *console_error_filename; extern char *console_log_filename; extern char *local_storage_filename; diff --git a/src/ecmascript/spidermonkey-shared.h b/src/ecmascript/spidermonkey-shared.h index 3342199d..10aa9fd1 100644 --- a/src/ecmascript/spidermonkey-shared.h +++ b/src/ecmascript/spidermonkey-shared.h @@ -3,6 +3,7 @@ #include #include +#include #include "util/string.h" @@ -47,8 +48,7 @@ static inline char * jsval_to_string(JSContext *ctx, JS::HandleValue hvp) { /* Memory must be freed in caller */ - - JSString *st = hvp.toString(); + JSString *st = JS::ToString(ctx, hvp); JS::RootedString rst(ctx, st); JS::UniqueChars utf8chars = JS_EncodeStringToUTF8(ctx, rst); diff --git a/src/ecmascript/spidermonkey/console.c b/src/ecmascript/spidermonkey/console.c index 6b922355..e29f5f4c 100644 --- a/src/ecmascript/spidermonkey/console.c +++ b/src/ecmascript/spidermonkey/console.c @@ -73,23 +73,22 @@ console_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS return true; } +static bool console_error(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool console_log(JSContext *ctx, unsigned int argc, JS::Value *vp); const spidermonkeyFunctionSpec console_funcs[] = { - { "log", console_log, 2 }, + { "log", console_log, 1 }, + { "error", console_error, 1 }, { NULL } }; static bool -console_log(JSContext *ctx, unsigned int argc, JS::Value *vp) +console_log_common(JSContext *ctx, unsigned int argc, JS::Value *vp, const char *log_filename) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); -#endif struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); JS::CallArgs args = CallArgsFromVp(argc, vp); - if (argc != 1 || !console_log_filename) + if (argc != 1 || !log_filename) { args.rval().setBoolean(false); return(true); @@ -99,7 +98,7 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp) { unsigned char *key = jsval_to_string(ctx, args[0]); - FILE *f = fopen(console_log_filename, "a"); + FILE *f = fopen(log_filename, "a"); if (f) { @@ -112,3 +111,21 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp) args.rval().setBoolean(true); return(true); } + +static bool +console_log(JSContext *ctx, unsigned int argc, JS::Value *vp) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + return console_log_common(ctx, argc, vp, console_log_filename); +} + +static bool +console_error(JSContext *ctx, unsigned int argc, JS::Value *vp) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + return console_log_common(ctx, argc, vp, console_error_filename); +}