From 9b568abf96defa0194f4fcb6e68d008c6e28423e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 22 Jan 2013 18:59:10 +0000 Subject: add default property handler for array indexing --- javascript/jsapi/nodelist.bnd | 41 ++++++++++++++++++++++++++++++----- test/js/dom-getElementsByTagName.html | 10 +++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/javascript/jsapi/nodelist.bnd b/javascript/jsapi/nodelist.bnd index 4aa8c47f5..d7adafd93 100644 --- a/javascript/jsapi/nodelist.bnd +++ b/javascript/jsapi/nodelist.bnd @@ -39,6 +39,41 @@ binding nodelist { private "struct html_content *" htmlc; } +api finalise %{ + if (private != NULL) { + dom_nodelist_unref(private->nodelist); + } +%} + +/* default handler for numericaly indexed property values */ +api getproperty %{ + jsval queryprop; + int idx; + JSObject *jsret = NULL; /* Node */ + dom_exception err; + dom_node *domnode; + + JSAPI_PROP_IDVAL(cx, &queryprop); + if (JSVAL_IS_INT(queryprop)) { + idx = JSVAL_TO_INT(queryprop); + LOG(("Index was %d", idx)); + + + err = dom_nodelist_item(private->nodelist, idx, &domnode); + if (err != DOM_NO_ERR) { + return JS_FALSE; + } + + if (domnode != NULL) { + jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc); + + JSLOG("return object:%p", jsret); + + JSAPI_PROP_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsret)); + } + } +%} + getter length %{ dom_exception err; @@ -62,9 +97,3 @@ operation item %{ } %} -api finalise %{ - if (private != NULL) { - dom_nodelist_unref(private->nodelist); - } -%} - diff --git a/test/js/dom-getElementsByTagName.html b/test/js/dom-getElementsByTagName.html index 02cdffc4d..2f03e7b46 100644 --- a/test/js/dom-getElementsByTagName.html +++ b/test/js/dom-getElementsByTagName.html @@ -15,6 +15,16 @@ for (var i=0;i +
+

+ -- cgit v1.2.3