From 9a829b3277474d48a55875fb5ea86755981e964b Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sat, 25 Nov 2006 21:14:56 +0200 Subject: [PATCH] Bug 846: Separate JS_GetParent & JS_GetPrivate calls from initializations. This will allow the types of objects to be checked before those calls. (Adapted from bbf0d478e934ab12d68d56ea5af755026ed651ac in ELinks 0.12.GIT.) --- src/ecmascript/spidermonkey/document.c | 29 ++- src/ecmascript/spidermonkey/form.c | 296 +++++++++++++++++-------- src/ecmascript/spidermonkey/location.c | 17 +- src/ecmascript/spidermonkey/unibar.c | 32 ++- src/ecmascript/spidermonkey/window.c | 22 +- src/scripting/smjs/bookmarks.c | 16 +- src/scripting/smjs/cache_object.c | 12 +- src/scripting/smjs/keybinding.c | 12 +- src/scripting/smjs/view_state_object.c | 8 +- 9 files changed, 308 insertions(+), 136 deletions(-) diff --git a/src/ecmascript/spidermonkey/document.c b/src/ecmascript/spidermonkey/document.c index 7d8c9a565..ebd2b03ba 100644 --- a/src/ecmascript/spidermonkey/document.c +++ b/src/ecmascript/spidermonkey/document.c @@ -73,11 +73,17 @@ const JSPropertySpec document_props[] = { static JSBool document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_win = JS_GetParent(ctx, obj); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses = doc_view->session; + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct session *ses; + + parent_win = JS_GetParent(ctx, obj); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + ses = doc_view->session; if (JSVAL_IS_STRING(id)) { struct form *form; @@ -157,10 +163,15 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_win = JS_GetParent(ctx, obj); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + + parent_win = JS_GetParent(ctx, obj); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; if (JSVAL_IS_STRING(id)) { #ifdef CONFIG_COOKIES diff --git a/src/ecmascript/spidermonkey/form.c b/src/ecmascript/spidermonkey/form.c index 460e39dbf..5de30729c 100644 --- a/src/ecmascript/spidermonkey/form.c +++ b/src/ecmascript/spidermonkey/form.c @@ -120,17 +120,26 @@ static const JSFunctionSpec input_funcs[] = { static JSBool input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_form = JS_GetParent(ctx, obj); - JSObject *parent_doc = JS_GetParent(ctx, parent_form); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct form_state *fs = JS_GetPrivate(ctx, obj); /* from @input_class */ - struct form_control *fc = find_form_control(document, fs); + JSObject *parent_form; /* instance of @form_class */ + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct form_state *fs; + struct form_control *fc; int linknum; struct link *link = NULL; + parent_form = JS_GetParent(ctx, obj); + parent_doc = JS_GetParent(ctx, parent_form); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + fs = JS_GetPrivate(ctx, obj); /* from @input_class */ + fc = find_form_control(document, fs); + assert(fc); assert(fc->form && fs); @@ -233,17 +242,26 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_form = JS_GetParent(ctx, obj); - JSObject *parent_doc = JS_GetParent(ctx, parent_form); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct form_state *fs = JS_GetPrivate(ctx, obj); /* from @input_class */ - struct form_control *fc = find_form_control(document, fs); + JSObject *parent_form; /* instance of @form_class */ + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct form_state *fs; + struct form_control *fc; int linknum; struct link *link = NULL; + parent_form = JS_GetParent(ctx, obj); + parent_doc = JS_GetParent(ctx, parent_form); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + fs = JS_GetPrivate(ctx, obj); /* from @input_class */ + fc = find_form_control(document, fs); + assert(fc); assert(fc->form && fs); @@ -319,17 +337,26 @@ input_blur(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) static JSBool input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - JSObject *parent_form = JS_GetParent(ctx, obj); - JSObject *parent_doc = JS_GetParent(ctx, parent_form); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses = doc_view->session; - struct form_state *fs = JS_GetPrivate(ctx, obj); /* from @input_class */ + JSObject *parent_form; /* instance of @form_class */ + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct session *ses; + struct form_state *fs; struct form_control *fc; int linknum; + parent_form = JS_GetParent(ctx, obj); + parent_doc = JS_GetParent(ctx, parent_form); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + ses = doc_view->session; + fs = JS_GetPrivate(ctx, obj); /* from @input_class */ + assert(fs); fc = find_form_control(document, fs); assert(fc); @@ -354,17 +381,26 @@ input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) static JSBool input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - JSObject *parent_form = JS_GetParent(ctx, obj); - JSObject *parent_doc = JS_GetParent(ctx, parent_form); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct session *ses = doc_view->session; - struct form_state *fs = JS_GetPrivate(ctx, obj); /* from @input_class */ + JSObject *parent_form; /* instance of @form_class */ + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct session *ses; + struct form_state *fs; struct form_control *fc; int linknum; + parent_form = JS_GetParent(ctx, obj); + parent_doc = JS_GetParent(ctx, parent_form); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + ses = doc_view->session; + fs = JS_GetPrivate(ctx, obj); /* from @input_class */ + assert(fs); fc = find_form_control(document, fs); assert(fc); @@ -467,14 +503,23 @@ static const JSPropertySpec form_elements_props[] = { static JSBool form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_form = JS_GetParent(ctx, obj); - JSObject *parent_doc = JS_GetParent(ctx, parent_form); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct form_view *form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ - struct form *form = find_form_by_form_view(document, form_view); + JSObject *parent_form; /* instance of @form_class */ + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct form_view *form_view; + struct form *form; + + parent_form = JS_GetParent(ctx, obj); + parent_doc = JS_GetParent(ctx, parent_form); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ + form = find_form_by_form_view(document, form_view); if (JSVAL_IS_STRING(id)) { form_elements_namedItem(ctx, obj, 1, &id, vp); @@ -503,18 +548,27 @@ form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - JSObject *parent_form = JS_GetParent(ctx, obj); - JSObject *parent_doc = JS_GetParent(ctx, parent_form); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct form_view *form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ - struct form *form = find_form_by_form_view(document, form_view); + JSObject *parent_form; /* instance of @form_class */ + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct form_view *form_view; + struct form *form; struct form_control *fc; int counter = -1; int index; + parent_form = JS_GetParent(ctx, obj); + parent_doc = JS_GetParent(ctx, parent_form); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ + form = find_form_by_form_view(document, form_view); + if (argc != 1) return JS_TRUE; @@ -541,17 +595,26 @@ form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval static JSBool form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - JSObject *parent_form = JS_GetParent(ctx, obj); - JSObject *parent_doc = JS_GetParent(ctx, parent_form); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; - struct form_view *form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ - struct form *form = find_form_by_form_view(document, form_view); + JSObject *parent_form; /* instance of @form_class */ + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct form_view *form_view; + struct form *form; struct form_control *fc; unsigned char *string; + parent_form = JS_GetParent(ctx, obj); + parent_doc = JS_GetParent(ctx, parent_form); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ + form = find_form_by_form_view(document, form_view); + if (argc != 1) return JS_TRUE; @@ -624,12 +687,19 @@ static JSBool form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ - JSObject *parent_doc = JS_GetParent(ctx, obj); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct form_view *fv = JS_GetPrivate(ctx, obj); /* from @form_class */ - struct form *form = find_form_by_form_view(doc_view->document, fv); + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct form_view *fv; + struct form *form; + + parent_doc = JS_GetParent(ctx, obj); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + fv = JS_GetPrivate(ctx, obj); /* from @form_class */ + form = find_form_by_form_view(doc_view->document, fv); assert(form); @@ -731,14 +801,21 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_doc = JS_GetParent(ctx, obj); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct form_view *fv = JS_GetPrivate(ctx, obj); /* from @form_class */ - struct form *form = find_form_by_form_view(doc_view->document, fv); + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct form_view *fv; + struct form *form; unsigned char *string; + parent_doc = JS_GetParent(ctx, obj); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + fv = JS_GetPrivate(ctx, obj); /* from @form_class */ + form = find_form_by_form_view(doc_view->document, fv); + assert(form); if (!JSVAL_IS_INT(id)) @@ -790,12 +867,19 @@ form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - JSObject *parent_doc = JS_GetParent(ctx, obj); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct form_view *fv = JS_GetPrivate(ctx, obj); /* from @form_class */ - struct form *form = find_form_by_form_view(doc_view->document, fv); + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct form_view *fv; + struct form *form; + + parent_doc = JS_GetParent(ctx, obj); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + fv = JS_GetPrivate(ctx, obj); /* from @form_class */ + form = find_form_by_form_view(doc_view->document, fv); assert(form); @@ -811,13 +895,21 @@ form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) static JSBool form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - JSObject *parent_doc = JS_GetParent(ctx, obj); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct session *ses = doc_view->session; - struct form_view *fv = JS_GetPrivate(ctx, obj); /* from @form_class */ - struct form *form = find_form_by_form_view(doc_view->document, fv); + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct session *ses; + struct form_view *fv; + struct form *form; + + parent_doc = JS_GetParent(ctx, obj); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + ses = doc_view->session; + fv = JS_GetPrivate(ctx, obj); /* from @form_class */ + form = find_form_by_form_view(doc_view->document, fv); assert(form); submit_given_form(ses, doc_view, form); @@ -877,11 +969,17 @@ const JSPropertySpec forms_props[] = { static JSBool forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_doc = JS_GetParent(ctx, obj); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + + parent_doc = JS_GetParent(ctx, obj); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; if (JSVAL_IS_STRING(id)) { forms_namedItem(ctx, obj, 1, &id, vp); @@ -908,13 +1006,17 @@ forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - JSObject *parent_doc = JS_GetParent(ctx, obj); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; struct form_view *fv; int counter = -1; int index; + parent_doc = JS_GetParent(ctx, obj); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + if (argc != 1) return JS_TRUE; @@ -937,14 +1039,20 @@ forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) static JSBool forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - JSObject *parent_doc = JS_GetParent(ctx, obj); - JSObject *parent_win = JS_GetParent(ctx, parent_doc); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct document *document = doc_view->document; + JSObject *parent_doc; /* instance of @document_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct document *document; struct form *form; unsigned char *string; + parent_doc = JS_GetParent(ctx, obj); + parent_win = JS_GetParent(ctx, parent_doc); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + document = doc_view->document; + if (argc != 1) return JS_TRUE; diff --git a/src/ecmascript/spidermonkey/location.c b/src/ecmascript/spidermonkey/location.c index 4556cd324..1f433cc0d 100644 --- a/src/ecmascript/spidermonkey/location.c +++ b/src/ecmascript/spidermonkey/location.c @@ -145,8 +145,11 @@ const JSPropertySpec location_props[] = { static JSBool location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_win = JS_GetParent(ctx, obj); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + + parent_win = JS_GetParent(ctx, obj); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ if (!JSVAL_IS_INT(id)) return JS_TRUE; @@ -169,9 +172,13 @@ location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_win = JS_GetParent(ctx, obj); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + + parent_win = JS_GetParent(ctx, obj); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; if (!JSVAL_IS_INT(id)) return JS_TRUE; diff --git a/src/ecmascript/spidermonkey/unibar.c b/src/ecmascript/spidermonkey/unibar.c index c7c8366a8..af749b49e 100644 --- a/src/ecmascript/spidermonkey/unibar.c +++ b/src/ecmascript/spidermonkey/unibar.c @@ -75,11 +75,17 @@ const JSPropertySpec unibar_props[] = { static JSBool unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_win = JS_GetParent(ctx, obj); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct session_status *status = &doc_view->session->status; - unsigned char *bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct session_status *status; + unsigned char *bar; + + parent_win = JS_GetParent(ctx, obj); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + status = &doc_view->session->status; + bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */ if (!JSVAL_IS_INT(id)) return JS_TRUE; @@ -115,11 +121,17 @@ unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - JSObject *parent_win = JS_GetParent(ctx, obj); - struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct session_status *status = &doc_view->session->status; - unsigned char *bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */ + JSObject *parent_win; /* instance of @window_class */ + struct view_state *vs; + struct document_view *doc_view; + struct session_status *status; + unsigned char *bar; + + parent_win = JS_GetParent(ctx, obj); + vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ + doc_view = vs->doc_view; + status = &doc_view->session->status; + bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */ if (!JSVAL_IS_INT(id)) return JS_TRUE; diff --git a/src/ecmascript/spidermonkey/window.c b/src/ecmascript/spidermonkey/window.c index a51e87de0..045a3ce54 100644 --- a/src/ecmascript/spidermonkey/window.c +++ b/src/ecmascript/spidermonkey/window.c @@ -118,7 +118,9 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe) static JSBool window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - struct view_state *vs = JS_GetPrivate(ctx, obj); /* from @window_class */ + struct view_state *vs; + + vs = JS_GetPrivate(ctx, obj); /* from @window_class */ /* No need for special window.location measurements - when * location is then evaluated in string context, toString() @@ -235,7 +237,9 @@ void location_goto(struct document_view *doc_view, unsigned char *url); static JSBool window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - struct view_state *vs = JS_GetPrivate(ctx, obj); /* from @window_class */ + struct view_state *vs; + + vs = JS_GetPrivate(ctx, obj); /* from @window_class */ if (JSVAL_IS_STRING(id)) { if (!strcmp(jsval_to_string(ctx, &id), "location")) { @@ -275,9 +279,11 @@ const JSFunctionSpec window_funcs[] = { static JSBool window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - struct view_state *vs = JS_GetPrivate(ctx, obj); /* from @window_class */ + struct view_state *vs; unsigned char *string; + vs = JS_GetPrivate(ctx, obj); /* from @window_class */ + if (argc != 1) return JS_TRUE; @@ -324,15 +330,19 @@ delayed_goto_uri_frame(void *data) static JSBool window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - struct view_state *vs = JS_GetPrivate(ctx, obj); /* from @window_class */ - struct document_view *doc_view = vs->doc_view; - struct session *ses = doc_view->session; + struct view_state *vs; + struct document_view *doc_view; + struct session *ses; unsigned char *target = ""; unsigned char *url; struct uri *uri; static time_t ratelimit_start; static int ratelimit_count; + vs = JS_GetPrivate(ctx, obj); /* from @window_class */ + doc_view = vs->doc_view; + ses = doc_view->session; + if (get_opt_bool("ecmascript.block_window_opening")) { #ifdef CONFIG_LEDS set_led_value(ses->status.popup_led, 'P'); diff --git a/src/scripting/smjs/bookmarks.c b/src/scripting/smjs/bookmarks.c index 670c89928..6f30474a1 100644 --- a/src/scripting/smjs/bookmarks.c +++ b/src/scripting/smjs/bookmarks.c @@ -39,7 +39,9 @@ smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp) static void bookmark_finalize(JSContext *ctx, JSObject *obj) { - struct bookmark *bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class or @bookmark_folder_class */ + struct bookmark *bookmark; + + bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class or @bookmark_folder_class */ if (bookmark) object_unlock(bookmark); } @@ -66,7 +68,9 @@ static JSObject *smjs_get_bookmark_folder_object(struct bookmark *bookmark); static JSBool bookmark_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - struct bookmark *bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class */ + struct bookmark *bookmark; + + bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class */ if (!bookmark) return JS_FALSE; @@ -102,7 +106,9 @@ bookmark_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool bookmark_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - struct bookmark *bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class */ + struct bookmark *bookmark; + + bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class */ if (!bookmark) return JS_FALSE; @@ -166,9 +172,11 @@ static JSBool bookmark_folder_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { struct bookmark *bookmark; - struct bookmark *folder = JS_GetPrivate(ctx, obj); /* from @bookmark_folder_class */ + struct bookmark *folder; unsigned char *title; + folder = JS_GetPrivate(ctx, obj); /* from @bookmark_folder_class */ + title = JS_GetStringBytes(JS_ValueToString(ctx, id)); if (!title) { *vp = JSVAL_NULL; diff --git a/src/scripting/smjs/cache_object.c b/src/scripting/smjs/cache_object.c index ebbfd4b89..7145df0b1 100644 --- a/src/scripting/smjs/cache_object.c +++ b/src/scripting/smjs/cache_object.c @@ -35,7 +35,9 @@ static const JSPropertySpec cache_entry_props[] = { static JSBool cache_entry_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - struct cache_entry *cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */ + struct cache_entry *cached; + + cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */ if (!cache_entry_is_valid(cached)) return JS_FALSE; @@ -87,7 +89,9 @@ cache_entry_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool cache_entry_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - struct cache_entry *cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */ + struct cache_entry *cached; + + cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */ if (!cache_entry_is_valid(cached)) return JS_FALSE; @@ -135,7 +139,9 @@ cache_entry_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static void cache_entry_finalize(JSContext *ctx, JSObject *obj) { - struct cache_entry *cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */ + struct cache_entry *cached; + + cached = JS_GetPrivate(ctx, obj); /* from @cache_entry_class */ if (!cached) return; diff --git a/src/scripting/smjs/keybinding.c b/src/scripting/smjs/keybinding.c index d60165f27..9deb07788 100644 --- a/src/scripting/smjs/keybinding.c +++ b/src/scripting/smjs/keybinding.c @@ -19,9 +19,11 @@ keymap_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { unsigned char *action_str; unsigned char *keystroke_str; - int *data = JS_GetPrivate(ctx, obj); /* from @keymap_class */ + int *data; enum keymap_id keymap_id = *data; + data = JS_GetPrivate(ctx, obj); /* from @keymap_class */ + keystroke_str = JS_GetStringBytes(JS_ValueToString(ctx, id)); if (!keystroke_str) goto ret_null; @@ -63,11 +65,13 @@ smjs_keybinding_action_callback(va_list ap, void *data) static JSBool keymap_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - int *data = JS_GetPrivate(ctx, obj); /* from @keymap_class */ + int *data; enum keymap_id keymap_id = *data; unsigned char *keymap_str; unsigned char *keystroke_str; + data = JS_GetPrivate(ctx, obj); /* from @keymap_class */ + /* Ugly fact: we need to get the string from the id to give to bind_do, * which will of course then convert the string back to an id... */ keymap_str = get_keymap_name(keymap_id); @@ -133,7 +137,9 @@ keymap_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static void keymap_finalize(JSContext *ctx, JSObject *obj) { - void *data = JS_GetPrivate(ctx, obj); /* from @keymap_class */ + void *data; + + data = JS_GetPrivate(ctx, obj); /* from @keymap_class */ mem_free(data); } diff --git a/src/scripting/smjs/view_state_object.c b/src/scripting/smjs/view_state_object.c index cd1dc0a07..426dff691 100644 --- a/src/scripting/smjs/view_state_object.c +++ b/src/scripting/smjs/view_state_object.c @@ -31,7 +31,9 @@ static const JSPropertySpec view_state_props[] = { static JSBool view_state_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - struct view_state *vs = JS_GetPrivate(ctx, obj); /* from @view_state_class */ + struct view_state *vs; + + vs = JS_GetPrivate(ctx, obj); /* from @view_state_class */ undef_to_jsval(ctx, vp); @@ -60,7 +62,9 @@ view_state_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) static JSBool view_state_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) { - struct view_state *vs = JS_GetPrivate(ctx, obj); /* from @view_state_class */ + struct view_state *vs; + + vs = JS_GetPrivate(ctx, obj); /* from @view_state_class */ if (!JSVAL_IS_INT(id)) return JS_FALSE;