mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-02 08:57:19 -04:00
SMJS: Fix error "forms.namedItem is not a function".
Commit 63752c854b303f5f58636a512a137bf3702e051b on 2004-12-27 seems to have broken this.
This commit is contained in:
parent
174b1f3af5
commit
c9b2fbbd46
@ -1178,6 +1178,29 @@ const JSPropertySpec forms_props[] = {
|
|||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Find the form whose name is @name, which should normally be a
|
||||||
|
* string (but might not be). If found, set *rval = the DOM
|
||||||
|
* object. If not found, leave *rval unchanged. */
|
||||||
|
static void
|
||||||
|
find_form_by_name(JSContext *ctx, JSObject *jsdoc,
|
||||||
|
struct document_view *doc_view,
|
||||||
|
jsval name, jsval *rval)
|
||||||
|
{
|
||||||
|
unsigned char *string = jsval_to_string(ctx, &name);
|
||||||
|
struct form *form;
|
||||||
|
|
||||||
|
if (!*string)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (form, doc_view->document->forms) {
|
||||||
|
if (form->name && !strcasecmp(string, form->name)) {
|
||||||
|
object_to_jsval(ctx, rval, get_form_object(ctx, jsdoc,
|
||||||
|
find_form_view(doc_view, form)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* @forms_class.getProperty */
|
/* @forms_class.getProperty */
|
||||||
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)
|
||||||
@ -1206,7 +1229,13 @@ forms_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
|||||||
document = doc_view->document;
|
document = doc_view->document;
|
||||||
|
|
||||||
if (JSVAL_IS_STRING(id)) {
|
if (JSVAL_IS_STRING(id)) {
|
||||||
forms_namedItem(ctx, obj, 1, &id, vp);
|
/* When SMJS evaluates forms.namedItem("foo"), it first
|
||||||
|
* calls forms_get_property with id = JSString "namedItem"
|
||||||
|
* and *vp = JSObject JSFunction forms_namedItem.
|
||||||
|
* If we don't find a form whose name is id,
|
||||||
|
* we must leave *vp unchanged here, to avoid
|
||||||
|
* "TypeError: forms.namedItem is not a function". */
|
||||||
|
find_form_by_name(ctx, parent_doc, doc_view, id, vp);
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1274,9 +1303,6 @@ forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *r
|
|||||||
JSObject *parent_win; /* instance of @window_class */
|
JSObject *parent_win; /* instance of @window_class */
|
||||||
struct view_state *vs;
|
struct view_state *vs;
|
||||||
struct document_view *doc_view;
|
struct document_view *doc_view;
|
||||||
struct document *document;
|
|
||||||
struct form *form;
|
|
||||||
unsigned char *string;
|
|
||||||
|
|
||||||
if (!JS_InstanceOf(ctx, obj, (JSClass *) &forms_class, argv)) return JS_FALSE;
|
if (!JS_InstanceOf(ctx, obj, (JSClass *) &forms_class, argv)) return JS_FALSE;
|
||||||
parent_doc = JS_GetParent(ctx, obj);
|
parent_doc = JS_GetParent(ctx, obj);
|
||||||
@ -1289,25 +1315,12 @@ forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *r
|
|||||||
vs = JS_GetInstancePrivate(ctx, parent_win,
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
||||||
(JSClass *) &window_class, NULL);
|
(JSClass *) &window_class, NULL);
|
||||||
doc_view = vs->doc_view;
|
doc_view = vs->doc_view;
|
||||||
document = doc_view->document;
|
|
||||||
|
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
|
|
||||||
undef_to_jsval(ctx, rval);
|
undef_to_jsval(ctx, rval);
|
||||||
|
find_form_by_name(ctx, parent_doc, doc_view, argv[0], rval);
|
||||||
string = jsval_to_string(ctx, &argv[0]);
|
|
||||||
if (!*string)
|
|
||||||
return JS_TRUE;
|
|
||||||
|
|
||||||
foreach (form, document->forms) {
|
|
||||||
if (form->name && !strcasecmp(string, form->name)) {
|
|
||||||
object_to_jsval(ctx, rval, get_form_object(ctx, parent_doc,
|
|
||||||
find_form_view(doc_view, form)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
41
test/ecmascript/forms.namedItem.html
Normal file
41
test/ecmascript/forms.namedItem.html
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>forms.namedItem variations</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
<BODY>
|
||||||
|
<FORM name="f" action="#">
|
||||||
|
<P><BUTTON name="b" type="button">dummy</BUTTON></P>
|
||||||
|
</FORM>
|
||||||
|
<SCRIPT type="application/ecmascript">
|
||||||
|
// iceweasel 2.0+dfsg-1: [object HTMLFormElement]
|
||||||
|
// ELinks 0.11.3: [object form]
|
||||||
|
window.alert("window.document.forms.f=" + window.document.forms.f);
|
||||||
|
</SCRIPT>
|
||||||
|
<SCRIPT type="application/ecmascript">
|
||||||
|
// iceweasel 2.0+dfsg-1: [object HTMLFormElement]
|
||||||
|
// ELinks 0.11.3: [object form]
|
||||||
|
window.alert("window.document.forms[\"f\"]=" + window.document.forms["f"]);
|
||||||
|
</SCRIPT>
|
||||||
|
<SCRIPT type="application/ecmascript">
|
||||||
|
// iceweasel 2.0+dfsg-1: [object HTMLFormElement]
|
||||||
|
// ELinks 0.11.3: TypeError: window.document.forms.namedItem is not a function
|
||||||
|
window.alert("window.document.forms.namedItem(\"f\")=" + window.document.forms.namedItem("f"));
|
||||||
|
</SCRIPT>
|
||||||
|
<SCRIPT type="application/ecmascript">
|
||||||
|
// iceweasel 2.0+dfsg-1: undefined
|
||||||
|
// ELinks 0.11.3: null
|
||||||
|
window.alert("window.document.forms.notfound=" + window.document.forms.notfound);
|
||||||
|
</SCRIPT>
|
||||||
|
<SCRIPT type="application/ecmascript">
|
||||||
|
// iceweasel 2.0+dfsg-1: undefined
|
||||||
|
// ELinks 0.11.3: null
|
||||||
|
window.alert("window.document.forms[\"notfound\"]=" + window.document.forms["notfound"]);
|
||||||
|
</SCRIPT>
|
||||||
|
<SCRIPT type="application/ecmascript">
|
||||||
|
// iceweasel 2.0+dfsg-1: null
|
||||||
|
// ELinks 0.11.3: TypeError: window.document.forms.namedItem is not a function
|
||||||
|
window.alert("window.document.forms.namedItem(\"notfound\")=" + window.document.forms.namedItem("notfound"));
|
||||||
|
</SCRIPT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
Loading…
Reference in New Issue
Block a user