diff options
author | Vincent Sanders <vince@kyllikki.org> | 2016-06-07 16:01:04 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2016-06-07 16:01:04 +0100 |
commit | 042fcb82b83d19bf08afd3367235ac71a60b3850 (patch) | |
tree | 47fe3c15f160b3fac7b0e8ab4f47b495901e0557 /content/handlers/javascript/duktape/NodeList.bnd | |
parent | 9754539e2275e33af34b5de9d343b85e8122d871 (diff) | |
download | netsurf-042fcb82b83d19bf08afd3367235ac71a60b3850.tar.gz netsurf-042fcb82b83d19bf08afd3367235ac71a60b3850.tar.bz2 |
Move javascript content handler as appropriate for updated source format
Diffstat (limited to 'content/handlers/javascript/duktape/NodeList.bnd')
-rw-r--r-- | content/handlers/javascript/duktape/NodeList.bnd | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/content/handlers/javascript/duktape/NodeList.bnd b/content/handlers/javascript/duktape/NodeList.bnd new file mode 100644 index 000000000..7ddf56d15 --- /dev/null +++ b/content/handlers/javascript/duktape/NodeList.bnd @@ -0,0 +1,54 @@ +/* NodeList binding for browser using duktape and libdom + * + * Copyright 2015 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * Released under the terms of the MIT License, + * http://www.opensource.org/licenses/mit-license + */ + +class NodeList { + private struct dom_nodelist *nodes; +}; + +init NodeList(struct dom_nodelist *nodes) +%{ + priv->nodes = nodes; + dom_nodelist_ref(nodes); +%} + +fini NodeList() +%{ + dom_nodelist_unref(priv->nodes); +%} + +getter NodeList::length() +%{ + dom_exception err; + uint32_t len; + + err = dom_nodelist_get_length(priv->nodes, &len); + + if (err != DOM_NO_ERR) return 0; /* coerced to undefined */ + + duk_push_uint(ctx, (duk_uint_t)len); + + return 1; +%} + +method NodeList::item() +%{ + unsigned long i = duk_to_uint(ctx, 0); + dom_exception err; + dom_node *node; + + err = dom_nodelist_item(priv->nodes, i, &node); + + if (err != DOM_NO_ERR) return 0; /* coerced to undefied */ + + dukky_push_node(ctx, node); + dom_node_unref(node); + + return 1; +%} |