console interface from IDL

This commit is contained in:
Vincent Sanders 2012-10-31 14:31:18 +00:00
parent ede48d6074
commit 5496a60431
5 changed files with 91 additions and 4 deletions

View File

@ -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))

View File

@ -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);
};

View File

@ -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);

View File

@ -0,0 +1,59 @@
/* Binding to generate Console interface
*
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
*
* 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 <vince@netsurf-browser.org>";
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));
}
%}

View File

@ -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;