From bfe3e6abbc547a542122fa34545df697ca36d684 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 1 Nov 2015 09:28:15 +0000 Subject: [PATCH] Implement Element::hasAttribute(). --- Docs/UnimplementedJavascript.txt | 1 - javascript/duktape/Element.bnd | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Docs/UnimplementedJavascript.txt b/Docs/UnimplementedJavascript.txt index a405a5884..c99c5804e 100644 --- a/Docs/UnimplementedJavascript.txt +++ b/Docs/UnimplementedJavascript.txt @@ -466,7 +466,6 @@ method Element::getAttributeNodeNS();\n method Element::getAttributeNS();\n method Element::getElementsByClassName();\n method Element::getElementsByTagNameNS();\n -method Element::hasAttribute();\n method Element::hasAttributeNS();\n method Element::hasAttributes();\n getter Element::localName(string);\n diff --git a/javascript/duktape/Element.bnd b/javascript/duktape/Element.bnd index a5ac8b94f..d34e8c1eb 100644 --- a/javascript/duktape/Element.bnd +++ b/javascript/duktape/Element.bnd @@ -318,6 +318,28 @@ method Element::setAttribute() return 0; %} +method Element::hasAttribute() +%{ + dom_string *attr_name = NULL; + dom_exception exc; + duk_size_t slen; + bool res; + + 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_has_attribute(priv->parent.node, + attr_name, &res); + dom_string_unref(attr_name); + if (exc != DOM_NO_ERR) { + return 0; + } + + duk_push_boolean(ctx, res); + return 1; +%} + getter Element::className () %{ dom_string *classstr = NULL;