1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

bug 755: Fixed.

Remember the index of struct form_state in vs->form_info
instead of the pointer to it. The pointer may change,
the index is persistent.
The field ecmascript_obj of the struct form_state is unused.
This commit is contained in:
Witold Filipczyk 2007-05-22 16:07:06 +02:00 committed by Kalle Olavi Niemitalo
parent d43fe19224
commit ecc03ad608
2 changed files with 66 additions and 44 deletions

View File

@ -56,8 +56,8 @@ static void js_input_focus(struct SEE_interpreter *, struct SEE_object *, struct
static void js_input_select(struct SEE_interpreter *, struct SEE_object *, struct SEE_object *, int, struct SEE_value **, struct SEE_value *); static void js_input_select(struct SEE_interpreter *, struct SEE_object *, struct SEE_object *, int, struct SEE_value **, struct SEE_value *);
static int input_canput(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *); static int input_canput(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *);
static int input_hasproperty(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *); static int input_hasproperty(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *);
static struct js_input *js_get_input_object(struct SEE_interpreter *, struct js_form *, struct form_state *); static struct js_input *js_get_input_object(struct SEE_interpreter *, struct js_form *, int);
static struct js_input *js_get_form_control_object(struct SEE_interpreter *, struct js_form *, enum form_type, struct form_state *); static struct js_input *js_get_form_control_object(struct SEE_interpreter *, struct js_form *, enum form_type, int);
static void js_form_elems_item(struct SEE_interpreter *, struct SEE_object *, struct SEE_object *, int, struct SEE_value **, struct SEE_value *); static void js_form_elems_item(struct SEE_interpreter *, struct SEE_object *, struct SEE_object *, int, struct SEE_value **, struct SEE_value *);
static void js_form_elems_namedItem(struct SEE_interpreter *, struct SEE_object *, struct SEE_object *, int, struct SEE_value **, struct SEE_value *); static void js_form_elems_namedItem(struct SEE_interpreter *, struct SEE_object *, struct SEE_object *, int, struct SEE_value **, struct SEE_value *);
@ -136,11 +136,11 @@ struct SEE_objectclass js_form_class = {
struct js_input { struct js_input {
struct SEE_object object; struct SEE_object object;
struct js_form *parent; struct js_form *parent;
struct form_state *fs;
struct SEE_object *blur; struct SEE_object *blur;
struct SEE_object *click; struct SEE_object *click;
struct SEE_object *focus; struct SEE_object *focus;
struct SEE_object *select; struct SEE_object *select;
int form_number;
}; };
struct js_forms_object { struct js_forms_object {
@ -168,7 +168,7 @@ input_get(struct SEE_interpreter *interp, struct SEE_object *o,
struct document *document = doc_view->document; struct document *document = doc_view->document;
struct js_input *input = (struct js_input *)o; struct js_input *input = (struct js_input *)o;
struct js_form *parent = input->parent; struct js_form *parent = input->parent;
struct form_state *fs = input->fs; struct form_state *fs = &vs->form_info[input->form_number];
struct form_control *fc = find_form_control(document, fs); struct form_control *fc = find_form_control(document, fs);
int linknum; int linknum;
struct link *link = NULL; struct link *link = NULL;
@ -271,7 +271,7 @@ input_put(struct SEE_interpreter *interp, struct SEE_object *o,
struct document_view *doc_view = vs->doc_view; struct document_view *doc_view = vs->doc_view;
struct document *document = doc_view->document; struct document *document = doc_view->document;
struct js_input *input = (struct js_input *)o; struct js_input *input = (struct js_input *)o;
struct form_state *fs = input->fs; struct form_state *fs = &vs->form_info[input->form_number];
struct form_control *fc = find_form_control(document, fs); struct form_control *fc = find_form_control(document, fs);
int linknum; int linknum;
struct link *link = NULL; struct link *link = NULL;
@ -371,7 +371,7 @@ js_input_click(struct SEE_interpreter *interp, struct SEE_object *self,
struct js_input *input = ( struct js_input *input = (
see_check_class(interp, thisobj, &js_input_object_class), see_check_class(interp, thisobj, &js_input_object_class),
(struct js_input *)thisobj); (struct js_input *)thisobj);
struct form_state *fs = input->fs; struct form_state *fs = &vs->form_info[input->form_number];
struct form_control *fc; struct form_control *fc;
int linknum; int linknum;
@ -406,7 +406,7 @@ js_input_focus(struct SEE_interpreter *interp, struct SEE_object *self,
struct js_input *input = ( struct js_input *input = (
see_check_class(interp, thisobj, &js_input_object_class), see_check_class(interp, thisobj, &js_input_object_class),
(struct js_input *)thisobj); (struct js_input *)thisobj);
struct form_state *fs = input->fs; struct form_state *fs = &vs->form_info[input->form_number];
struct form_control *fc; struct form_control *fc;
int linknum; int linknum;
@ -451,8 +451,7 @@ input_hasproperty(struct SEE_interpreter *interp, struct SEE_object *o,
} }
static struct js_input * static struct js_input *
js_get_input_object(struct SEE_interpreter *interp, struct js_form *jsform, js_get_input_object(struct SEE_interpreter *interp, struct js_form *jsform, int num)
struct form_state *fs)
{ {
struct js_input *jsinput; struct js_input *jsinput;
@ -474,16 +473,14 @@ js_get_input_object(struct SEE_interpreter *interp, struct js_form *jsform,
jsinput->focus = SEE_cfunction_make(interp, js_input_focus, s_focus, 0); jsinput->focus = SEE_cfunction_make(interp, js_input_focus, s_focus, 0);
jsinput->select = SEE_cfunction_make(interp, js_input_select, s_select, 0); jsinput->select = SEE_cfunction_make(interp, js_input_select, s_select, 0);
jsinput->fs = fs; jsinput->form_number = num;
jsinput->parent = jsform; jsinput->parent = jsform;
fs->ecmascript_obj = jsinput;
return jsinput; return jsinput;
} }
static struct js_input * static struct js_input *
js_get_form_control_object(struct SEE_interpreter *interp, struct js_form *jsform, js_get_form_control_object(struct SEE_interpreter *interp, struct js_form *jsform,
enum form_type type, struct form_state *fs) enum form_type type, int num)
{ {
switch (type) { switch (type) {
case FC_TEXT: case FC_TEXT:
@ -497,7 +494,7 @@ js_get_form_control_object(struct SEE_interpreter *interp, struct js_form *jsfor
case FC_BUTTON: case FC_BUTTON:
case FC_HIDDEN: case FC_HIDDEN:
case FC_SELECT: case FC_SELECT:
return js_get_input_object(interp, jsform, fs); return js_get_input_object(interp, jsform, num);
case FC_TEXTAREA: case FC_TEXTAREA:
/* TODO */ /* TODO */
@ -544,10 +541,13 @@ js_form_elems_item(struct SEE_interpreter *interp, struct SEE_object *self,
foreach (fc, form->items) { foreach (fc, form->items) {
counter++; counter++;
if (counter == index) { if (counter == index) {
struct js_input *fcobj = js_get_form_control_object(interp, parent_form, fc->type, find_form_state(doc_view, fc)); struct form_state *fs = find_form_state(doc_view, fc);
if (fcobj) { if (fs) {
SEE_SET_OBJECT(res, (struct SEE_object *)fcobj); struct js_input *fcobj = js_get_form_control_object(interp, parent_form, fc->type, fc->g_ctrl_num);
if (fcobj)
SEE_SET_OBJECT(res, (struct SEE_object *)fcobj);
} }
break; break;
} }
@ -582,10 +582,13 @@ js_form_elems_namedItem(struct SEE_interpreter *interp, struct SEE_object *self,
foreach (fc, form->items) { foreach (fc, form->items) {
if ((fc->id && !strcasecmp(string, fc->id)) || (fc->name && !strcasecmp(string, fc->name))) { if ((fc->id && !strcasecmp(string, fc->id)) || (fc->name && !strcasecmp(string, fc->name))) {
struct js_input *fcobj = js_get_form_control_object(interp, parent_form, fc->type, find_form_state(doc_view, fc)); struct form_state *fs = find_form_state(doc_view, fc);
if (fcobj) { if (fs) {
SEE_SET_OBJECT(res, (struct SEE_object *)fcobj); struct js_input *fcobj = js_get_form_control_object(interp, parent_form, fc->type, fc->g_ctrl_num);
if (fcobj)
SEE_SET_OBJECT(res, (struct SEE_object *)fcobj);
} }
break; break;
} }
@ -839,13 +842,16 @@ form_get(struct SEE_interpreter *interp, struct SEE_object *o,
foreach(fc, form->items) { foreach(fc, form->items) {
struct js_input *fcobj = NULL; struct js_input *fcobj = NULL;
struct form_state *fs;
if ((!fc->id || strcasecmp(string, fc->id)) && (!fc->name || strcasecmp(string, fc->name))) if ((!fc->id || strcasecmp(string, fc->id)) && (!fc->name || strcasecmp(string, fc->name)))
continue; continue;
fcobj = js_get_form_control_object(interp, js_form, fc->type, find_form_state(doc_view, fc)); fs = find_form_state(doc_view, fc);
if (fs) {
fcobj = js_get_form_control_object(interp, js_form, fc->type, fc->g_ctrl_num);
if (fcobj) { if (fcobj)
SEE_SET_OBJECT(res, (struct SEE_object *)fcobj); SEE_SET_OBJECT(res, (struct SEE_object *)fcobj);
} }
break; break;
} }

View File

@ -130,6 +130,15 @@ static const JSFunctionSpec input_funcs[] = {
static JSString *unicode_to_jsstring(JSContext *ctx, unicode_val_T u); static JSString *unicode_to_jsstring(JSContext *ctx, unicode_val_T u);
static unicode_val_T jsval_to_accesskey(JSContext *ctx, jsval *vp); static unicode_val_T jsval_to_accesskey(JSContext *ctx, jsval *vp);
static struct form_state *
input_get_form_state(JSContext *ctx, JSObject *obj, struct view_state *vs)
{
int n = (int)(long)JS_GetPrivate(ctx, obj);
return &vs->form_info[n];
}
/* @input_class.getProperty */ /* @input_class.getProperty */
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)
@ -163,7 +172,7 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view; doc_view = vs->doc_view;
document = doc_view->document; document = doc_view->document;
fs = JS_GetPrivate(ctx, obj); /* from @input_class */ fs = input_get_form_state(ctx, obj, vs);
fc = find_form_control(document, fs); fc = find_form_control(document, fs);
assert(fc); assert(fc);
@ -313,7 +322,7 @@ input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */ vs = JS_GetPrivate(ctx, parent_win); /* from @window_class */
doc_view = vs->doc_view; doc_view = vs->doc_view;
document = doc_view->document; document = doc_view->document;
fs = JS_GetPrivate(ctx, obj); /* from @input_class */ fs = input_get_form_state(ctx, obj, vs);
fc = find_form_control(document, fs); fc = find_form_control(document, fs);
assert(fc); assert(fc);
@ -435,7 +444,7 @@ input_click(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
doc_view = vs->doc_view; doc_view = vs->doc_view;
document = doc_view->document; document = doc_view->document;
ses = doc_view->session; ses = doc_view->session;
fs = JS_GetPrivate(ctx, obj); /* from @input_class */ fs = input_get_form_state(ctx, obj, vs);
assert(fs); assert(fs);
fc = find_form_control(document, fs); fc = find_form_control(document, fs);
@ -487,7 +496,7 @@ input_focus(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
doc_view = vs->doc_view; doc_view = vs->doc_view;
document = doc_view->document; document = doc_view->document;
ses = doc_view->session; ses = doc_view->session;
fs = JS_GetPrivate(ctx, obj); /* from @input_class */ fs = input_get_form_state(ctx, obj, vs);
assert(fs); assert(fs);
fc = find_form_control(document, fs); fc = find_form_control(document, fs);
@ -514,7 +523,7 @@ input_select(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
} }
static JSObject * static JSObject *
get_input_object(JSContext *ctx, JSObject *jsform, struct form_state *fs) get_input_object(JSContext *ctx, JSObject *jsform, long number)
{ {
#if 0 #if 0
if (fs->ecmascript_obj) if (fs->ecmascript_obj)
@ -527,14 +536,13 @@ get_input_object(JSContext *ctx, JSObject *jsform, struct form_state *fs)
JS_DefineProperties(ctx, jsinput, (JSPropertySpec *) input_props); JS_DefineProperties(ctx, jsinput, (JSPropertySpec *) input_props);
JS_DefineFunctions(ctx, jsinput, (JSFunctionSpec *) input_funcs); JS_DefineFunctions(ctx, jsinput, (JSFunctionSpec *) input_funcs);
JS_SetPrivate(ctx, jsinput, fs); /* to @input_class */ JS_SetPrivate(ctx, jsinput, (void *)number); /* to @input_class */
fs->ecmascript_obj = jsinput; return jsinput;;
return fs->ecmascript_obj;
} }
static JSObject * static JSObject *
get_form_control_object(JSContext *ctx, JSObject *jsform, enum form_type type, struct form_state *fs) get_form_control_object(JSContext *ctx, JSObject *jsform, enum form_type type, int number)
{ {
switch (type) { switch (type) {
case FC_TEXT: case FC_TEXT:
@ -548,7 +556,7 @@ get_form_control_object(JSContext *ctx, JSObject *jsform, enum form_type type, s
case FC_BUTTON: case FC_BUTTON:
case FC_HIDDEN: case FC_HIDDEN:
case FC_SELECT: case FC_SELECT:
return get_input_object(ctx, jsform, fs); return get_input_object(ctx, jsform, (long)number);
case FC_TEXTAREA: case FC_TEXTAREA:
/* TODO */ /* TODO */
@ -693,10 +701,13 @@ form_elements_item(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval
foreach (fc, form->items) { foreach (fc, form->items) {
counter++; counter++;
if (counter == index) { if (counter == index) {
JSObject *fcobj = get_form_control_object(ctx, parent_form, fc->type, find_form_state(doc_view, fc)); struct form_state *fs = find_form_state(doc_view, fc);
if (fcobj) { if (fs) {
object_to_jsval(ctx, rval, fcobj); JSObject *fcobj = get_form_control_object(ctx, parent_form, fc->type, fc->g_ctrl_num);
if (fcobj)
object_to_jsval(ctx, rval, fcobj);
} }
break; break;
} }
@ -748,10 +759,13 @@ form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
foreach (fc, form->items) { foreach (fc, form->items) {
if ((fc->id && !strcasecmp(string, fc->id)) || (fc->name && !strcasecmp(string, fc->name))) { if ((fc->id && !strcasecmp(string, fc->id)) || (fc->name && !strcasecmp(string, fc->name))) {
JSObject *fcobj = get_form_control_object(ctx, parent_form, fc->type, find_form_state(doc_view, fc)); struct form_state *fs = find_form_state(doc_view, fc);
if (fcobj) { if (fs) {
object_to_jsval(ctx, rval, fcobj); JSObject *fcobj = get_form_control_object(ctx, parent_form, fc->type, fc->g_ctrl_num);
if (fcobj)
object_to_jsval(ctx, rval, fcobj);
} }
break; break;
} }
@ -846,15 +860,17 @@ form_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
string = jsval_to_string(ctx, &id); string = jsval_to_string(ctx, &id);
foreach (fc, form->items) { foreach (fc, form->items) {
JSObject *fcobj = NULL; JSObject *fcobj = NULL;
struct form_state *fs;
if ((!fc->id || strcasecmp(string, fc->id)) && (!fc->name || strcasecmp(string, fc->name))) if ((!fc->id || strcasecmp(string, fc->id)) && (!fc->name || strcasecmp(string, fc->name)))
continue; continue;
fcobj = get_form_control_object(ctx, obj, fc->type, find_form_state(doc_view, fc)); undef_to_jsval(ctx, vp);
if (fcobj) { fs = find_form_state(doc_view, fc);
object_to_jsval(ctx, vp, fcobj); if (fs) {
} else { fcobj = get_form_control_object(ctx, obj, fc->type, fc->g_ctrl_num);
undef_to_jsval(ctx, vp); if (fcobj)
object_to_jsval(ctx, vp, fcobj);
} }
break; break;
} }