From 67da94a5375a88104b6c31a8acde93cfdeb75c26 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 5 May 2019 22:16:35 +0100 Subject: Use consoleFormatter in Console.bnd Signed-off-by: Daniel Silverstone --- content/handlers/javascript/duktape/Console.bnd | 33 ++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'content/handlers/javascript/duktape/Console.bnd') diff --git a/content/handlers/javascript/duktape/Console.bnd b/content/handlers/javascript/duktape/Console.bnd index c4c0c8399..acaab1610 100644 --- a/content/handlers/javascript/duktape/Console.bnd +++ b/content/handlers/javascript/duktape/Console.bnd @@ -13,28 +13,49 @@ class Console { private unsigned int group; prologue %{ #include +#include "netsurf/browser_window.h" #define CONSOLE_TIMERS MAGIC(ConsoleTimers) static void -write_log_entry(duk_context *ctx, unsigned int group, char logtype) +write_log_entry(duk_context *ctx, unsigned int group, browser_window_console_flags flags) { /* objs... */ + dukky_push_generics(ctx, "consoleFormatter"); + duk_insert(ctx, 0); + if (dukky_pcall(ctx, duk_get_top(ctx) - 1, false)) { + /* Failed to convert somehow, oh dear, you get to keep + * all the pieces. + */ + duk_pop(ctx); + duk_push_string(ctx, "Oh dear, formatter went banananas"); + } + /* str?objs?... */ for (int i = 0; i < duk_get_top(ctx); ++i) { (void)duk_safe_to_string(ctx, i); } /* strs... */ - duk_push_sprintf(ctx, "%c: ", logtype); - duk_insert(ctx, 0); - /* pfx strs... */ for (unsigned int u = 0; u < group; ++u) { duk_push_lstring(ctx, " ", 1); duk_insert(ctx, 0); } - /* spcs... pfx strs... */ + /* spcs... strs... */ duk_concat(ctx, duk_get_top(ctx)); /* str */ - NSLOG(netsurf, INFO, "%s", duk_safe_to_string(ctx, 0)); + + duk_push_global_object(ctx); + duk_get_prop_string(ctx, -1, PRIVATE_MAGIC); + window_private_t *priv_win = duk_get_pointer(ctx, -1); + duk_pop(ctx); + + duk_size_t msglen; + const char *msg = duk_safe_to_lstring(ctx, 0, &msglen); + + if (browser_window_console_log(priv_win->win, BW_CS_SCRIPT_CONSOLE, + msg, msglen, + flags) != NSERROR_OK) { + NSLOG(netsurf, DEBUG, "Unable to log: %s", duk_safe_to_string(ctx, 0)); + } } %}; -- cgit v1.2.3