Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

boiling it down once again

  • Loading branch information...
commit 66ff77af0e4bb731cb6e21188c72098cd84d7ced 1 parent e47c383
@tmpvar tmpvar authored
View
1  lib/jsdom/level1/core.js
@@ -834,6 +834,7 @@ core.Node.prototype = {
core.NamedNodeMap = function NamedNodeMap(document) {
this._nodes = {};
+ this._nsStore = {};
this.length = 0;
this._ownerDocument = document;
this._readonly = false;
View
59 lib/jsdom/level2/core.js
@@ -151,6 +151,11 @@ core.Node.prototype.hasAttributes = function() {
core.NamedNodeMap.prototype.getNamedItemNS = function(/* string */ namespaceURI,
/* string */ localName)
{
+ if (this._nsStore[namespaceURI] && this._nsStore[namespaceURI][localName]) {
+ return this._nsStore[namespaceURI][localName];
+ }
+ return null;
+
return this._map(function(item) {
var node = null, equal = item.localName === localName;
@@ -202,6 +207,25 @@ core.NamedNodeMap.prototype.setNamedItemNS = function(/* Node */ arg)
throw new core.DOMException(core.INUSE_ATTRIBUTE_ERR);
}
+ // readonly
+ if (this._readonly === true) {
+ throw new core.DOMException(NO_MODIFICATION_ALLOWED_ERR);
+ }
+
+
+ if (!this._nsStore[arg.namespaceURI]) {
+ this._nsStore[arg.namespaceURI] = {};
+ }
+ var existing = null;
+ if (this._nsStore[arg.namespaceURI][arg.localName]) {
+ var existing = this._nsStore[arg.namespaceURI][arg.localName];
+ }
+
+ this._nsStore[arg.namespaceURI][arg.localName] = arg;
+
+ arg._specified = true;
+ arg._ownerDocument = this._ownerDocument;
+
return this.setNamedItem(arg);
};
@@ -229,21 +253,20 @@ core.NamedNodeMap.prototype.removeNamedItemNS = function(/*string */ namespaceUR
}
defaultEl = defaults.getNamedItemNS(parent._namespaceURI, parent._localName);
+ var found = null;
- found = this._map(function(attr) {
- if (namespaceURI === attr.namespaceURI &&
- attr.localName === localName)
- {
- return true;
- }
- })[0] || null;
+ if (this._nsStore[namespaceURI] &&
+ this._nsStore[namespaceURI][localName])
+ {
+ found = this._nsStore[namespaceURI][localName];
+ this.removeNamedItem(found.qualifiedName);
+ delete this._nsStore[namespaceURI][localName];
+ }
if (!found) {
throw new core.DOMException(core.NOT_FOUND_ERR);
}
- this.removeNamedItem(found.name);
-
if (defaultEl) {
defaultAttr = defaultEl._attributes.getNamedItemNS(namespaceURI, localName);
@@ -353,7 +376,7 @@ core.Element.prototype.removeAttributeNS = function(/* string */ namespaceURI,
}
var defaults = this.ownerDocument.doctype._attributes, clone,
- found = this._attributes.getNamedItemNS(namespaceURI, localName),
+ found,
defaultEl = defaults.getNamedItemNS(namespaceURI, localName),
defaultAttr,
clone;
@@ -362,9 +385,7 @@ core.Element.prototype.removeAttributeNS = function(/* string */ namespaceURI,
defaultAttr = defaultEl._attributes.getNamedItemNS(namespaceURI, localName);
}
- if (found) {
- this._attributes.removeNamedItemNS(namespaceURI, localName);
- }
+ found = this._attributes.removeNamedItemNS(namespaceURI, localName);
if (defaultAttr) {
clone = this.setAttributeNS(defaultAttr.namespaceURI,
@@ -390,16 +411,13 @@ core.Element.prototype.setAttributeNodeNS = function(/* Attr */ newAttr)
}
var existing = null;
-
try {
existing = this._attributes.removeNamedItemNS(newAttr.namespaceURI,
newAttr.localName);
} catch (e) { /* noop */}
newAttr._ownerElement = this;
- this._attributes.setNamedItemNS(newAttr);
-
- return existing || null;
+ return this._attributes.setNamedItemNS(newAttr);
};
core.Element.prototype.getElementsByTagNameNS = function(/* String */ namespaceURI,
@@ -440,7 +458,12 @@ core.Element.prototype.hasAttribute = function(/* string */name)
core.Element.prototype.hasAttributeNS = function(/* string */namespaceURI,
/* string */localName)
{
- return !!this._attributes.getNamedItemNS(namespaceURI, localName);
+ if (this._attributes.getNamedItemNS(namespaceURI, localName)) {
+ return true;
+ } else if (this.hasAttribute(localName)) {
+ return true;
+ }
+ return false;
};
core.DocumentType.prototype.__defineGetter__("publicId", function() {
View
1  test/level2/core.js
@@ -4392,6 +4392,7 @@ elementhasattributens02 : function () {
element = doc.createElementNS("http://www.w3.org/DOM","address");
attribute = doc.createAttributeNS("http://www.w3.org/DOM","domestic");
newAttribute = element.setAttributeNode(attribute);
+ console.log(element.attributes._nsStore);
state = element.hasAttributeNS("http://www.w3.org/DOM","domestic");
assertTrue("hasDomesticAttr",state);
Please sign in to comment.
Something went wrong with that request. Please try again.