diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-11-03 15:13:43 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-11-03 15:13:43 +0000 |
commit | 180f7ff42cc42862a39e9c18ba7556b3020bb647 (patch) | |
tree | 5ef0deef46801d4c1b47a86a2d373533d9c0bd74 /javascript/jsapi.c | |
parent | ef5c8c21a6dbf5db68743704a74066e01cc9a853 (diff) | |
parent | 45d508487af4a817fda3b536c2872f588291902b (diff) | |
download | netsurf-180f7ff42cc42862a39e9c18ba7556b3020bb647.tar.gz netsurf-180f7ff42cc42862a39e9c18ba7556b3020bb647.tar.bz2 |
Merge Vincent's Javascript work onto master
Diffstat (limited to 'javascript/jsapi.c')
-rw-r--r-- | javascript/jsapi.c | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/javascript/jsapi.c b/javascript/jsapi.c index fa8726b42..03e7ff5e3 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,43 +91,31 @@ 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; - - 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, doc_priv); - 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; + } - return NULL; + window = jsapi_new_Window(cx, window_proto, NULL, win_priv, doc_priv); + + return (jsobject *)window; } bool js_exec(jscontext *ctx, const char *txt, size_t txtlen) |