Skip to content
Browse files

refactored 2 more methods to use *NamedItemNS internally

  • Loading branch information...
1 parent 24d3ce7 commit 2d5265edd6a582b355b85520eda4b84bbfa12f18 @tmpvar tmpvar committed Feb 6, 2011
Showing with 22 additions and 38 deletions.
  1. +22 −38 lib/jsdom/level2/core.js
View
60 lib/jsdom/level2/core.js
@@ -198,10 +198,10 @@ core.NamedNodeMap.prototype.setNamedItemNS = function(/* Node */ arg)
throw new core.DOMException(core.WRONG_DOCUMENT_ERR);
}
-
if (arg._parentNode) {
throw new core.DOMException(core.INUSE_ATTRIBUTE_ERR);
}
+
return this.setNamedItem(arg);
};
@@ -355,36 +355,24 @@ core.Element.prototype.removeAttributeNS = function(/* string */ namespaceURI,
throw new core.DOMException(core.NO_MODIFICATION_ALLOWED_ERR);
}
-
var defaults = this.ownerDocument.doctype._attributes, clone,
- found = this._attributes._map(function(attr) {
- if (namespaceURI === attr.namespaceURI &&
- attr.localName === localName)
- {
- return true;
- }
- }),
- defaultEl = defaults.getNamedItem(this.name),
- defaultAttr;
-
-
- if (!found || !found[0]) {
- return;
- } else if (found[0]) {
- found = found[0];
- }
+ found = this._attributes.getNamedItemNS(namespaceURI, localName),
+ defaultEl = defaults.getNamedItemNS(namespaceURI, localName),
+ defaultAttr,
+ clone;
if (defaultEl) {
- defaultAttr = defaultEl.getAttributeNode(found.name);
+ defaultAttr = defaultEl.attributes.getNamedItemNS(namespaceURI, localName);
}
- this.removeAttributeNode(found);
+ if (found) {
+ this.attributes.removeNamedItemNS(namespaceURI, localName);
+ }
if (defaultAttr) {
- clone = defaultAttr.cloneNode(true);
- clone.namespaceURI = found.namespaceURI;
- clone.qualifiedName = found.name;
- this.setAttributeNodeNS(clone);
+ clone = this.setAttributeNS(defaultAttr.namespaceURI,
+ defaultAttr.name,
+ defaultAttr.value);
clone._specified = false;
}
@@ -394,13 +382,7 @@ core.Element.prototype.removeAttributeNS = function(/* string */ namespaceURI,
core.Element.prototype.getAttributeNodeNS = function(/* string */ namespaceURI,
/* string */ localName)
{
- return this._attributes._map(function(attr) {
- if (namespaceURI === attr.namespaceURI &&
- attr._localName === localName)
- {
- return true;
- }
- })[0] || null;
+ return this._attributes.getNamedItemNS(namespaceURI, localName);
};
core.Element.prototype._created = false;
@@ -410,15 +392,17 @@ core.Element.prototype.setAttributeNodeNS = function(/* Attr */ newAttr)
throw new core.DOMException(core.INUSE_ATTRIBUTE_ERR);
}
- var existing = this.getAttributeNodeNS(newAttr.namespaceURI,
- newAttr._localName);
- if (existing) {
- this.removeAttributeNode(existing);
- }
+ var existing = null;
+
+ try {
+ existing = this._attributes.removeNamedItemNS(newAttr.namespaceURI,
+ newAttr.localName);
+ } catch (e) { /* noop */}
newAttr._ownerElement = this;
- this.setAttributeNode(newAttr);
- return existing;
+ this.attributes.setNamedItemNS(newAttr);
+
+ return existing || null;
};
core.Element.prototype.getElementsByTagNameNS = function(/* String */ namespaceURI,

0 comments on commit 2d5265e

Please sign in to comment.
Something went wrong with that request. Please try again.