From 5496a604310b65db0513c063ed171f0168baee28 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 31 Oct 2012 14:31:18 +0000 Subject: console interface from IDL --- Makefile.sources.javascript | 5 +-- javascript/WebIDL/console.idl | 20 ++++++++++++ javascript/jsapi/binding.h | 3 +- javascript/jsapi/bindings/console.bnd | 59 +++++++++++++++++++++++++++++++++++ javascript/jsapi/bindings/window.bnd | 8 ++++- 5 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 javascript/WebIDL/console.idl create mode 100644 javascript/jsapi/bindings/console.bnd diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript index 626854869..f5c49f801 100644 --- a/Makefile.sources.javascript +++ b/Makefile.sources.javascript @@ -13,6 +13,7 @@ S_JSAPI_BINDING:= JSAPI_BINDING_htmldocument := javascript/jsapi/bindings/htmldocument.bnd JSAPI_BINDING_window := javascript/jsapi/bindings/window.bnd JSAPI_BINDING_navigator := javascript/jsapi/bindings/navigator.bnd +JSAPI_BINDING_console := javascript/jsapi/bindings/console.bnd # 1: input file # 2: output file @@ -30,8 +31,8 @@ endef # Javascript sources ifeq ($(NETSURF_USE_JS),YES) -S_JSAPI = console.c htmlelement.c -#htmldocument.c window.c navigator.c +S_JSAPI = htmlelement.c +#htmldocument.c window.c navigator.c console.c S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI)) diff --git a/javascript/WebIDL/console.idl b/javascript/WebIDL/console.idl new file mode 100644 index 000000000..309b976da --- /dev/null +++ b/javascript/WebIDL/console.idl @@ -0,0 +1,20 @@ +// de facto set of features for console object +// https://developer.mozilla.org/en-US/docs/DOM/console +// http://msdn.microsoft.com/en-us/library/dd565625%28v=vs.85%29.aspx#consolelogging +// 31st October +// Yay for non-standard standards + +interface Console { + void debug(DOMString msg, Substitition... subst); + void dir(JSObject object); + void error(DOMString msg, Substitition... subst); + void group(); + void groupCollapsed(); + void groupEnd(); + void info(DOMString msg, Substitition... subst); + void log(DOMString msg, Substitition... subst); + void time(DOMString timerName); + void timeEnd(DOMString timerName); + void trace(); + void warn(DOMString msg, Substitition... subst); +}; \ No newline at end of file diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h index 2d88c005b..80340a57a 100644 --- a/javascript/jsapi/binding.h +++ b/javascript/jsapi/binding.h @@ -57,13 +57,14 @@ JSObject *jsapi_new_Document(JSContext *cx, dom_document *node, struct html_content *htmlc); +JSObject *jsapi_InitClass_Console(JSContext *cx, JSObject *parent); /** Create a new javascript console object * * @param cx The javascript context. * @param parent The parent object, usually a global window object * @return new javascript object or NULL on error */ -JSObject *jsapi_new_Console(JSContext *cx, JSObject *parent); +JSObject *jsapi_new_Console(JSContext *cx, JSObject *prototype, JSObject *parent); JSObject *jsapi_InitClass_Navigator(JSContext *cx, JSObject *parent); diff --git a/javascript/jsapi/bindings/console.bnd b/javascript/jsapi/bindings/console.bnd new file mode 100644 index 000000000..6aef9dcb8 --- /dev/null +++ b/javascript/jsapi/bindings/console.bnd @@ -0,0 +1,59 @@ +/* Binding to generate Console interface + * + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * Released under the terms of the MIT License, + * http://www.opensource.org/licenses/mit-license + */ + +webidlfile "console.idl"; + +hdrcomment "Copyright 2012 Vincent Sanders "; +hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; +hdrcomment "Released under the terms of the MIT License,"; +hdrcomment " http://www.opensource.org/licenses/mit-license"; + +preamble %{ + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +%} + +binding navigator { + type js_libdom; /* the binding type */ + + interface Console; /* Web IDL interface to generate */ + + /* private members: + * - stored in private context structure. + * - passed as parameters to constructor and stored automatically. + * - are *not* considered for property getters/setters. + * + * internal members: + * - value stored in private context structure + * - not passed to constructor + * - must be instantiated by constructor + * - are considered for property getters/setters. + */ + internal "void *" gui_console; +} + +operation log %{ + unsigned int argloop; + JSString *jsstr; + unsigned long jsstrlen; + char *txt; + + for (argloop = 0; argloop < argc; argloop++) { + jsstr = JS_ValueToString(cx, argv[argloop]); + + JSString_to_char(jsstr, txt, jsstrlen); + LOG(("%s", txt)); + } +%} diff --git a/javascript/jsapi/bindings/window.bnd b/javascript/jsapi/bindings/window.bnd index 9d4a844a1..ba2db52b2 100644 --- a/javascript/jsapi/bindings/window.bnd +++ b/javascript/jsapi/bindings/window.bnd @@ -84,6 +84,12 @@ api init %{ if (user_proto == NULL) { return NULL; } + + user_proto = jsapi_InitClass_Console(cx, prototype); + if (user_proto == NULL) { + return NULL; + } + %} api new %{ @@ -112,7 +118,7 @@ api new %{ /** @todo forms, history, location */ - private->console = jsapi_new_Console(cx, newobject); + private->console = jsapi_new_Console(cx, NULL, newobject); if (private->console == NULL) { free(private); return NULL; -- cgit v1.2.3