1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

Bug 846: Separate JS_GetParent & JS_GetPrivate calls from initializations.

This will allow the types of objects to be checked before those calls.
This commit is contained in:
Kalle Olavi Niemitalo 2006-11-24 08:50:12 +02:00 committed by Kalle Olavi Niemitalo
parent 98a120b3d5
commit bbf0d478e9
11 changed files with 320 additions and 140 deletions

View File

@ -73,11 +73,17 @@ const JSPropertySpec document_props[] = {
static JSBool static JSBool
document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_win = JS_GetParent(ctx, obj); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct session *ses = doc_view->session; 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)) { if (JSVAL_IS_STRING(id)) {
struct form *form; struct form *form;
@ -160,10 +166,15 @@ document_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) document_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_win = JS_GetParent(ctx, obj); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; 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)) { if (JSVAL_IS_STRING(id)) {
#ifdef CONFIG_COOKIES #ifdef CONFIG_COOKIES

View File

@ -125,17 +125,26 @@ static unicode_val_T jsval_to_accesskey(JSContext *ctx, jsval *vp);
static JSBool static JSBool
input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_form = JS_GetParent(ctx, obj); JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc = JS_GetParent(ctx, parent_form); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct form_state *fs = JS_GetPrivate(ctx, obj); /* from @input_class */ struct form_state *fs;
struct form_control *fc = find_form_control(document, fs); struct form_control *fc;
int linknum; int linknum;
struct link *link = NULL; 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);
assert(fc->form && fs); assert(fc->form && fs);
@ -247,18 +256,27 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_form = JS_GetParent(ctx, obj); JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc = JS_GetParent(ctx, parent_form); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct form_state *fs = JS_GetPrivate(ctx, obj); /* from @input_class */ struct form_state *fs;
struct form_control *fc = find_form_control(document, fs); struct form_control *fc;
int linknum; int linknum;
struct link *link = NULL; struct link *link = NULL;
unicode_val_T accesskey; unicode_val_T accesskey;
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);
assert(fc->form && fs); assert(fc->form && fs);
@ -347,17 +365,26 @@ input_blur(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool static JSBool
input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSObject *parent_form = JS_GetParent(ctx, obj); JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc = JS_GetParent(ctx, parent_form); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct session *ses = doc_view->session; struct session *ses;
struct form_state *fs = JS_GetPrivate(ctx, obj); /* from @input_class */ struct form_state *fs;
struct form_control *fc; struct form_control *fc;
int linknum; 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); assert(fs);
fc = find_form_control(document, fs); fc = find_form_control(document, fs);
assert(fc); assert(fc);
@ -382,17 +409,26 @@ input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool static JSBool
input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSObject *parent_form = JS_GetParent(ctx, obj); JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc = JS_GetParent(ctx, parent_form); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct session *ses = doc_view->session; struct session *ses;
struct form_state *fs = JS_GetPrivate(ctx, obj); /* from @input_class */ struct form_state *fs;
struct form_control *fc; struct form_control *fc;
int linknum; 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); assert(fs);
fc = find_form_control(document, fs); fc = find_form_control(document, fs);
assert(fc); assert(fc);
@ -497,14 +533,23 @@ static const JSPropertySpec form_elements_props[] = {
static JSBool static JSBool
form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_form = JS_GetParent(ctx, obj); JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc = JS_GetParent(ctx, parent_form); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct form_view *form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ struct form_view *form_view;
struct form *form = find_form_by_form_view(document, 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)) { if (JSVAL_IS_STRING(id)) {
form_elements_namedItem(ctx, obj, 1, &id, vp); form_elements_namedItem(ctx, obj, 1, &id, vp);
@ -533,18 +578,27 @@ form_elements_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSObject *parent_form = JS_GetParent(ctx, obj); JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc = JS_GetParent(ctx, parent_form); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct form_view *form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ struct form_view *form_view;
struct form *form = find_form_by_form_view(document, form_view); struct form *form;
struct form_control *fc; struct form_control *fc;
int counter = -1; int counter = -1;
int index; 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) if (argc != 1)
return JS_TRUE; return JS_TRUE;
@ -571,17 +625,26 @@ form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval
static JSBool static JSBool
form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSObject *parent_form = JS_GetParent(ctx, obj); JSObject *parent_form; /* instance of @form_class */
JSObject *parent_doc = JS_GetParent(ctx, parent_form); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct form_view *form_view = JS_GetPrivate(ctx, parent_form); /* from @form_class */ struct form_view *form_view;
struct form *form = find_form_by_form_view(document, form_view); struct form *form;
struct form_control *fc; struct form_control *fc;
unsigned char *string; 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) if (argc != 1)
return JS_TRUE; return JS_TRUE;
@ -654,12 +717,19 @@ static JSBool
form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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)))); */ /* 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_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct form_view *fv = JS_GetPrivate(ctx, obj); /* from @form_class */ struct form_view *fv;
struct form *form = find_form_by_form_view(doc_view->document, 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); assert(form);
@ -761,14 +831,21 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_doc = JS_GetParent(ctx, obj); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct form_view *fv = JS_GetPrivate(ctx, obj); /* from @form_class */ struct form_view *fv;
struct form *form = find_form_by_form_view(doc_view->document, fv); struct form *form;
unsigned char *string; 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); assert(form);
if (!JSVAL_IS_INT(id)) if (!JSVAL_IS_INT(id))
@ -825,12 +902,19 @@ form_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSObject *parent_doc = JS_GetParent(ctx, obj); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct form_view *fv = JS_GetPrivate(ctx, obj); /* from @form_class */ struct form_view *fv;
struct form *form = find_form_by_form_view(doc_view->document, 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); assert(form);
@ -846,13 +930,21 @@ form_reset(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool static JSBool
form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) form_submit(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSObject *parent_doc = JS_GetParent(ctx, obj); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct session *ses = doc_view->session; struct session *ses;
struct form_view *fv = JS_GetPrivate(ctx, obj); /* from @form_class */ struct form_view *fv;
struct form *form = find_form_by_form_view(doc_view->document, 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); assert(form);
submit_given_form(ses, doc_view, form, 0); submit_given_form(ses, doc_view, form, 0);
@ -914,11 +1006,17 @@ const JSPropertySpec forms_props[] = {
static JSBool static JSBool
forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_doc = JS_GetParent(ctx, obj); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; 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)) { if (JSVAL_IS_STRING(id)) {
forms_namedItem(ctx, obj, 1, &id, vp); forms_namedItem(ctx, obj, 1, &id, vp);
@ -945,13 +1043,17 @@ forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSObject *parent_doc = JS_GetParent(ctx, obj); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct form_view *fv; struct form_view *fv;
int counter = -1; int counter = -1;
int index; 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) if (argc != 1)
return JS_TRUE; return JS_TRUE;
@ -974,14 +1076,20 @@ forms_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool static JSBool
forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
JSObject *parent_doc = JS_GetParent(ctx, obj); JSObject *parent_doc; /* instance of @document_class */
JSObject *parent_win = JS_GetParent(ctx, parent_doc); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct document *document = doc_view->document; struct document *document;
struct form *form; struct form *form;
unsigned char *string; 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) if (argc != 1)
return JS_TRUE; return JS_TRUE;

