summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2012-06-10 22:17:30 +0000
committerVincent Sanders <vince@netsurf-browser.org>2012-06-10 22:17:30 +0000
commit4c89c9d5df511852f2743d277cf39611b49ce7f2 (patch)
tree07185cff7b5ab26416efe12c243f0d8ee76abe4a /desktop
parentfeb37dd067e7dac56fd5076badc7f2428134ef76 (diff)
downloadnetsurf-4c89c9d5df511852f2743d277cf39611b49ce7f2.tar.gz
netsurf-4c89c9d5df511852f2743d277cf39611b49ce7f2.tar.bz2
improve javascript support
svn path=/trunk/netsurf/; revision=13962
Diffstat (limited to 'desktop')
-rw-r--r--desktop/browser.c46
-rw-r--r--desktop/browser.h2
-rw-r--r--desktop/js.c104
-rw-r--r--desktop/js.h11
-rw-r--r--desktop/netsurf.c4
-rw-r--r--desktop/nojs.c24
6 files changed, 33 insertions, 158 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index 0f9ec2bc5..d43098003 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -54,7 +54,8 @@
#include "desktop/selection.h"
#include "desktop/textinput.h"
#include "desktop/plotters.h"
-#include "desktop/js.h"
+
+#include "javascript/js.h"
#include "render/form.h"
#include "render/textplain.h"
@@ -963,9 +964,6 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
browser_window_set_status(bw, messages_get("Loading"));
bw->history_add = add_to_history;
- /* fresh javascript compartment */
- bw->jsglobal = js_newcompartment(bw->jsctx);
-
/* Verifiable fetches may trigger a download */
if (verifiable)
fetch_flags |= HLCACHE_RETRIEVE_MAY_DOWNLOAD;
@@ -977,28 +975,34 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
browser_window_callback, bw,
parent != NULL ? &child : NULL,
CONTENT_ANY, &c);
- if (error == NSERROR_NO_FETCH_HANDLER) {
+
+ switch (error) {
+ case NSERROR_NO_FETCH_HANDLER: /* no handler for this type */
gui_launch_url(nsurl_access(nsurl));
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
- return;
- } else if (error != NSERROR_OK) {
+ break;
+
+ case NSERROR_OK:
+ bw->loading_content = c;
+ browser_window_start_throbber(bw);
+ browser_window_refresh_url_bar(bw, nsurl, NULL);
+
+ nsurl_unref(nsurl);
+ if (nsref != NULL)
+ nsurl_unref(nsref);
+ break;
+
+ default: /* assume out of memory */
+ /* TODO: fix all fetcher errors being reported as OOM? */
nsurl_unref(nsurl);
if (nsref != NULL)
nsurl_unref(nsref);
browser_window_set_status(bw, messages_get("NoMemory"));
warn_user("NoMemory", 0);
- return;
- }
- bw->loading_content = c;
- browser_window_start_throbber(bw);
- browser_window_refresh_url_bar(bw, nsurl, NULL);
-
- nsurl_unref(nsurl);
- if (nsref != NULL)
- nsurl_unref(nsref);
+ }
}
@@ -1391,6 +1395,16 @@ nserror browser_window_callback(hlcache_handle *c,
}
break;
+ case CONTENT_MSG_GETCTX:
+ /* only the content object created by the browser
+ * window requires a new global compartment object
+ */
+ if (js_newcompartment(bw->jsctx,
+ hlcache_handle_get_content(c)) != NULL) {
+ *(event->data.jscontext) = bw->jsctx;
+ }
+ break;
+
default:
assert(0);
}
diff --git a/desktop/browser.h b/desktop/browser.h
index e0d42265a..09107a3e6 100644
--- a/desktop/browser.h
+++ b/desktop/browser.h
@@ -199,8 +199,6 @@ struct browser_window {
/** current javascript context */
struct jscontext *jsctx;
- /** current global javascript object */
- struct jsobject *jsglobal;
/** cache of the currently displayed status text. */
char *status_text; /**< Current status bar text. */
diff --git a/desktop/js.c b/desktop/js.c
deleted file mode 100644
index 540ff82a5..000000000
--- a/desktop/js.c
+++ /dev/null
@@ -1,104 +0,0 @@
-#include "mozjs/jsapi.h"
-
-#include "desktop/js.h"
-#include "utils/log.h"
-
-static JSRuntime *rt; /* global runtime */
-
-void js_initialise(void)
-{
- /* Create a JS runtime. */
- rt = JS_NewRuntime(8L * 1024L * 1024L);
- LOG(("New runtime handle %p", rt));
-}
-
-void js_finalise(void)
-{
- if (rt != NULL) {
- LOG(("destroying runtime handle %p", rt));
- JS_DestroyRuntime(rt);
- }
- JS_ShutDown();
-}
-
-/* The error reporter callback. */
-static void js_reportError(JSContext *cx, const char *message, JSErrorReport *report)
-{
- LOG(("%s:%u:%s\n",
- report->filename ? report->filename : "<no filename>",
- (unsigned int) report->lineno,
- message));
-}
-
-jscontext *js_newcontext(void)
-{
- JSContext *cx;
-
- if (rt == NULL) {
- return NULL;
- }
-
- cx = JS_NewContext(rt, 8192);
- if (cx == NULL) {
- return NULL;
- }
- JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );
- JS_SetVersion(cx, JSVERSION_LATEST);
- JS_SetErrorReporter(cx, js_reportError);
-
- LOG(("New Context %p", cx));
-
- return (jscontext *)cx;
-}
-
-void js_destroycontext(jscontext *ctx)
-{
- JSContext *cx = (JSContext *)ctx;
- if (cx != NULL) {
- LOG(("Destroying Context %p", cx));
- JS_DestroyContext(cx);
- }
-}
-
-
-
-/* The class of the global object. */
-static JSClass global_class = {
- "global", JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
- JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-
-jsobject *js_newcompartment(jscontext *ctx)
-{
- JSContext *cx = (JSContext *)ctx;
- JSObject *global;
-
- if (cx == NULL) {
- return NULL;
- }
-#ifdef HAVE_JS_NEWCOMPARTMENTANDGLOBALOBJECT
- global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
- if (global == NULL) {
- return NULL;
- }
-#else
- global = JS_NewObject(cx, &global_class, NULL, NULL);
- if (global == NULL) {
- return NULL;
- }
- JS_SetGlobalObject(cx, global);
-#endif
-
- /* Populate the global object with the standard globals,
- like Object and Array. */
- if (!JS_InitStandardClasses(cx, global)) {
- return NULL;
- }
-
- LOG(("Creating new global object %p", global));
-
- return (jsobject *)global;
-}
diff --git a/desktop/js.h b/desktop/js.h
deleted file mode 100644
index b70845f16..000000000
--- a/desktop/js.h
+++ /dev/null
@@ -1,11 +0,0 @@
-
-typedef struct jscontext jscontext;
-typedef struct jsobject jsobject;
-
-void js_initialise(void);
-void js_finalise(void);
-
-jscontext *js_newcontext(void);
-void js_destroycontext(jscontext *ctx);
-
-jsobject *js_newcompartment(jscontext *ctx);
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index 606dfa649..2b6be861a 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -42,7 +42,9 @@
#include "desktop/gui.h"
#include "desktop/options.h"
#include "desktop/searchweb.h"
-#include "desktop/js.h"
+
+#include "javascript/js.h"
+
#include "render/html.h"
#include "render/textplain.h"
#include "utils/log.h"
diff --git a/desktop/nojs.c b/desktop/nojs.c
deleted file mode 100644
index 9a5c3c65e..000000000
--- a/desktop/nojs.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "desktop/js.h"
-#include "utils/log.h"
-
-void js_initialise(void)
-{
-}
-
-void js_finalise(void)
-{
-}
-
-jscontext *js_newcontext(void)
-{
- return NULL;
-}
-
-void js_destroycontext(jscontext *ctx)
-{
-}
-
-jsobject *js_newcompartment(jscontext *ctx)
-{
- return NULL;
-}