Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/8dc78699374dca5b8369ffa65a6e27a3eeb8f985
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/8dc78699374dca5b8369ffa65a6e27a3eeb8f985
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/8dc78699374dca5b8369ffa65a6e27a3eeb8f985

The branch, master has been updated
       via  8dc78699374dca5b8369ffa65a6e27a3eeb8f985 (commit)
       via  67da94a5375a88104b6c31a8acde93cfdeb75c26 (commit)
       via  846e811760eb79965a844546d50c49c31768fbee (commit)
       via  8b4ec11b8958b7b7893d2b0f6aad20b2ddc3599f (commit)
       via  8474c5d4c0b59e74e2ef001b5033b78d7a99fcad (commit)
       via  6952a239465811c26838e177d35222fd5229e393 (commit)
      from  5e1f4c406d63139e2eff1fbd004e4f33b0ad20d1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=8dc78699374dca5b8369ffa65a6e27a3eeb8f985
commit 8dc78699374dca5b8369ffa65a6e27a3eeb8f985
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Use console formatting to prove it out
    
    Signed-off-by: Daniel Silverstone <[email protected]>

diff --git a/test/js/inserted-script-async.js b/test/js/inserted-script-async.js
index 5552e27..aa6c0a3 100644
--- a/test/js/inserted-script-async.js
+++ b/test/js/inserted-script-async.js
@@ -1 +1 @@
-console.log("External asynchronous dynamism!");
+console.log("External %s dynamism!", "asynchronous");


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=67da94a5375a88104b6c31a8acde93cfdeb75c26
commit 67da94a5375a88104b6c31a8acde93cfdeb75c26
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Use consoleFormatter in Console.bnd
    
    Signed-off-by: Daniel Silverstone <[email protected]>

diff --git a/content/handlers/javascript/duktape/Console.bnd 
b/content/handlers/javascript/duktape/Console.bnd
index c4c0c83..acaab16 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 <nsutils/time.h>
+#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));
+       }
 }
 
 %};


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=846e811760eb79965a844546d50c49c31768fbee
commit 846e811760eb79965a844546d50c49c31768fbee
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Generics: Add consoleFormatter
    
    In order to support the console logging formatting specification
    as per https://console.spec.whatwg.org/#logger we need to implement
    the Formatter(...) algorithm which is easier done within JavaScript
    
    Signed-off-by: Daniel Silverstone <[email protected]>

diff --git a/content/handlers/javascript/duktape/generics.js 
b/content/handlers/javascript/duktape/generics.js
index ee5e801..6850c9b 100644
--- a/content/handlers/javascript/duktape/generics.js
+++ b/content/handlers/javascript/duktape/generics.js
@@ -27,4 +27,80 @@ var NetSurf = {
            },
        });
     },
+    consoleFormatter: function Formatter() {
+
+       if (arguments.length == 0) {
+           return new Array("");
+       } else if (arguments.length == 1) {
+           return new Array(arguments[0].toString());
+       }
+
+       const target = arguments[0];
+       const current = arguments[1];
+
+       if (typeof target !== "string") {
+           return Array.from(arguments);
+       }
+
+       const offset = target.search("%");
+
+       if (offset == -1 || offset >= target.length) {
+           // We've a string, but the % either doesn't exist or is
+           // at the end of it, so give up
+           return Array.from(arguments);
+       }
+
+       const specifier = target[offset + 1];
+
+       var converted = undefined;
+
+       if (specifier === 's') {
+           // Stringification
+           converted = current.toString();
+       } else if (specifier === 'd' || specifier === 'i') {
+           converted = parseInt(current, 10).toString();
+       } else if (specifier === 'f') {
+           converted = parseFloat(current).toString();
+       } else if (specifier === 'o') {
+           // TODO: Objectification?
+           converted = current.toString();
+       } else if (specifier === 'O') {
+           // TODO: JSONification
+           converted = current.toString();
+       }
+
+       var result = new Array();
+
+       if (converted !== undefined) {
+           // We converted it, so we need to absorb the formatted thing
+           // and move on
+           var newtarget = "";
+           if (offset > 0) {
+               newtarget = target.substring(0, offset);
+           }
+           newtarget = newtarget + converted;
+           if (offset < target.length - 2) {
+               newtarget = newtarget + target.substring(offset + 2, 
target.length);
+           }
+           result.push(newtarget);
+       } else {
+           // Undefined, so we drop this argument and move on
+           result.push(target);
+       }
+
+       var i;
+       for (i = 2; i < arguments.length; i++) {
+           result.push(arguments[i]);
+       }
+
+       if (result[0].search("%") == -1) {
+           return result;
+       }
+
+       if (result.length === 1) {
+           return result;
+       }
+
+       return Formatter.apply(result);
+    }
 };


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=8b4ec11b8958b7b7893d2b0f6aad20b2ddc3599f
commit 8b4ec11b8958b7b7893d2b0f6aad20b2ddc3599f
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Dukky: Change from specifically named generics
    
    Instead of specifically having to extract each generic by name,
    such as makeListProxy, instead support the entire generics table
    and use `dukky_push_generics()` to gain access to it.
    
    Signed-off-by: Daniel Silverstone <[email protected]>