View File

@ -145,8 +145,11 @@ const JSPropertySpec location_props[] = {
static JSBool static JSBool
location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_win = JS_GetParent(ctx, obj); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @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)) if (!JSVAL_IS_INT(id))
return JS_TRUE; return JS_TRUE;
@ -169,9 +172,13 @@ location_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) location_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_win = JS_GetParent(ctx, obj); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; 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)) if (!JSVAL_IS_INT(id))
return JS_TRUE; return JS_TRUE;

View File

@ -75,11 +75,17 @@ const JSPropertySpec unibar_props[] = {
static JSBool static JSBool
unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_win = JS_GetParent(ctx, obj); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct session_status *status = &doc_view->session->status; struct session_status *status;
unsigned char *bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */ 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)) if (!JSVAL_IS_INT(id))
return JS_TRUE; return JS_TRUE;
@ -115,11 +121,17 @@ unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
JSObject *parent_win = JS_GetParent(ctx, obj); JSObject *parent_win; /* instance of @window_class */
struct view_state *vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ struct view_state *vs;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct session_status *status = &doc_view->session->status; struct session_status *status;
unsigned char *bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */ 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)) if (!JSVAL_IS_INT(id))
return JS_TRUE; return JS_TRUE;

View File

@ -120,7 +120,9 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe)
static JSBool static JSBool
window_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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 /* No need for special window.location measurements - when
* location is then evaluated in string context, toString() * location is then evaluated in string context, toString()
@ -239,7 +241,9 @@ void location_goto(struct document_view *doc_view, unsigned char *url);
static JSBool static JSBool
window_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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 (JSVAL_IS_STRING(id)) {
if (!strcmp(jsval_to_string(ctx, &id), "location")) { if (!strcmp(jsval_to_string(ctx, &id), "location")) {
@ -285,9 +289,11 @@ const JSFunctionSpec window_funcs[] = {
static JSBool static JSBool
window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) 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; unsigned char *string;
vs = JS_GetPrivate(ctx, obj); /* from @window_class */
if (argc != 1) if (argc != 1)
return JS_TRUE; return JS_TRUE;
@ -306,15 +312,19 @@ window_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
static JSBool static JSBool
window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) window_open(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;
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view;
struct session *ses = doc_view->session; struct session *ses;
unsigned char *frame = ""; unsigned char *frame = "";
unsigned char *url; unsigned char *url;
struct uri *uri; struct uri *uri;
static time_t ratelimit_start; static time_t ratelimit_start;
static int ratelimit_count; 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")) { if (get_opt_bool("ecmascript.block_window_opening")) {
#ifdef CONFIG_LEDS #ifdef CONFIG_LEDS
set_led_value(ses->status.popup_led, 'P'); set_led_value(ses->status.popup_led, 'P');

View File

@ -25,7 +25,9 @@ struct smjs_action_fn_callback_hop {
static void static void
smjs_action_fn_finalize(JSContext *ctx, JSObject *obj) smjs_action_fn_finalize(JSContext *ctx, JSObject *obj)
{ {
struct smjs_action_fn_callback_hop *hop = JS_GetPrivate(ctx, obj); /* from @action_fn_class */ struct smjs_action_fn_callback_hop *hop;
hop = JS_GetPrivate(ctx, obj); /* from @action_fn_class */
if (hop) mem_free(hop); if (hop) mem_free(hop);
} }

View File

@ -39,7 +39,9 @@ smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp)
static void static void
bookmark_finalize(JSContext *ctx, JSObject *obj) 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); if (bookmark) object_unlock(bookmark);
} }
@ -66,7 +68,9 @@ static JSObject *smjs_get_bookmark_folder_object(struct bookmark *bookmark);
static JSBool static JSBool
bookmark_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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; if (!bookmark) return JS_FALSE;
@ -102,7 +106,9 @@ bookmark_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
bookmark_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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; if (!bookmark) return JS_FALSE;
@ -166,9 +172,11 @@ static JSBool
bookmark_folder_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) bookmark_folder_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
struct bookmark *bookmark; struct bookmark *bookmark;
struct bookmark *folder = JS_GetPrivate(ctx, obj); /* from @bookmark_folder_class */ struct bookmark *folder;
unsigned char *title; unsigned char *title;
folder = JS_GetPrivate(ctx, obj); /* from @bookmark_folder_class */
*vp = JSVAL_NULL; *vp = JSVAL_NULL;
title = JS_GetStringBytes(JS_ValueToString(ctx, id)); title = JS_GetStringBytes(JS_ValueToString(ctx, id));

