diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2012-11-02 22:37:57 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2012-11-02 22:37:57 +0000 |
commit | 48cbca0399836db3d6f52db7439d5a49a97643ed (patch) | |
tree | e093529818c7cd5fca4c137ecc69584c1ac0896f /javascript/jsapi/window.bnd | |
parent | 7cb31505738ef0beaf984bebf8bb7f0529097f33 (diff) | |
download | netsurf-48cbca0399836db3d6f52db7439d5a49a97643ed.tar.gz netsurf-48cbca0399836db3d6f52db7439d5a49a97643ed.tar.bz2 |
move bindings into the correct place
Diffstat (limited to 'javascript/jsapi/window.bnd')
-rw-r--r-- | javascript/jsapi/window.bnd | 165 |
1 files changed, 165 insertions, 0 deletions
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 <dom/dom.h> + +#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; +%} |