diff --git a/content/handlers/javascript/duktape/Document.bnd 
b/content/handlers/javascript/duktape/Document.bnd
index d275917..9c63a61 100644
--- a/content/handlers/javascript/duktape/Document.bnd
+++ b/content/handlers/javascript/duktape/Document.bnd
@@ -18,7 +18,7 @@ prologue Document()
 #include "content/urldb.h"
 
 #define HANDLER_MAGIC MAGIC(HANDLER_MAP)
-#define LIST_PROXY_MAGIC MAGIC(LIST_PROXY)
+#define GENERICS_MAGIC MAGIC(GENERICS_TABLE)
 %}
 
 
@@ -345,7 +345,7 @@ method Document::getElementsByTagName()
 
        if (nodes == NULL) return 0; /* coerced to undefined */
 
-       duk_get_global_string(ctx, LIST_PROXY_MAGIC);
+       dukky_push_generics(ctx, "makeListProxy");
 
        duk_push_pointer(ctx, nodes);
        dukky_create_object(ctx, PROTO_NAME(NODELIST), 1);
diff --git a/content/handlers/javascript/duktape/dukky.c 
b/content/handlers/javascript/duktape/dukky.c
index 8af3165..d1bd4ec 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -48,7 +48,7 @@
 #define HANDLER_LISTENER_MAGIC MAGIC(HANDLER_LISTENER_MAP)
 #define HANDLER_MAGIC MAGIC(HANDLER_MAP)
 #define EVENT_LISTENER_JS_MAGIC MAGIC(EVENT_LISTENER_JS_MAP)
-#define LIST_PROXY_MAGIC MAGIC(LIST_PROXY)
+#define GENERICS_MAGIC MAGIC(GENERICS_TABLE)
 
 static duk_ret_t dukky_populate_object(duk_context *ctx, void *udata)
 {
@@ -663,11 +663,7 @@ jsobject *js_newcompartment(jscontext *ctx, void 
*win_priv, void *doc_priv)
        /* ..., Win */
        duk_get_prop_string(CTX, -1, "NetSurf");
        /* ..., Win, NetSurf */
-       duk_get_prop_string(CTX, -1, "makeListProxy");
-       /* ..., Win, NetSurf, MLP */
-       duk_put_global_string(CTX, LIST_PROXY_MAGIC);
-       /* ..., Win, NetSurf */
-       duk_pop(CTX);
+       duk_put_global_string(CTX, GENERICS_MAGIC);
        /* ..., Win */
        duk_del_prop_string(CTX, -1, "NetSurf");
        duk_pop(CTX);
@@ -754,6 +750,17 @@ duk_int_t dukky_pcall(duk_context *ctx, duk_size_t argc, 
bool reset_timeout)
 }
 
 
