From 48cbca0399836db3d6f52db7439d5a49a97643ed Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 2 Nov 2012 22:37:57 +0000 Subject: move bindings into the correct place --- javascript/jsapi/bindings/console.bnd | 59 -------- javascript/jsapi/bindings/dom.bnd | 26 ---- javascript/jsapi/bindings/example.bnd | 229 ----------------------------- javascript/jsapi/bindings/htmldocument.bnd | 40 ----- javascript/jsapi/bindings/htmlelement.bnd | 51 ------- javascript/jsapi/bindings/location.bnd | 53 ------- javascript/jsapi/bindings/navigator.bnd | 120 --------------- javascript/jsapi/bindings/window.bnd | 165 --------------------- javascript/jsapi/console.bnd | 59 ++++++++ javascript/jsapi/dom.bnd | 26 ++++ javascript/jsapi/example.bnd | 229 +++++++++++++++++++++++++++++ javascript/jsapi/htmldocument.bnd | 40 +++++ javascript/jsapi/htmlelement.bnd | 51 +++++++ javascript/jsapi/location.bnd | 53 +++++++ javascript/jsapi/navigator.bnd | 120 +++++++++++++++ javascript/jsapi/window.bnd | 165 +++++++++++++++++++++ 16 files changed, 743 insertions(+), 743 deletions(-) delete mode 100644 javascript/jsapi/bindings/console.bnd delete mode 100644 javascript/jsapi/bindings/dom.bnd delete mode 100644 javascript/jsapi/bindings/example.bnd delete mode 100644 javascript/jsapi/bindings/htmldocument.bnd delete mode 100644 javascript/jsapi/bindings/htmlelement.bnd delete mode 100644 javascript/jsapi/bindings/location.bnd delete mode 100644 javascript/jsapi/bindings/navigator.bnd delete mode 100644 javascript/jsapi/bindings/window.bnd create mode 100644 javascript/jsapi/console.bnd create mode 100644 javascript/jsapi/dom.bnd create mode 100644 javascript/jsapi/example.bnd create mode 100644 javascript/jsapi/htmldocument.bnd create mode 100644 javascript/jsapi/htmlelement.bnd create mode 100644 javascript/jsapi/location.bnd create mode 100644 javascript/jsapi/navigator.bnd create mode 100644 javascript/jsapi/window.bnd (limited to 'javascript') diff --git a/javascript/jsapi/bindings/console.bnd b/javascript/jsapi/bindings/console.bnd deleted file mode 100644 index 6aef9dcb8..000000000 --- a/javascript/jsapi/bindings/console.bnd +++ /dev/null @@ -1,59 +0,0 @@ -/* 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/dom.bnd b/javascript/jsapi/bindings/dom.bnd deleted file mode 100644 index 362c828f6..000000000 --- a/javascript/jsapi/bindings/dom.bnd +++ /dev/null @@ -1,26 +0,0 @@ -/* DOM bindings entries */ - -webidlfile "dom.idl"; - -operation getElementById %{ - dom_string *elementId_dom; - dom_element *element; - dom_exception exc; - - dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom); - - exc = dom_document_get_element_by_id(private->node, elementId_dom, &element); - if ((exc == DOM_NO_ERR) && (element != NULL)) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); - } -%} - -getter textContent %{ - dom_exception exc; - dom_string *content; - - exc = dom_node_get_text_content(private->node, &content); - if ((exc == DOM_NO_ERR) && (content != NULL)) { - jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content)); - } -%} diff --git a/javascript/jsapi/bindings/example.bnd b/javascript/jsapi/bindings/example.bnd deleted file mode 100644 index f2f81fb2d..000000000 --- a/javascript/jsapi/bindings/example.bnd +++ /dev/null @@ -1,229 +0,0 @@ -/* Example binding to generate Example interface - * - * The js_libdom (javascript to libdom) binding type is currently the - * only one implemented and this principly describes that binding. - * - * 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 - */ - -/* additional binding fragments may be included - * Note: this is not preprocessed despite the #include name, the - * parser will simply switch input to the included file and carry on - * cosntructing the bindings Abstract Syntax Tree (AST) - */ -#include "dom.bnd" - -/* directive to read WebIDL file and add its contents to the webidl AST */ -webidlfile "html.idl"; - -/* The hdrcomment are added into the geenrated output comment header */ -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"; - -/* the preamble block is copied verbatum into the generated output - * - * This can be used for includes, comments or whatever else is desired - */ -preamble %{ - -#include - -#include "utils/config.h" -#include "utils/log.h" - -#include "javascript/jsapi.h" -#include "javascript/jsapi/binding.h" - -%} - -/* this block describes the binding to be generated - * - * Depending on the type of binding being generated multiple blocks - * may be allowed. - * - * Note: the js_libdom (javascript to libdom) binding as currently - * implemented only allows for a single binding per file, this may - * be improved in future. - */ -binding example { - type js_libdom; /* the binding type */ - - interface Navigator; /* The WebIDL interface to generate a binding for */ - - /* private members: - * - stored in private context structure. - * - passed as parameters to constructor and stored automatically. - * - are *not* considered for property getters/setters. - */ - private "dom_document *" node; - - /* 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 *" fluff; - -} - -/* operation implementation code. - * - * The body is copied verbatum into operation binding - * - * several values are generated automatically: - * - * - The generated operations use a macro to create a JSNative JSAPI - * callback. The interface allows a uniform interface despite the - * evolution of the interface over differing spidermonkey versions. - * - * - The above implies the javascript context is in a variable called cx - * - * - If private or internal binding members are present they may be - * accessed through a structure named "private" - * - * - if there are arguemnts they may be accesed via an argc/argv jsval - * vector. - * - * - Arguments are automatically converted into c variables (named as - * per the WebIDL names. - * - * - Return values (excepting void return types where its omitted) are - * always named "retval" and are of the appropriate c type. The - * initial value is set appropriately. - */ -operation foo %{ - retval = JS_NewStringCopyN(cx, "foo", SLEN("foo")); -%} - -/* property getter implementation code. - * - * The body is copied verbatum into property getter binding - * - * several values are generated automatically: - * - * - The generated operations use a macro to create a JSPropertyOp - * JSAPI callback. The interface allows a uniform interface despite - * the evolution of the interface over differing spidermonkey - * versions. - * - * - The above implies the javascript context is available in a - * variable called "cx". - * - * - If private or internal binding members are present they may be - * accessed through a structure named "private" - * - * - Return values (void on a getter is not possible) are always named - * "retval" and are of the appropriate c type. The initial value is - * set appropriately. - * - * - If the getter is omitted altogether but an internal or private - * value of the same name appears in the private structure a getter - * is automatically constructed to return that value. - */ -getter bar %{ - retval = JS_NewStringCopyN(cx, "bar", SLEN("bar")); -%} - -/* property setter implementation code. - * - * The body is copied verbatum into property getter binding - * - * several values are generated automatically: - * - * - The generated operations use a macro to create a JSPropertyOp - * JSAPI callback. The interface allows a uniform interface despite - * the evolution of the interface over differing spidermonkey - * versions. - * - * - The above implies the javascript context is available in a - * variable called "cx". - * - * - If private or internal binding members are present they may be - * accessed through a structure named "private" - * - * - Value to set is placed in a c variable named "setval" of the - * appropriate type. - * - * - Return value, named retval" is a boolean (default true) which - * indicates if the set was performed. - * - * - If the setter is omitted altogether but an internal or private - * value of the same name appears in the private structure a setter - * is automatically constructed to assign that value. - */ -setter baz %{ - printf("%s\n", setval); -%} - -/* implementation of the class initilisation - * - * This allows the default JS_InitClass to be overriden - currently - * only used for the window (global) object to cause all the other class - * initialisors to be called. - * - * function prototype is: - * JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent) - */ -api init %{ - %} - -/* implementation of the c instance creation - * - * This allows the overriding of the construction of an interface instance. - * - * The body is copied verbatum and must return the new object in the - * "newobject" variable. - * - * The base prototype is - * JSObject *jsapi_new_HTMLElement(JSContext *cx, JSObject *prototype, JSObject *parent, ...) - * The varadic elements are private variables as specified in the binding - * - * If there are private or internal values the private struct is - * constructed and instantiated. The struct is available during the - * new function and is automatically attached as the private value to - * the object. - * - * The default implemenattion simply calls JS_NewObject() - * - * Note this does *not* rely upon (or even call) the instances - * javascript constructor allowing the c code to create objects that - * cannot be instantiated from javascript. - * - */ -api new %{ - %} - -/* additional code in the instance finalise operation. - * - * The body is copied verbatum into the output - * - * Prototype is - * void jsclass_finalize(JSContext *cx, JSObject *obj) - * - * private is available (if appropriate) and freed after the body - */ -api finalise %{ - %} - -/* resolver code - * - * A resolver is only generated if this api is provided. This is a - * JSResolveOp with JSCLASS_NEW_RESOLVE specified and must provide a - * complete implementation. - * - * The body is copied verbatum into the output - * - * Prototype is: - * JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) - * - */ -api resolve %{ - %} diff --git a/javascript/jsapi/bindings/htmldocument.bnd b/javascript/jsapi/bindings/htmldocument.bnd deleted file mode 100644 index c90114162..000000000 --- a/javascript/jsapi/bindings/htmldocument.bnd +++ /dev/null @@ -1,40 +0,0 @@ -/* Binding to generate htmldocument */ - -#include "dom.bnd" - -webidlfile "html.idl"; - -hdrcomment "Part of NetSurf Project"; - -preamble %{ - -#include - -#include "utils/config.h" -#include "utils/log.h" - -#include "javascript/jsapi.h" -#include "javascript/jsapi/binding.h" - -%} - -operation write %{ - LOG(("content %p parser %p writing %s", - private->htmlc, private->htmlc->parser, text)); - - if (private->htmlc->parser != NULL) { - dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len); - } -%} - -binding document { - type js_libdom; /* the binding type */ - - /* parameters to constructor value stored in private - * context structure. - */ - private "dom_document *" node; - private "struct html_content *" htmlc; - - interface Document; /* Web IDL interface to generate */ -} diff --git a/javascript/jsapi/bindings/htmlelement.bnd b/javascript/jsapi/bindings/htmlelement.bnd deleted file mode 100644 index 596bb7de0..000000000 --- a/javascript/jsapi/bindings/htmlelement.bnd +++ /dev/null @@ -1,51 +0,0 @@ -/* Binding to generate HTMLElement 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 - */ - -#include "dom.bnd" - -webidlfile "html.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 - -#include "utils/config.h" -#include "utils/log.h" - -#include "javascript/jsapi.h" -#include "javascript/jsapi/binding.h" - -%} - -binding htmlelement { - type js_libdom; /* the binding type */ - - interface HTMLElement; /* 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. - */ - private "dom_element *" node; - private "struct html_content *" htmlc; -} - diff --git a/javascript/jsapi/bindings/location.bnd b/javascript/jsapi/bindings/location.bnd deleted file mode 100644 index c83fe46e3..000000000 --- a/javascript/jsapi/bindings/location.bnd +++ /dev/null @@ -1,53 +0,0 @@ -/* Binding to generate Location 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 - */ - -#include "dom.bnd" - -webidlfile "html.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 "desktop/browser.h" - -#include "utils/config.h" -#include "utils/log.h" - -#include "javascript/jsapi.h" -#include "javascript/jsapi/binding.h" - -%} - -binding location { - type js_libdom; /* the binding type */ - - interface Location; /* 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. - */ - private "struct browser_window *" bw; -} - -operation reload %{ - browser_window_reload(private->bw, false); -%} diff --git a/javascript/jsapi/bindings/navigator.bnd b/javascript/jsapi/bindings/navigator.bnd deleted file mode 100644 index e63e9a9fd..000000000 --- a/javascript/jsapi/bindings/navigator.bnd +++ /dev/null @@ -1,120 +0,0 @@ -/* Binding to generate Navigator 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 - */ - -#include "dom.bnd" - -webidlfile "html.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 -#include - -#include "desktop/netsurf.h" -#include "desktop/options.h" - -#include "utils/config.h" -#include "utils/useragent.h" -#include "utils/log.h" -#include "utils/utsname.h" - -#include "javascript/jsapi.h" -#include "javascript/jsapi/binding.h" - -/* - * navigator properties for netsurf - * - * Property | Everyone else | NetSurf | Notes - * ------------+-----------------+--------------+------------------------------ - * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless - * | | | constant as everyone returns - * | | | "Mozilla" which is dumb - * ------------+-----------------+--------------+------------------------------ - * appName | "" | "NetSurf" | Browsers named other than - * | | | "Netscape", "Mozilla", - * | | | "Netscape Navigator", - * | | | "Microsoft Internet Explorer" - * | | | often other browser have - * | | | "(compatible with Netscape)" - * | | | append. - * ------------+-----------------+--------------+------------------------------ - * appVersion | " ()"| "" | Actually just the version - * | | | number e.g "3.0". - * ------------+-----------------+--------------+------------------------------ - * language | "" | "" | The language the frontend is - * | | | configured for - * ------------+-----------------+--------------+------------------------------ - * platform | " " | " " | Efectively uname -s -i, - * | | | eg "Linux x86_64" - * ------------+-----------------+--------------+------------------------------ - * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string - * | | | with excessive lies - * ------------+-----------------+--------------+------------------------------ - */ - -#define NAVIGATOR_APPNAME "NetSurf" -#define NAVIGATOR_APPCODENAME "NetSurf" -%} - -binding navigator { - type js_libdom; /* the binding type */ - - interface Navigator; /* Web IDL interface to generate */ - -} - -getter appName %{ - jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME); -%} - -getter appCodeName %{ - jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME); -%} - -getter appVersion %{ - jsret = JS_NewStringCopyZ(cx, netsurf_version); -%} - -getter language %{ - const char *alang = nsoption_charp(accept_language); - - if (alang != NULL) { - jsret = JS_NewStringCopyZ(cx, alang); - } - -%} - -getter platform %{ - struct utsname *cutsname; - - cutsname = malloc(sizeof(struct utsname)); - - if ((cutsname != NULL) && (uname(cutsname) >= 0)) { - char *platstr; - int platstrlen; - - platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2; - platstr = malloc(platstrlen); - if (platstr != NULL) { - snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine); - jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1); - free(platstr); - } - } -%} - -getter userAgent %{ - jsret = JS_NewStringCopyZ(cx, user_agent_string()); -%} diff --git a/javascript/jsapi/bindings/window.bnd b/javascript/jsapi/bindings/window.bnd deleted file mode 100644 index 956932c77..000000000 --- a/javascript/jsapi/bindings/window.bnd +++ /dev/null @@ -1,165 +0,0 @@ -/* binding to generate window */ - -#include "dom.bnd" - -webidlfile "html.idl"; - -hdrcomment "Part of NetSurf Project"; - -preamble %{ - -#include - -#include "utils/config.h" -#include "utils/log.h" - -#include "javascript/jsapi.h" -#include "javascript/jsapi/binding.h" - -%} - -binding window { - type js_libdom; /* the binding type */ - - interface Window; /* Web IDL interface to generate */ - - /* private are parameters to constructor stored in private - * context structure. - * - * internal are value stored in private context structure but not - * passed to constructor but are considered for property - * getters/setters. - */ - private "struct browser_window *" bw; - private "struct html_content *" htmlc; - internal "JSObject *" document; - internal "JSObject *" navigator; - internal "JSObject *" console; - internal "JSObject *" location; -} - - -api init %{ - JSObject *user_proto; - - prototype = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL); - if (prototype == NULL) { - return NULL; - } - - /** @todo reconsider global object handling. future - * editions of spidermonkey appear to be removing the - * idea of a global so we probably need to handle - * global object references internally - */ - - /* set the contexts global */ - JS_SetGlobalObject(cx, prototype); - - /* Populate the global object with the standard globals, like - * Object and Array. - */ - if (!JS_InitStandardClasses(cx, prototype)) { - return NULL; - } - - /* add functions to prototype */ - if (!JS_DefineFunctions(cx, prototype, jsclass_functions)) { - return NULL; - } - - /* add properties to prototype */ - if (!JS_DefineProperties(cx, prototype, jsclass_properties)) - return NULL; - - /* Initialises all the user javascript classes to make their - * prototypes available. - */ - /** @todo should we be managing these prototype objects ourselves */ - user_proto = jsapi_InitClass_Document(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Navigator(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Location(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_Console(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - - user_proto = jsapi_InitClass_HTMLElement(cx, prototype); - if (user_proto == NULL) { - return NULL; - } - -%} - -api new %{ - /* @todo sort out windows that are not globals */ - assert(parent == NULL); - - /* the window object is the global so its prototype *is* the instance */ - newobject = prototype; - - /* instantiate the subclasses off the window global */ - private->document = jsapi_new_Document(cx, - NULL, - newobject, - htmlc->document, - htmlc); - if (private->document == NULL) { - free(private); - return NULL; - } - - private->navigator = jsapi_new_Navigator(cx, NULL, newobject); - if (private->navigator == NULL) { - free(private); - return NULL; - } - - private->location = jsapi_new_Location(cx, NULL, newobject, bw); - if (private->location == NULL) { - free(private); - return NULL; - } - - private->console = jsapi_new_Console(cx, NULL, newobject); - if (private->console == NULL) { - free(private); - return NULL; - } - - /** @todo forms, history */ - - LOG(("Created new window object %p", newobject)); -%} - -operation confirm %{ - warn_user(message, NULL); -%} - -operation alert %{ - warn_user(message, NULL); -%} - -operation prompt %{ - warn_user(message, NULL); -%} - -getter window %{ - jsret = obj; -%} - -getter self %{ - jsret = obj; -%} diff --git a/javascript/jsapi/console.bnd b/javascript/jsapi/console.bnd new file mode 100644 index 000000000..6aef9dcb8 --- /dev/null +++ b/javascript/jsapi/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/dom.bnd b/javascript/jsapi/dom.bnd new file mode 100644 index 000000000..362c828f6 --- /dev/null +++ b/javascript/jsapi/dom.bnd @@ -0,0 +1,26 @@ +/* DOM bindings entries */ + +webidlfile "dom.idl"; + +operation getElementById %{ + dom_string *elementId_dom; + dom_element *element; + dom_exception exc; + + dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom); + + exc = dom_document_get_element_by_id(private->node, elementId_dom, &element); + if ((exc == DOM_NO_ERR) && (element != NULL)) { + jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); + } +%} + +getter textContent %{ + dom_exception exc; + dom_string *content; + + exc = dom_node_get_text_content(private->node, &content); + if ((exc == DOM_NO_ERR) && (content != NULL)) { + jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content)); + } +%} diff --git a/javascript/jsapi/example.bnd b/javascript/jsapi/example.bnd new file mode 100644 index 000000000..f2f81fb2d --- /dev/null +++ b/javascript/jsapi/example.bnd @@ -0,0 +1,229 @@ +/* Example binding to generate Example interface + * + * The js_libdom (javascript to libdom) binding type is currently the + * only one implemented and this principly describes that binding. + * + * 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 + */ + +/* additional binding fragments may be included + * Note: this is not preprocessed despite the #include name, the + * parser will simply switch input to the included file and carry on + * cosntructing the bindings Abstract Syntax Tree (AST) + */ +#include "dom.bnd" + +/* directive to read WebIDL file and add its contents to the webidl AST */ +webidlfile "html.idl"; + +/* The hdrcomment are added into the geenrated output comment header */ +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"; + +/* the preamble block is copied verbatum into the generated output + * + * This can be used for includes, comments or whatever else is desired + */ +preamble %{ + +#include + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +%} + +/* this block describes the binding to be generated + * + * Depending on the type of binding being generated multiple blocks + * may be allowed. + * + * Note: the js_libdom (javascript to libdom) binding as currently + * implemented only allows for a single binding per file, this may + * be improved in future. + */ +binding example { + type js_libdom; /* the binding type */ + + interface Navigator; /* The WebIDL interface to generate a binding for */ + + /* private members: + * - stored in private context structure. + * - passed as parameters to constructor and stored automatically. + * - are *not* considered for property getters/setters. + */ + private "dom_document *" node; + + /* 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 *" fluff; + +} + +/* operation implementation code. + * + * The body is copied verbatum into operation binding + * + * several values are generated automatically: + * + * - The generated operations use a macro to create a JSNative JSAPI + * callback. The interface allows a uniform interface despite the + * evolution of the interface over differing spidermonkey versions. + * + * - The above implies the javascript context is in a variable called cx + * + * - If private or internal binding members are present they may be + * accessed through a structure named "private" + * + * - if there are arguemnts they may be accesed via an argc/argv jsval + * vector. + * + * - Arguments are automatically converted into c variables (named as + * per the WebIDL names. + * + * - Return values (excepting void return types where its omitted) are + * always named "retval" and are of the appropriate c type. The + * initial value is set appropriately. + */ +operation foo %{ + retval = JS_NewStringCopyN(cx, "foo", SLEN("foo")); +%} + +/* property getter implementation code. + * + * The body is copied verbatum into property getter binding + * + * several values are generated automatically: + * + * - The generated operations use a macro to create a JSPropertyOp + * JSAPI callback. The interface allows a uniform interface despite + * the evolution of the interface over differing spidermonkey + * versions. + * + * - The above implies the javascript context is available in a + * variable called "cx". + * + * - If private or internal binding members are present they may be + * accessed through a structure named "private" + * + * - Return values (void on a getter is not possible) are always named + * "retval" and are of the appropriate c type. The initial value is + * set appropriately. + * + * - If the getter is omitted altogether but an internal or private + * value of the same name appears in the private structure a getter + * is automatically constructed to return that value. + */ +getter bar %{ + retval = JS_NewStringCopyN(cx, "bar", SLEN("bar")); +%} + +/* property setter implementation code. + * + * The body is copied verbatum into property getter binding + * + * several values are generated automatically: + * + * - The generated operations use a macro to create a JSPropertyOp + * JSAPI callback. The interface allows a uniform interface despite + * the evolution of the interface over differing spidermonkey + * versions. + * + * - The above implies the javascript context is available in a + * variable called "cx". + * + * - If private or internal binding members are present they may be + * accessed through a structure named "private" + * + * - Value to set is placed in a c variable named "setval" of the + * appropriate type. + * + * - Return value, named retval" is a boolean (default true) which + * indicates if the set was performed. + * + * - If the setter is omitted altogether but an internal or private + * value of the same name appears in the private structure a setter + * is automatically constructed to assign that value. + */ +setter baz %{ + printf("%s\n", setval); +%} + +/* implementation of the class initilisation + * + * This allows the default JS_InitClass to be overriden - currently + * only used for the window (global) object to cause all the other class + * initialisors to be called. + * + * function prototype is: + * JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent) + */ +api init %{ + %} + +/* implementation of the c instance creation + * + * This allows the overriding of the construction of an interface instance. + * + * The body is copied verbatum and must return the new object in the + * "newobject" variable. + * + * The base prototype is + * JSObject *jsapi_new_HTMLElement(JSContext *cx, JSObject *prototype, JSObject *parent, ...) + * The varadic elements are private variables as specified in the binding + * + * If there are private or internal values the private struct is + * constructed and instantiated. The struct is available during the + * new function and is automatically attached as the private value to + * the object. + * + * The default implemenattion simply calls JS_NewObject() + * + * Note this does *not* rely upon (or even call) the instances + * javascript constructor allowing the c code to create objects that + * cannot be instantiated from javascript. + * + */ +api new %{ + %} + +/* additional code in the instance finalise operation. + * + * The body is copied verbatum into the output + * + * Prototype is + * void jsclass_finalize(JSContext *cx, JSObject *obj) + * + * private is available (if appropriate) and freed after the body + */ +api finalise %{ + %} + +/* resolver code + * + * A resolver is only generated if this api is provided. This is a + * JSResolveOp with JSCLASS_NEW_RESOLVE specified and must provide a + * complete implementation. + * + * The body is copied verbatum into the output + * + * Prototype is: + * JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) + * + */ +api resolve %{ + %} diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd new file mode 100644 index 000000000..c90114162 --- /dev/null +++ b/javascript/jsapi/htmldocument.bnd @@ -0,0 +1,40 @@ +/* Binding to generate htmldocument */ + +#include "dom.bnd" + +webidlfile "html.idl"; + +hdrcomment "Part of NetSurf Project"; + +preamble %{ + +#include + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +%} + +operation write %{ + LOG(("content %p parser %p writing %s", + private->htmlc, private->htmlc->parser, text)); + + if (private->htmlc->parser != NULL) { + dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len); + } +%} + +binding document { + type js_libdom; /* the binding type */ + + /* parameters to constructor value stored in private + * context structure. + */ + private "dom_document *" node; + private "struct html_content *" htmlc; + + interface Document; /* Web IDL interface to generate */ +} diff --git a/javascript/jsapi/htmlelement.bnd b/javascript/jsapi/htmlelement.bnd new file mode 100644 index 000000000..596bb7de0 --- /dev/null +++ b/javascript/jsapi/htmlelement.bnd @@ -0,0 +1,51 @@ +/* Binding to generate HTMLElement 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 + */ + +#include "dom.bnd" + +webidlfile "html.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 + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +%} + +binding htmlelement { + type js_libdom; /* the binding type */ + + interface HTMLElement; /* 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. + */ + private "dom_element *" node; + private "struct html_content *" htmlc; +} + diff --git a/javascript/jsapi/location.bnd b/javascript/jsapi/location.bnd new file mode 100644 index 000000000..c83fe46e3 --- /dev/null +++ b/javascript/jsapi/location.bnd @@ -0,0 +1,53 @@ +/* Binding to generate Location 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 + */ + +#include "dom.bnd" + +webidlfile "html.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 "desktop/browser.h" + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +%} + +binding location { + type js_libdom; /* the binding type */ + + interface Location; /* 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. + */ + private "struct browser_window *" bw; +} + +operation reload %{ + browser_window_reload(private->bw, false); +%} diff --git a/javascript/jsapi/navigator.bnd b/javascript/jsapi/navigator.bnd new file mode 100644 index 000000000..e63e9a9fd --- /dev/null +++ b/javascript/jsapi/navigator.bnd @@ -0,0 +1,120 @@ +/* Binding to generate Navigator 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 + */ + +#include "dom.bnd" + +webidlfile "html.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 +#include + +#include "desktop/netsurf.h" +#include "desktop/options.h" + +#include "utils/config.h" +#include "utils/useragent.h" +#include "utils/log.h" +#include "utils/utsname.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +/* + * navigator properties for netsurf + * + * Property | Everyone else | NetSurf | Notes + * ------------+-----------------+--------------+------------------------------ + * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless + * | | | constant as everyone returns + * | | | "Mozilla" which is dumb + * ------------+-----------------+--------------+------------------------------ + * appName | "" | "NetSurf" | Browsers named other than + * | | | "Netscape", "Mozilla", + * | | | "Netscape Navigator", + * | | | "Microsoft Internet Explorer" + * | | | often other browser have + * | | | "(compatible with Netscape)" + * | | | append. + * ------------+-----------------+--------------+------------------------------ + * appVersion | " ()"| "" | Actually just the version + * | | | number e.g "3.0". + * ------------+-----------------+--------------+------------------------------ + * language | "" | "" | The language the frontend is + * | | | configured for + * ------------+-----------------+--------------+------------------------------ + * platform | " " | " " | Efectively uname -s -i, + * | | | eg "Linux x86_64" + * ------------+-----------------+--------------+------------------------------ + * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string + * | | | with excessive lies + * ------------+-----------------+--------------+------------------------------ + */ + +#define NAVIGATOR_APPNAME "NetSurf" +#define NAVIGATOR_APPCODENAME "NetSurf" +%} + +binding navigator { + type js_libdom; /* the binding type */ + + interface Navigator; /* Web IDL interface to generate */ + +} + +getter appName %{ + jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME); +%} + +getter appCodeName %{ + jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME); +%} + +getter appVersion %{ + jsret = JS_NewStringCopyZ(cx, netsurf_version); +%} + +getter language %{ + const char *alang = nsoption_charp(accept_language); + + if (alang != NULL) { + jsret = JS_NewStringCopyZ(cx, alang); + } + +%} + +getter platform %{ + struct utsname *cutsname; + + cutsname = malloc(sizeof(struct utsname)); + + if ((cutsname != NULL) && (uname(cutsname) >= 0)) { + char *platstr; + int platstrlen; + + platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2; + platstr = malloc(platstrlen); + if (platstr != NULL) { + snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine); + jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1); + free(platstr); + } + } +%} + +getter userAgent %{ + jsret = JS_NewStringCopyZ(cx, user_agent_string()); +%} diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd new file mode 100644 index 000000000..956932c77 --- /dev/null +++ b/javascript/jsapi/window.bnd @@ -0,0 +1,165 @@ +/* binding to generate window */ + +#include "dom.bnd" + +webidlfile "html.idl"; + +hdrcomment "Part of NetSurf Project"; + +preamble %{ + +#include + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +%} + +binding window { + type js_libdom; /* the binding type */ + + interface Window; /* Web IDL interface to generate */ + + /* private are parameters to constructor stored in private + * context structure. + * + * internal are value stored in private context structure but not + * passed to constructor but are considered for property + * getters/setters. + */ + private "struct browser_window *" bw; + private "struct html_content *" htmlc; + internal "JSObject *" document; + internal "JSObject *" navigator; + internal "JSObject *" console; + internal "JSObject *" location; +} + + +api init %{ + JSObject *user_proto; + + prototype = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL); + if (prototype == NULL) { + return NULL; + } + + /** @todo reconsider global object handling. future + * editions of spidermonkey appear to be removing the + * idea of a global so we probably need to handle + * global object references internally + */ + + /* set the contexts global */ + JS_SetGlobalObject(cx, prototype); + + /* Populate the global object with the standard globals, like + * Object and Array. + */ + if (!JS_InitStandardClasses(cx, prototype)) { + return NULL; + } + + /* add functions to prototype */ + if (!JS_DefineFunctions(cx, prototype, jsclass_functions)) { + return NULL; + } + + /* add properties to prototype */ + if (!JS_DefineProperties(cx, prototype, jsclass_properties)) + return NULL; + + /* Initialises all the user javascript classes to make their + * prototypes available. + */ + /** @todo should we be managing these prototype objects ourselves */ + user_proto = jsapi_InitClass_Document(cx, prototype); + if (user_proto == NULL) { + return NULL; + } + + user_proto = jsapi_InitClass_Navigator(cx, prototype); + if (user_proto == NULL) { + return NULL; + } + + user_proto = jsapi_InitClass_Location(cx, prototype); + if (user_proto == NULL) { + return NULL; + } + + user_proto = jsapi_InitClass_Console(cx, prototype); + if (user_proto == NULL) { + return NULL; + } + + user_proto = jsapi_InitClass_HTMLElement(cx, prototype); + if (user_proto == NULL) { + return NULL; + } + +%} + +api new %{ + /* @todo sort out windows that are not globals */ + assert(parent == NULL); + + /* the window object is the global so its prototype *is* the instance */ + newobject = prototype; + + /* instantiate the subclasses off the window global */ + private->document = jsapi_new_Document(cx, + NULL, + newobject, + htmlc->document, + htmlc); + if (private->document == NULL) { + free(private); + return NULL; + } + + private->navigator = jsapi_new_Navigator(cx, NULL, newobject); + if (private->navigator == NULL) { + free(private); + return NULL; + } + + private->location = jsapi_new_Location(cx, NULL, newobject, bw); + if (private->location == NULL) { + free(private); + return NULL; + } + + private->console = jsapi_new_Console(cx, NULL, newobject); + if (private->console == NULL) { + free(private); + return NULL; + } + + /** @todo forms, history */ + + LOG(("Created new window object %p", newobject)); +%} + +operation confirm %{ + warn_user(message, NULL); +%} + +operation alert %{ + warn_user(message, NULL); +%} + +operation prompt %{ + warn_user(message, NULL); +%} + +getter window %{ + jsret = obj; +%} + +getter self %{ + jsret = obj; +%} -- cgit v1.2.3