From f65ea4b096fbb2a555547a400224108bfdb955df Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 31 Oct 2015 23:23:38 +0000 Subject: [PATCH] Add Element::getAttribute() implementation. --- Docs/UnimplementedJavascript.txt | 1 - javascript/duktape/Element.bnd | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Docs/UnimplementedJavascript.txt b/Docs/UnimplementedJavascript.txt index 133b8f554..a405a5884 100644 --- a/Docs/UnimplementedJavascript.txt +++ b/Docs/UnimplementedJavascript.txt @@ -461,7 +461,6 @@ method Element::before();\n getter Element::children(user);\n getter Element::classList(user);\n method Element::closest();\n -method Element::getAttribute();\n method Element::getAttributeNode();\n method Element::getAttributeNodeNS();\n method Element::getAttributeNS();\n diff --git a/javascript/duktape/Element.bnd b/javascript/duktape/Element.bnd index 231c7affb..4bb9367b5 100644 --- a/javascript/duktape/Element.bnd +++ b/javascript/duktape/Element.bnd @@ -265,6 +265,31 @@ method Element::removeAttribute() return 0; %} +method Element::getAttribute() +%{ + dom_string *attr_name = NULL; + dom_string *attr_value = NULL; + dom_exception exc; + duk_size_t slen; + + const char *s = duk_safe_to_lstring(ctx, 0, &slen); + exc = dom_string_create((const uint8_t *)s, slen, &attr_name); + duk_pop(ctx); + + exc = dom_element_get_attribute(priv->parent.node, + attr_name, &attr_value); + dom_string_unref(attr_name); + if (exc != DOM_NO_ERR) return 0; + if (attr_value == NULL) { + duk_push_lstring(ctx, "", 0); + } else { + duk_push_lstring(ctx, dom_string_data(attr_value), + dom_string_length(attr_value)); + dom_string_unref(attr_value); + } + return 1; +%} + method Element::setAttribute() %{ dom_exception exc;