View File

@ -35,7 +35,9 @@ static const JSPropertySpec cache_entry_props[] = {
static JSBool static JSBool
cache_entry_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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; 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 static JSBool
cache_entry_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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; 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 static void
cache_entry_finalize(JSContext *ctx, JSObject *obj) 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; if (!cached) return;

View File

@ -17,7 +17,9 @@
static void static void
smjs_globhist_item_finalize(JSContext *ctx, JSObject *obj) smjs_globhist_item_finalize(JSContext *ctx, JSObject *obj)
{ {
struct global_history_item *history_item = JS_GetPrivate(ctx, obj); /* from @smjs_globhist_item_class */ struct global_history_item *history_item;
history_item = JS_GetPrivate(ctx, obj); /* from @smjs_globhist_item_class */
if (history_item) object_unlock(history_item); if (history_item) object_unlock(history_item);
} }
@ -40,7 +42,9 @@ static JSBool
smjs_globhist_item_get_property(JSContext *ctx, JSObject *obj, jsval id, smjs_globhist_item_get_property(JSContext *ctx, JSObject *obj, jsval id,
jsval *vp) jsval *vp)
{ {
struct global_history_item *history_item = JS_GetPrivate(ctx, obj); /* from @smjs_globhist_item_class */ struct global_history_item *history_item;
history_item = JS_GetPrivate(ctx, obj); /* from @smjs_globhist_item_class */
if (!history_item) return JS_FALSE; if (!history_item) return JS_FALSE;
@ -92,7 +96,9 @@ smjs_globhist_item_get_property(JSContext *ctx, JSObject *obj, jsval id,
static JSBool static JSBool
smjs_globhist_item_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) smjs_globhist_item_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
struct global_history_item *history_item = JS_GetPrivate(ctx, obj); /* from @smjs_globhist_item_class */ struct global_history_item *history_item;
history_item = JS_GetPrivate(ctx, obj); /* from @smjs_globhist_item_class */
if (!history_item) return JS_FALSE; if (!history_item) return JS_FALSE;

View File

@ -19,9 +19,11 @@ keymap_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
{ {
unsigned char *action_str; unsigned char *action_str;
const unsigned char *keystroke_str; const unsigned char *keystroke_str;
int *data = JS_GetPrivate(ctx, obj); /* from @keymap_class */ int *data;
enum keymap_id keymap_id = *data; enum keymap_id keymap_id = *data;
data = JS_GetPrivate(ctx, obj); /* from @keymap_class */
keystroke_str = JS_GetStringBytes(JS_ValueToString(ctx, id)); keystroke_str = JS_GetStringBytes(JS_ValueToString(ctx, id));
if (!keystroke_str) goto ret_null; if (!keystroke_str) goto ret_null;
@ -63,11 +65,13 @@ smjs_keybinding_action_callback(va_list ap, void *data)
static JSBool static JSBool
keymap_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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; enum keymap_id keymap_id = *data;
unsigned char *keymap_str; unsigned char *keymap_str;
const unsigned char *keystroke_str; const 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, /* 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... */ * which will of course then convert the string back to an id... */
keymap_str = get_keymap_name(keymap_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 static void
keymap_finalize(JSContext *ctx, JSObject *obj) 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); mem_free(data);
} }

View File

@ -35,7 +35,9 @@ static const JSPropertySpec view_state_props[] = {
static JSBool static JSBool
view_state_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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); undef_to_jsval(ctx, vp);
@ -64,7 +66,9 @@ view_state_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
static JSBool static JSBool
view_state_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) 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)) if (!JSVAL_IS_INT(id))
return JS_FALSE; return JS_FALSE;