Permalink
Browse files

Merge pull request #21 from bigeasy/setAttribute-in-use

Throw `INUSE_ATTRIBUTE_ERR`.
  • Loading branch information...
2 parents 27fedc9 + 409677c commit 121647d745530ef7908233a7249608926dfbfe7c @bigeasy bigeasy committed Jul 1, 2012
Showing with 19 additions and 3 deletions.
  1. +2 −2 dom.js
  2. +17 −1 test/dom/attr.js
View
4 dom.js
@@ -200,7 +200,7 @@ NamedNodeMap.prototype = {
setNamedItem: function(attr) {
var el = attr.ownerElement;
if(el && el!=this._ownerElement){
- el.removeAttributeNode(attr);
+ throw new DOMException(INUSE_ATTRIBUTE_ERR);
}
var oldAttr = this.getNamedItem(attr.nodeName);
_addNamedNode(this._ownerElement,this,attr,oldAttr);
@@ -210,7 +210,7 @@ NamedNodeMap.prototype = {
setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
var el = attr.ownerElement, oldAttr;
if(el && el!=this._ownerElement){
- el.removeAttributeNode(attr);
+ throw new DOMException(INUSE_ATTRIBUTE_ERR);
}
oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
_addNamedNode(this._ownerElement,this,attr,oldAttr);
View
@@ -12,17 +12,33 @@ wows.describe('XML attrs').addBatch({
root.setAttribute('a',1);
root.setAttribute('a',1);
console.assert(root.attributes.length == 2);
+ try {
+ var c = root.ownerDocument.createElement('c');
+ c.setAttributeNode(root.attributes.item(0));
+ } catch (e) {
+ console.assert(e.code == 10);
+ return;
+ }
+ console.assert(false);
},
"set ns attribute":function(){
var root = new DOMParser().parseFromString("<xml xmlns:a='a' xmlns:b='b' xmlns='e'><child/></xml>",'text/xml').documentElement;
var child = root.firstChild
- child.setAttributeNS('a','a:a','1');
+ child.setAttributeNS('a','a:a','1');
child.setAttributeNS('b','b:b','2');
child.setAttributeNS('b','b:a','1');
console.assert(child.attributes.length == 3,child.attributes.length,child+'');
child.setAttribute('a',1);
child.setAttributeNS('b','b:b','2');
console.assert(child.attributes.length == 4,child.attributes.length);
+ try {
+ var c = root.ownerDocument.createElement('c');
+ c.setAttributeNodeNS(root.attributes.item(0));
+ } catch (e) {
+ console.assert(e.code == 10);
+ return;
+ }
+ console.assert(false);
},
"override attribute":function(){
var root = new DOMParser().parseFromString("<xml xmlns:a='a' xmlns:b='b' xmlns='e'><child/></xml>",'text/xml').documentElement;

0 comments on commit 121647d

Please sign in to comment.