Add Element::getAttribute() implementation.

This commit is contained in:
Michael Drake 2015-10-31 23:23:38 +00:00
parent 0247bed13f
commit f65ea4b096
2 changed files with 25 additions and 1 deletions

View File

@ -461,7 +461,6 @@ method Element::before();\n
getter Element::children(user);\n getter Element::children(user);\n
getter Element::classList(user);\n getter Element::classList(user);\n
method Element::closest();\n method Element::closest();\n
method Element::getAttribute();\n
method Element::getAttributeNode();\n method Element::getAttributeNode();\n
method Element::getAttributeNodeNS();\n method Element::getAttributeNodeNS();\n
method Element::getAttributeNS();\n method Element::getAttributeNS();\n

View File

@ -265,6 +265,31 @@ method Element::removeAttribute()
return 0; 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() method Element::setAttribute()
%{ %{
dom_exception exc; dom_exception exc;