/* 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" %} operation confirm %{ warn_user(message, NULL); %} operation alert %{ warn_user(message, NULL); %} operation prompt %{ warn_user(message, NULL); %} api init %{ JSObject *window = NULL; JSObject *proto; window = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL); if (window == 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, window); /* Populate the global object with the standard globals, like * Object and Array. */ if (!JS_InitStandardClasses(cx, window)) { return NULL; } /* Initialises all the user javascript classes to make their * prototypes available. */ /** @todo should we be managing these prototype objects ourselves */ proto = jsapi_InitClass_Document(cx, window); if (proto == NULL) { return NULL; } return window; %} api new %{ struct jsclass_private *private; /* @todo sort out windows that are not globals */ assert(parent == NULL); /* create private data */ private = malloc(sizeof(struct jsclass_private)); if (private == NULL) { return NULL; } private->bw = bw; private->htmlc = htmlc; /* instantiate the subclasses off the window global */ private->document_obj = jsapi_new_Document(cx, NULL, window, htmlc->document, htmlc); if (private->document_obj == NULL) { free(private); return NULL; } /* private->navigator_obj = jsapi_new_Navigator(cx, window); if (private->navigator_obj == NULL) { free(private); return NULL; } */ /** @todo forms, history, location */ private->console_obj = jsapi_new_Console(cx, window); if (private->console_obj == NULL) { free(private); return NULL; } /* private pointer to browsing context */ if (!JS_SetPrivate(cx, window, private)) return NULL; /* functions */ if (!JS_DefineFunctions(cx, window, jsfunctions_window)) { return NULL; } /* properties */ if (!JS_DefineProperties(cx, window, jsproperties_window)) return NULL; LOG(("Created new window object %p", window)); return window; %} 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. */ private "struct browser_window *" bw; private "struct html_content *" htmlc; internal "JSObject *" document; internal "JSObject *" navigator; internal "JSObject *" console; }