summaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2012-08-05 14:28:10 +0100
committerChris Young <chris@unsatisfactorysoftware.co.uk>2012-08-05 14:28:10 +0100
commit7716143240429371e8f357ddc44d15d343759ae1 (patch)
tree8df5a2839bcfdf4d0f68f2df8ab3f112ea36bf1b /javascript
parent1e02eba1932b1fa2eff148ed6e9b58170a74189e (diff)
parentf5891097cc955e05946f114a7e28b36f61faddf1 (diff)
downloadnetsurf-7716143240429371e8f357ddc44d15d343759ae1.tar.gz
netsurf-7716143240429371e8f357ddc44d15d343759ae1.tar.bz2
Merge branch 'master' of git://git.netsurf-browser.org/netsurf
Diffstat (limited to 'javascript')
-rw-r--r--javascript/jsapi/document.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index c54d2f6a5..49144c4a9 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -115,7 +115,40 @@ static JSClass jsclass_document =
static JSBool JSAPI_NATIVE(getElementById, JSContext *cx, uintN argc, jsval *vp)
{
- JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
+ JSString* u16_txt;
+ char *txt;
+ unsigned long txtlen;
+ struct html_content *htmlc;
+ dom_string *idstr;
+ dom_element *idelement;
+
+ htmlc = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), &jsclass_document, NULL);
+ if (htmlc == NULL)
+ return JS_FALSE;
+
+ if (htmlc->document == NULL) {
+ /* no document available, this is obviously a problem
+ * for finding elements
+ */
+ JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
+
+ return JS_TRUE;
+ }
+
+ if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
+ return JS_FALSE;
+
+ JSString_to_char(u16_txt, txt, txtlen);
+
+ dom_string_create((unsigned char*)txt, txtlen, &idstr);
+
+ dom_document_get_element_by_id(htmlc->document, idstr, &idelement);
+
+ if (idelement==NULL) {
+ JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
+ } else {
+ /* create element object and return it*/
+ }
return JS_TRUE;
}