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.
[ Backported from commit ecc03ad608
in
ELinks 0.12.GIT. --KON ]
This commit is contained in:
parent
a15079282a
commit
9bbd795787
@ -121,6 +121,15 @@ static const JSFunctionSpec input_funcs[] = {
|
|||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
@ -154,7 +163,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);
|
||||||
@ -293,7 +302,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);
|
||||||
@ -400,7 +409,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);
|
||||||
@ -452,7 +461,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);
|
||||||
@ -479,7 +488,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)
|
||||||
@ -492,14 +501,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:
|
||||||
@ -512,7 +520,7 @@ get_form_control_object(JSContext *ctx, JSObject *jsform, enum form_type type, s
|
|||||||
case FC_RESET:
|
case FC_RESET:
|
||||||
case FC_BUTTON:
|
case FC_BUTTON:
|
||||||
case FC_HIDDEN:
|
case FC_HIDDEN:
|
||||||
return get_input_object(ctx, jsform, fs);
|
return get_input_object(ctx, jsform, (long)number);
|
||||||
|
|
||||||
case FC_TEXTAREA:
|
case FC_TEXTAREA:
|
||||||
case FC_SELECT:
|
case FC_SELECT:
|
||||||
@ -655,10 +663,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;
|
||||||
}
|
}
|
||||||
@ -710,10 +721,13 @@ form_elements_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
|
|||||||
|
|
||||||
foreach (fc, form->items) {
|
foreach (fc, form->items) {
|
||||||
if (fc->name && !strcasecmp(string, fc->name)) {
|
if (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;
|
||||||
}
|
}
|
||||||
@ -804,15 +818,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->name || strcasecmp(string, fc->name))
|
if (!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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user