From 99c54f1d9d198fc6ea9477ff58aafb76e5c1f20a Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 26 Oct 2012 12:36:14 +0100 Subject: split class prototype initialisation from instantiation --- javascript/jsapi.c | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) (limited to 'javascript/jsapi.c') diff --git a/javascript/jsapi.c b/javascript/jsapi.c index f7ac3eda1..4e980b5fd 100644 --- a/javascript/jsapi.c +++ b/javascript/jsapi.c @@ -17,6 +17,7 @@ */ #include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" #include "content/content.h" #include "javascript/content.h" @@ -90,46 +91,32 @@ void js_destroycontext(jscontext *ctx) } - +/** Create new compartment to run scripts within + * + * This performs the following actions + * 1. constructs a new global object by initialising a window class + * 2. Instantiate the global a window object + */ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv) { JSContext *cx = (JSContext *)ctx; - JSObject *window_obj = NULL; - JSObject *document_obj; - JSObject *navigator_obj; - JSObject *console_obj; - struct html_content *htmlc = doc_priv; - - if (cx == NULL) - goto js_newcompartment_fail; - - /* create the window object as the global */ - window_obj = jsapi_new_window(cx, NULL, win_priv); - if (window_obj == NULL) - goto js_newcompartment_fail; - - /* attach the subclasses off the window global */ - document_obj = jsapi_new_Document(cx, window_obj, htmlc->document, htmlc); - if (document_obj == NULL) - goto js_newcompartment_fail; - - navigator_obj = jsapi_new_navigator(cx, window_obj); - if (navigator_obj == NULL) - goto js_newcompartment_fail; + JSObject *window_proto; + JSObject *window; - /* @todo forms, history, location */ - - console_obj = jsapi_new_console(cx, window_obj); - if (console_obj == NULL) - goto js_newcompartment_fail; - - return (jsobject *)window_obj; + if (cx == NULL) { + return NULL; + } -js_newcompartment_fail: + window_proto = jsapi_InitClass_Window(cx, NULL); + if (window_proto == NULL) { + LOG(("Unable to initialise window class")); + return NULL; + } - LOG(("New compartment creation failed")); + window = jsapi_new_Window(cx, window_proto, NULL, win_priv, doc_priv); + + return (jsobject *)window; - return NULL; } bool js_exec(jscontext *ctx, const char *txt, size_t txtlen) -- cgit v1.2.3