+void dukky_push_generics(duk_context *ctx, const char *generic)
+{
+       /* ... */
+       duk_get_global_string(ctx, GENERICS_MAGIC);
+       /* ..., generics */
+       duk_get_prop_string(ctx, -1, generic);
+       /* ..., generics, generic */
+       duk_remove(ctx, -2);
+       /* ..., generic */
+}
+
 bool js_exec(jscontext *ctx, const char *txt, size_t txtlen, const char *name)
 {
        assert(ctx);
diff --git a/content/handlers/javascript/duktape/dukky.h 
b/content/handlers/javascript/duktape/dukky.h
index ee9f474..93d4169 100644
--- a/content/handlers/javascript/duktape/dukky.h
+++ b/content/handlers/javascript/duktape/dukky.h
@@ -51,4 +51,7 @@ void dukky_shuffle_array(duk_context *ctx, duk_uarridx_t idx);
 /* pcall something, and if it errored, also dump the error to the log */
 duk_int_t dukky_pcall(duk_context *ctx, duk_size_t argc, bool reset_timeout);
 
+/* Push a generics function onto the stack */
+void dukky_push_generics(duk_context *ctx, const char *generic);
+
 #endif


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=8474c5d4c0b59e74e2ef001b5033b78d7a99fcad
commit 8474c5d4c0b59e74e2ef001b5033b78d7a99fcad
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Logging: migrate and provide content interface
    
    Migrate the console enums into netsurf/console.h and add
    support so that contents can raise a message to log to
    the console.
    
    Signed-off-by: Daniel Silverstone <[email protected]>

diff --git a/content/content.h b/content/content.h
index 77cc605..417fb7b 100644
--- a/content/content.h
+++ b/content/content.h
@@ -33,6 +33,7 @@
 #include "content/content_factory.h"
 #include "desktop/search.h" /* search flags enum */
 #include "netsurf/mouse.h" /* mouse state enums */
+#include "netsurf/console.h" /* console state and flags enums */
 
 struct browser_window;
 struct browser_window_features;
@@ -56,6 +57,7 @@ typedef enum {
 
 /** Used in callbacks to indicate what has occurred. */
 typedef enum {
+       CONTENT_MSG_LOG,       /**< Content wishes to log something */
        CONTENT_MSG_LOADING,   /**< fetching or converting */
        CONTENT_MSG_READY,     /**< may be displayed */
        CONTENT_MSG_DONE,      /**< finished */
@@ -95,6 +97,13 @@ struct content_rfc5988_link {
 
 /** Extra data for some content_msg messages. */
 union content_msg_data {
+       /** CONTENT_MSG_LOG - Information for logging */
+       struct {
+               browser_window_console_source src; /**< The source of the 
logging */
+               const char *msg; /**< The message to log */
+               size_t msglen; /**< The length of that message */
+               browser_window_console_flags flags; /**< The flags of the 
logging */
+       } log;
        /** CONTENT_MSG_ERROR - Error message */
        const char *error;
         /** CONTENT_MSG_ERRORCODE - Error code */
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index a47725b..4ffdb39 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -2514,7 +2514,7 @@ static bool html_exec(struct content *c, const char *src, 
size_t srclen)
        dom_text *text_node;
        dom_node *spare_node;
        dom_html_script_element *script_node;
-       
+
        if (htmlc->document == NULL) {
                NSLOG(netsurf, DEEPDEBUG, "Unable to exec, no document");
                goto out_no_string;
diff --git a/desktop/browser.c b/desktop/browser.c
index 1a74935..dad830f 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1358,6 +1358,13 @@ browser_window_callback(hlcache_handle *c,
        float sx, sy;
 
        switch (event->type) {
+       case CONTENT_MSG_LOG:
+               browser_window_console_log(bw,
+                                          event->data.log.src,
+                                          event->data.log.msg,
+                                          event->data.log.msglen,
+                                          event->data.log.flags);
+               break;
        case CONTENT_MSG_DOWNLOAD:
                assert(bw->loading_content == c);
 
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index 9c6fe7a..e701aa3 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -30,6 +30,7 @@
 
 #include "utils/errors.h"
 #include "netsurf/mouse.h"
+#include "netsurf/console.h"
 
 struct browser_window;
 struct hlcache_handle;
@@ -144,43 +145,6 @@ struct browser_window_features {
 };
 
 /**
- * Sources of messages which end up in the browser window console
- */
-typedef enum {
-       BW_CS_INPUT, /**< Input from the client */
-       BW_CS_SCRIPT_ERROR, /**< Error from some running script */
-       BW_CS_SCRIPT_CONSOLE, /**< Logging from some running script */
-} browser_window_console_source;
-
-/**
- * Flags for browser window console logging.
- *
- * It is valid to bitwise-or some of these flags together where indicated.
- */
-typedef enum {
-       /**
-        * The log entry is foldable.
-        *
-        * Set this to indicate that the text should be folded on the first
-        * newline on display.  If this is set but there are no newlines in
-        * the logged text, the core will unset it before passing on to
-        * callbacks or storing the log entry.
-        */
-       BW_CS_FLAG_FOLDABLE = 1 << 0,
-
-       /** Logged at the 'log' level, please only use one of the LEVEL flags */
-       BW_CS_FLAG_LEVEL_LOG = 0 << 1,
-       /** Logged at the 'info' level, please use only one of the LEVEL flags 
*/
-       BW_CS_FLAG_LEVEL_INFO = 1 << 1,
-       /** Logged at the 'warn' level, please use only one of the LEVEL flags 
*/
-       BW_CS_FLAG_LEVEL_WARN = 2 << 1,
-       /** Logged at the 'error' level, please use only one of the LEVEL flags 
*/
-       BW_CS_FLAG_LEVEL_ERROR = 3 << 1,
-       /** Mask for the error level to allow easy comparison using the above */
-       BW_CS_FLAG_LEVEL_MASK = 3 << 1,
-} browser_window_console_flags;
-
-/**
  * Create and open a new root browser window with the given page.
  *
  * \param flags                Flags to control operation
diff --git a/include/netsurf/console.h b/include/netsurf/console.h
new file mode 100644
index 0000000..31ed0e7
--- /dev/null
+++ b/include/netsurf/console.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2019 Daniel Silverstone <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Browser window console stuff
+ */
+
+#ifndef _NETSURF_CONSOLE_H_
+#define _NETSURF_CONSOLE_H_
+
+/**
+ * Sources of messages which end up in the browser window console
+ */
+typedef enum {
+       BW_CS_INPUT, /**< Input from the client */
+       BW_CS_SCRIPT_ERROR, /**< Error from some running script */
+       BW_CS_SCRIPT_CONSOLE, /**< Logging from some running script */
+} browser_window_console_source;
+
+/**
+ * Flags for browser window console logging.
+ *
+ * It is valid to bitwise-or some of these flags together where indicated.
+ */
+typedef enum {
+       /**
+        * The log entry is foldable.
+        *
+        * Set this to indicate that the text should be folded on the first
+        * newline on display.  If this is set but there are no newlines in
+        * the logged text, the core will unset it before passing on to
+        * callbacks or storing the log entry.
+        */
+       BW_CS_FLAG_FOLDABLE = 1 << 0,
+
+       /** Logged at the 'log' level, please only use one of the LEVEL flags */
+       BW_CS_FLAG_LEVEL_LOG = 0 << 1,
+       /** Logged at the 'info' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_INFO = 1 << 1,
+       /** Logged at the 'warn' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_WARN = 2 << 1,
+       /** Logged at the 'error' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_ERROR = 3 << 1,
+       /** Mask for the error level to allow easy comparison using the above */
+       BW_CS_FLAG_LEVEL_MASK = 3 << 1,
+} browser_window_console_flags;
+
+#endif /* _NETSURF_CONSOLE_H_ */
+


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=6952a239465811c26838e177d35222fd5229e393
commit 6952a239465811c26838e177d35222fd5229e393
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Provide new browser_window_console_log() API
    
    Signed-off-by: Daniel Silverstone <[email protected]>

diff --git a/desktop/browser.c b/desktop/browser.c
index d26abd0..1a74935 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -3427,3 +3427,46 @@ bool browser_window_exec(struct browser_window *bw, 
const char *src, size_t srcl
         */
        return content_exec(bw->current_content, src, srclen);
 }
+
+/* exported interface documented in browser_window.h */
+nserror browser_window_console_log(struct browser_window *bw,
+                                  browser_window_console_source src,
+                                  const char *msg,
+                                  size_t msglen,
+                                  browser_window_console_flags flags)
+{
+       browser_window_console_flags log_level = flags & BW_CS_FLAG_LEVEL_MASK;
+       struct browser_window *root = browser_window_get_root(bw);
+
+       assert(msg != NULL);
+       assert(msglen > 0);
+
+       /* bw is the target of the log, but root is where we log it */
+
+       NSLOG(netsurf, DEEPDEBUG, "Logging message in %p targetted at %p", 
root, bw);
+       NSLOG(netsurf, DEEPDEBUG, "Log came from %s",
+             ((src == BW_CS_INPUT) ? "user input" :
+              (src == BW_CS_SCRIPT_ERROR) ? "script error" :
+              (src == BW_CS_SCRIPT_CONSOLE) ? "script console" :
+              "unknown input location"));
+
+       switch (log_level) {
+       case BW_CS_FLAG_LEVEL_LOG:
+               NSLOG(netsurf, VERBOSE, "%.*s", (int)msglen, msg);
+               break;
+       case BW_CS_FLAG_LEVEL_INFO:
+               NSLOG(netsurf, INFO, "%.*s", (int)msglen, msg);
+               break;
+       case BW_CS_FLAG_LEVEL_WARN:
+               NSLOG(netsurf, WARNING, "%.*s", (int)msglen, msg);
+               break;
+       case BW_CS_FLAG_LEVEL_ERROR:
+               NSLOG(netsurf, ERROR, "%.*s", (int)msglen, msg);
+               break;
+       default:
+               /* Unreachable */
+               break;
+       }
+       
+       return NSERROR_OK;
+}
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index 77a2631..9c6fe7a 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -144,6 +144,43 @@ struct browser_window_features {
 };
 
 /**
+ * Sources of messages which end up in the browser window console
+ */
+typedef enum {
+       BW_CS_INPUT, /**< Input from the client */
+       BW_CS_SCRIPT_ERROR, /**< Error from some running script */
+       BW_CS_SCRIPT_CONSOLE, /**< Logging from some running script */
+} browser_window_console_source;
+
+/**
+ * Flags for browser window console logging.
+ *
+ * It is valid to bitwise-or some of these flags together where indicated.
+ */
+typedef enum {
+       /**
+        * The log entry is foldable.
+        *
+        * Set this to indicate that the text should be folded on the first
+        * newline on display.  If this is set but there are no newlines in
+        * the logged text, the core will unset it before passing on to
+        * callbacks or storing the log entry.
+        */
+       BW_CS_FLAG_FOLDABLE = 1 << 0,
+
+       /** Logged at the 'log' level, please only use one of the LEVEL flags */
+       BW_CS_FLAG_LEVEL_LOG = 0 << 1,
+       /** Logged at the 'info' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_INFO = 1 << 1,
+       /** Logged at the 'warn' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_WARN = 2 << 1,
+       /** Logged at the 'error' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_ERROR = 3 << 1,
+       /** Mask for the error level to allow easy comparison using the above */
+       BW_CS_FLAG_LEVEL_MASK = 3 << 1,
+} browser_window_console_flags;
+
+/**
  * Create and open a new root browser window with the given page.
  *
  * \param flags                Flags to control operation
@@ -737,4 +774,23 @@ nserror browser_window_set_name(struct browser_window *bw, 
const char *name);
  */
 bool browser_window_exec(struct browser_window *bw, const char *src, size_t 
srclen);
 
+/**
+ * Log a console message into the browser window console.
+ *
+ * If the targetted browser window is a frame, the message will be bubbled
+ * to the outermost window to be logged.
+ *
+ * \param bw The browser window
+ * \param src The source of the message
+ * \param msg The text of the message
+ * \param msglen The length of the text of the message
+ * \param flags Flags for the message
+ * \return Whether or not the logged message succeeded in being stored
+ */
+nserror browser_window_console_log(struct browser_window *bw,
+                                  browser_window_console_source src,
+                                  const char *msg,
+                                  size_t msglen,
+                                  browser_window_console_flags flags);
+
 #endif


-----------------------------------------------------------------------

Summary of changes:
 content/content.h                                |    9 +++
 content/handlers/html/html.c                     |    2 +-
 content/handlers/javascript/duktape/Console.bnd  |   33 ++++++++--
 content/handlers/javascript/duktape/Document.bnd |    4 +-
 content/handlers/javascript/duktape/dukky.c      |   19 ++++--
 content/handlers/javascript/duktape/dukky.h      |    3 +
 content/handlers/javascript/duktape/generics.js  |   76 ++++++++++++++++++++++
 desktop/browser.c                                |   50 ++++++++++++++
 include/netsurf/browser_window.h                 |   20 ++++++
 include/netsurf/console.h                        |   65 ++++++++++++++++++
 test/js/inserted-script-async.js                 |    2 +-
 11 files changed, 267 insertions(+), 16 deletions(-)
 create mode 100644 include/netsurf/console.h

diff --git a/content/content.h b/content/content.h
index 77cc605..417fb7b 100644
--- a/content/content.h
+++ b/content/content.h
@@ -33,6 +33,7 @@
 #include "content/content_factory.h"
 #include "desktop/search.h" /* search flags enum */
 #include "netsurf/mouse.h" /* mouse state enums */
+#include "netsurf/console.h" /* console state and flags enums */
 
 struct browser_window;
 struct browser_window_features;
@@ -56,6 +57,7 @@ typedef enum {
 
 /** Used in callbacks to indicate what has occurred. */
 typedef enum {
+       CONTENT_MSG_LOG,       /**< Content wishes to log something */
        CONTENT_MSG_LOADING,   /**< fetching or converting */
        CONTENT_MSG_READY,     /**< may be displayed */
        CONTENT_MSG_DONE,      /**< finished */
@@ -95,6 +97,13 @@ struct content_rfc5988_link {
 
 /** Extra data for some content_msg messages. */
 union content_msg_data {
+       /** CONTENT_MSG_LOG - Information for logging */
+       struct {
+               browser_window_console_source src; /**< The source of the 
logging */
+               const char *msg; /**< The message to log */
+               size_t msglen; /**< The length of that message */
+               browser_window_console_flags flags; /**< The flags of the 
logging */
+       } log;
        /** CONTENT_MSG_ERROR - Error message */
        const char *error;
         /** CONTENT_MSG_ERRORCODE - Error code */
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index a47725b..4ffdb39 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -2514,7 +2514,7 @@ static bool html_exec(struct content *c, const char *src, 
size_t srclen)
        dom_text *text_node;
        dom_node *spare_node;
        dom_html_script_element *script_node;
-       
+
        if (htmlc->document == NULL) {
                NSLOG(netsurf, DEEPDEBUG, "Unable to exec, no document");
                goto out_no_string;
diff --git a/content/handlers/javascript/duktape/Console.bnd 
b/content/handlers/javascript/duktape/Console.bnd
index c4c0c83..acaab16 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 <nsutils/time.h>
+#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));
+       }
 }
 
 %};
diff --git a/content/handlers/javascript/duktape/Document.bnd 
b/content/handlers/javascript/duktape/Document.bnd
index d275917..9c63a61 100644
--- a/content/handlers/javascript/duktape/Document.bnd
+++ b/content/handlers/javascript/duktape/Document.bnd
@@ -18,7 +18,7 @@ prologue Document()
 #include "content/urldb.h"
 
 #define HANDLER_MAGIC MAGIC(HANDLER_MAP)
-#define LIST_PROXY_MAGIC MAGIC(LIST_PROXY)
+#define GENERICS_MAGIC MAGIC(GENERICS_TABLE)
 %}
 
 
@@ -345,7 +345,7 @@ method Document::getElementsByTagName()
 
        if (nodes == NULL) return 0; /* coerced to undefined */
 
-       duk_get_global_string(ctx, LIST_PROXY_MAGIC);
+       dukky_push_generics(ctx, "makeListProxy");
 
        duk_push_pointer(ctx, nodes);
        dukky_create_object(ctx, PROTO_NAME(NODELIST), 1);
diff --git a/content/handlers/javascript/duktape/dukky.c 
b/content/handlers/javascript/duktape/dukky.c
index 8af3165..d1bd4ec 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -48,7 +48,7 @@
 #define HANDLER_LISTENER_MAGIC MAGIC(HANDLER_LISTENER_MAP)
 #define HANDLER_MAGIC MAGIC(HANDLER_MAP)
 #define EVENT_LISTENER_JS_MAGIC MAGIC(EVENT_LISTENER_JS_MAP)
-#define LIST_PROXY_MAGIC MAGIC(LIST_PROXY)
+#define GENERICS_MAGIC MAGIC(GENERICS_TABLE)
 
 static duk_ret_t dukky_populate_object(duk_context *ctx, void *udata)
 {
@@ -663,11 +663,7 @@ jsobject *js_newcompartment(jscontext *ctx, void 
*win_priv, void *doc_priv)
        /* ..., Win */
        duk_get_prop_string(CTX, -1, "NetSurf");
        /* ..., Win, NetSurf */
-       duk_get_prop_string(CTX, -1, "makeListProxy");
-       /* ..., Win, NetSurf, MLP */
-       duk_put_global_string(CTX, LIST_PROXY_MAGIC);
-       /* ..., Win, NetSurf */
-       duk_pop(CTX);
+       duk_put_global_string(CTX, GENERICS_MAGIC);
        /* ..., Win */
        duk_del_prop_string(CTX, -1, "NetSurf");
        duk_pop(CTX);
@@ -754,6 +750,17 @@ duk_int_t dukky_pcall(duk_context *ctx, duk_size_t argc, 
bool reset_timeout)
 }
 
 
+void dukky_push_generics(duk_context *ctx, const char *generic)
+{
+       /* ... */
+       duk_get_global_string(ctx, GENERICS_MAGIC);
+       /* ..., generics */
+       duk_get_prop_string(ctx, -1, generic);
+       /* ..., generics, generic */
+       duk_remove(ctx, -2);
+       /* ..., generic */
+}
+
 bool js_exec(jscontext *ctx, const char *txt, size_t txtlen, const char *name)
 {
        assert(ctx);
diff --git a/content/handlers/javascript/duktape/dukky.h 
b/content/handlers/javascript/duktape/dukky.h
index ee9f474..93d4169 100644
--- a/content/handlers/javascript/duktape/dukky.h
+++ b/content/handlers/javascript/duktape/dukky.h
@@ -51,4 +51,7 @@ void dukky_shuffle_array(duk_context *ctx, duk_uarridx_t idx);
 /* pcall something, and if it errored, also dump the error to the log */
 duk_int_t dukky_pcall(duk_context *ctx, duk_size_t argc, bool reset_timeout);
 
+/* Push a generics function onto the stack */
+void dukky_push_generics(duk_context *ctx, const char *generic);
+
 #endif
diff --git a/content/handlers/javascript/duktape/generics.js 
b/content/handlers/javascript/duktape/generics.js
index ee5e801..6850c9b 100644
--- a/content/handlers/javascript/duktape/generics.js
+++ b/content/handlers/javascript/duktape/generics.js
@@ -27,4 +27,80 @@ var NetSurf = {
            },
        });
     },
+    consoleFormatter: function Formatter() {
+
+       if (arguments.length == 0) {
+           return new Array("");
+       } else if (arguments.length == 1) {
+           return new Array(arguments[0].toString());
+       }
+
+       const target = arguments[0];
+       const current = arguments[1];
+
+       if (typeof target !== "string") {
+           return Array.from(arguments);
+       }
+
+       const offset = target.search("%");
+
+       if (offset == -1 || offset >= target.length) {
+           // We've a string, but the % either doesn't exist or is
+           // at the end of it, so give up
+           return Array.from(arguments);
+       }
+
+       const specifier = target[offset + 1];
+
+       var converted = undefined;
+
+       if (specifier === 's') {
+           // Stringification
+           converted = current.toString();
+       } else if (specifier === 'd' || specifier === 'i') {
+           converted = parseInt(current, 10).toString();
+       } else if (specifier === 'f') {
+           converted = parseFloat(current).toString();
+       } else if (specifier === 'o') {
+           // TODO: Objectification?
+           converted = current.toString();
+       } else if (specifier === 'O') {
+           // TODO: JSONification
+           converted = current.toString();
+       }
+
+       var result = new Array();
+
+       if (converted !== undefined) {
+           // We converted it, so we need to absorb the formatted thing
+           // and move on
+           var newtarget = "";
+           if (offset > 0) {
+               newtarget = target.substring(0, offset);
+           }
+           newtarget = newtarget + converted;
+           if (offset < target.length - 2) {
+               newtarget = newtarget + target.substring(offset + 2, 
target.length);
+           }
+           result.push(newtarget);
+       } else {
+           // Undefined, so we drop this argument and move on
+           result.push(target);
+       }
+
+       var i;
+       for (i = 2; i < arguments.length; i++) {
+           result.push(arguments[i]);
+       }
+
+       if (result[0].search("%") == -1) {
+           return result;
+       }
+
+       if (result.length === 1) {
+           return result;
+       }
+
+       return Formatter.apply(result);
+    }
 };
diff --git a/desktop/browser.c b/desktop/browser.c
index d26abd0..dad830f 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1358,6 +1358,13 @@ browser_window_callback(hlcache_handle *c,
        float sx, sy;
 
        switch (event->type) {
+       case CONTENT_MSG_LOG:
+               browser_window_console_log(bw,
+                                          event->data.log.src,
+                                          event->data.log.msg,
+                                          event->data.log.msglen,
+                                          event->data.log.flags);
+               break;
        case CONTENT_MSG_DOWNLOAD:
                assert(bw->loading_content == c);
 
@@ -3427,3 +3434,46 @@ bool browser_window_exec(struct browser_window *bw, 
const char *src, size_t srcl
         */
        return content_exec(bw->current_content, src, srclen);
 }
+
+/* exported interface documented in browser_window.h */
+nserror browser_window_console_log(struct browser_window *bw,
+                                  browser_window_console_source src,
+                                  const char *msg,
+                                  size_t msglen,
+                                  browser_window_console_flags flags)
+{
+       browser_window_console_flags log_level = flags & BW_CS_FLAG_LEVEL_MASK;
+       struct browser_window *root = browser_window_get_root(bw);
+
+       assert(msg != NULL);
+       assert(msglen > 0);
+
+       /* bw is the target of the log, but root is where we log it */
+
+       NSLOG(netsurf, DEEPDEBUG, "Logging message in %p targetted at %p", 
root, bw);
+       NSLOG(netsurf, DEEPDEBUG, "Log came from %s",
+             ((src == BW_CS_INPUT) ? "user input" :
+              (src == BW_CS_SCRIPT_ERROR) ? "script error" :
+              (src == BW_CS_SCRIPT_CONSOLE) ? "script console" :
+              "unknown input location"));
+
+       switch (log_level) {
+       case BW_CS_FLAG_LEVEL_LOG:
+               NSLOG(netsurf, VERBOSE, "%.*s", (int)msglen, msg);
+               break;
+       case BW_CS_FLAG_LEVEL_INFO:
+               NSLOG(netsurf, INFO, "%.*s", (int)msglen, msg);
+               break;
+       case BW_CS_FLAG_LEVEL_WARN:
+               NSLOG(netsurf, WARNING, "%.*s", (int)msglen, msg);
+               break;
+       case BW_CS_FLAG_LEVEL_ERROR:
+               NSLOG(netsurf, ERROR, "%.*s", (int)msglen, msg);
+               break;
+       default:
+               /* Unreachable */
+               break;
+       }
+       
+       return NSERROR_OK;
+}
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index 77a2631..e701aa3 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -30,6 +30,7 @@
 
 #include "utils/errors.h"
 #include "netsurf/mouse.h"
+#include "netsurf/console.h"
 
 struct browser_window;
 struct hlcache_handle;
@@ -737,4 +738,23 @@ nserror browser_window_set_name(struct browser_window *bw, 
const char *name);
  */
 bool browser_window_exec(struct browser_window *bw, const char *src, size_t 
srclen);
 
+/**
+ * Log a console message into the browser window console.
+ *
+ * If the targetted browser window is a frame, the message will be bubbled
+ * to the outermost window to be logged.
+ *
+ * \param bw The browser window
+ * \param src The source of the message
+ * \param msg The text of the message
+ * \param msglen The length of the text of the message
+ * \param flags Flags for the message
+ * \return Whether or not the logged message succeeded in being stored
+ */
+nserror browser_window_console_log(struct browser_window *bw,
+                                  browser_window_console_source src,
+                                  const char *msg,
+                                  size_t msglen,
+                                  browser_window_console_flags flags);
+
 #endif
diff --git a/include/netsurf/console.h b/include/netsurf/console.h
new file mode 100644
index 0000000..31ed0e7
--- /dev/null
+++ b/include/netsurf/console.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2019 Daniel Silverstone <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Browser window console stuff
+ */
+
+#ifndef _NETSURF_CONSOLE_H_
+#define _NETSURF_CONSOLE_H_
+
+/**
+ * Sources of messages which end up in the browser window console
+ */
+typedef enum {
+       BW_CS_INPUT, /**< Input from the client */
+       BW_CS_SCRIPT_ERROR, /**< Error from some running script */
+       BW_CS_SCRIPT_CONSOLE, /**< Logging from some running script */
+} browser_window_console_source;
+
+/**
+ * Flags for browser window console logging.
+ *
+ * It is valid to bitwise-or some of these flags together where indicated.
+ */
+typedef enum {
+       /**
+        * The log entry is foldable.
+        *
+        * Set this to indicate that the text should be folded on the first
+        * newline on display.  If this is set but there are no newlines in
+        * the logged text, the core will unset it before passing on to
+        * callbacks or storing the log entry.
+        */
+       BW_CS_FLAG_FOLDABLE = 1 << 0,
+
+       /** Logged at the 'log' level, please only use one of the LEVEL flags */
+       BW_CS_FLAG_LEVEL_LOG = 0 << 1,
+       /** Logged at the 'info' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_INFO = 1 << 1,
+       /** Logged at the 'warn' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_WARN = 2 << 1,
+       /** Logged at the 'error' level, please use only one of the LEVEL flags 
*/
+       BW_CS_FLAG_LEVEL_ERROR = 3 << 1,
+       /** Mask for the error level to allow easy comparison using the above */
+       BW_CS_FLAG_LEVEL_MASK = 3 << 1,
+} browser_window_console_flags;
+
+#endif /* _NETSURF_CONSOLE_H_ */
+
diff --git a/test/js/inserted-script-async.js b/test/js/inserted-script-async.js
index 5552e27..aa6c0a3 100644
--- a/test/js/inserted-script-async.js
+++ b/test/js/inserted-script-async.js
@@ -1 +1 @@
-console.log("External asynchronous dynamism!");
+console.log("External %s dynamism!", "asynchronous");


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to