mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
DOM, HTMLCollection: Defined the namedItem method.
This commit is contained in:
parent
4df27a6700
commit
46584fc5c0
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "document/dom/ecmascript/spidermonkey.h"
|
#include "document/dom/ecmascript/spidermonkey.h"
|
||||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLCollection.h"
|
#include "document/dom/ecmascript/spidermonkey/html/HTMLCollection.h"
|
||||||
|
#include "document/dom/ecmascript/spidermonkey/html/HTMLElement.h"
|
||||||
#include "dom/node.h"
|
#include "dom/node.h"
|
||||||
|
|
||||||
static JSBool
|
static JSBool
|
||||||
@ -40,6 +41,8 @@ HTMLCollection_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
|
|||||||
jsval *rval)
|
jsval *rval)
|
||||||
{
|
{
|
||||||
struct dom_node_list *list;
|
struct dom_node_list *list;
|
||||||
|
unsigned char *id;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!obj || (!JS_InstanceOf(ctx, obj, (JSClass *)&HTMLCollection_class, NULL)))
|
if (!obj || (!JS_InstanceOf(ctx, obj, (JSClass *)&HTMLCollection_class, NULL)))
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
@ -49,7 +52,45 @@ HTMLCollection_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
|
|||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
|
|
||||||
|
|
||||||
/* Write me! */
|
id = jsval_to_string(ctx, &argv[0]);
|
||||||
|
for (i = 0; i < list->size; i++) {
|
||||||
|
struct dom_node *node = list->entries[i];
|
||||||
|
struct HTMLElement_struct *html;
|
||||||
|
unsigned char *name;
|
||||||
|
|
||||||
|
if (!node)
|
||||||
|
continue;
|
||||||
|
html = node->data.element.html_data;
|
||||||
|
if (!html)
|
||||||
|
continue;
|
||||||
|
name = html->id;
|
||||||
|
if (!name)
|
||||||
|
continue;
|
||||||
|
if (!strcasecmp(name, id)) {
|
||||||
|
object_to_jsval(ctx, rval, node->ecmascript_obj);
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < list->size; i++) {
|
||||||
|
struct dom_node *node = list->entries[i];
|
||||||
|
JSObject *obj;
|
||||||
|
unsigned char *name;
|
||||||
|
jsval v;
|
||||||
|
|
||||||
|
if (!node)
|
||||||
|
continue;
|
||||||
|
obj = node->ecmascript_obj;
|
||||||
|
if (!obj)
|
||||||
|
continue;
|
||||||
|
if (!JS_GetProperty(ctx, obj, "name", &v))
|
||||||
|
continue;
|
||||||
|
name = jsval_to_string(ctx, &v);
|
||||||
|
if (!strcasecmp(name, id)) {
|
||||||
|
object_to_jsval(ctx, rval, obj);
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
undef_to_jsval(ctx, rval);
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user