From: dhrname Date: Wed, 20 Jun 2012 13:27:11 +0000 (+0900) Subject: DOMExceptionのマジックナンバーは軽量化のために、コメントと数字を活用 X-Git-Tag: v16beta~525 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=05ee63e18a32550b9e8f4c880962f6dfba3b6516;p=sie%2Fsie.git DOMExceptionのマジックナンバーは軽量化のために、コメントと数字を活用 --- diff --git a/org/w3c/core.js b/org/w3c/core.js index e52db9d..6d1c1dc 100644 --- a/org/w3c/core.js +++ b/org/w3c/core.js @@ -133,6 +133,7 @@ WRONG_DOCUMENT_ERR */ }; (function(t) { +/*マジックナンバーは軽量化のため原則コメントで記述するのみ t.INDEX_SIZE_ERR = 1; t.DOMSTRING_SIZE_ERR = 2; t.HIERARCHY_REQUEST_ERR = 3; @@ -147,7 +148,7 @@ t.INVALID_STATE_ERR = 11; t.SYNTAX_ERR = 12; t.INVALID_MODIFICATION_ERR = 13; t.NAMESPACE_ERR = 14; -t.INVALID_ACCESS_ERR = 15; +t.INVALID_ACCESS_ERR = 15;*/ t.prototype = new Error(); })(DOMException); @@ -253,13 +254,13 @@ Node.prototype = { if (tp) { while (!tp) { //先祖をたどっていく if (tp === n) { //先祖要素が追加ノードならばエラー - throw (new DOMException(DOMException.HIERARCHY_REQUEST_ERR)); + throw (new DOMException(/*DOMException.HIERARCHY_REQUEST_ERR*/ 3)); } tp = tp.parentNode; } } if (this.ownerDocument !== n.ownerDocument) { //所属Documentの生成元が違うならば - throw (new DOMException(DOMException.WRONG_DOCUMENT_ERR)); + throw (new DOMException(/*DOMException.WRONG_DOCUMENT_ERR*/ 4)); } if (np === this) { //入力した要素が子要素ならば this.removeChild(n); @@ -277,7 +278,7 @@ Node.prototype = { } } else { if (ref.parentNode !== this) { //参照ノードが子要素でない場合 - throw (new DOMException(DOMException.NOT_FOUND_ERR)); + throw (new DOMException(/*DOMException.NOT_FOUND_ERR*/ 8)); } this.childNodes.splice(ref._num,1,n,ref); //Arrayのspliceを利用して、リストにnノードを追加 rp = ref.previousSibling; @@ -319,7 +320,7 @@ Node.prototype = { ele.previousSibling && (ele.previousSibling.nextSibling = ele.nextSibling); ele.nextSibling && (ele.nextSibling.previousSibling = ele.previousSibling); } else { //親が違う場合 - throw (new DOMException(DOMException.NOT_FOUND_ERR)); + throw (new DOMException(/*DOMException.NOT_FOUND_ERR*/ 8)); } if (ele.ownerDocument !== this.ownerDocument) { //所属ドキュメントが違う場合 throw (new Error()); @@ -463,7 +464,7 @@ NamedNodeMap.prototype = { return s; } else { if (arg.ownerElement !== void 0) { //ノードがもはや別の要素で使われている - throw (new DOMException(DOMException.INUSE_ATTRIBUTE_ERR)); + throw (new DOMException(/*DOMException.INUSE_ATTRIBUTE_ERR*/ 10)); } this[this.length] = arg; //新たに、argを項目として追加する this.length += 1; @@ -477,7 +478,7 @@ NamedNodeMap.prototype = { /*Node*/ removeNamedItemNS : function(/*string*/ namespaceURI, /*string*/ localName) { var tgans = this.getNamedItemNS(namespaceURI, localName); if (!tgans) { //ノードが見当たらない場合、 - throw (new DOMException(DOMException.NOT_FOUND_ERR)); + throw (new DOMException(/*DOMException.NOT_FOUND_ERR*/ 8)); } else { var s = this[this._num]; delete (this[this._num]); @@ -504,7 +505,7 @@ CharacterData.prototype.length = 0; */ /*string*/ CharacterData.prototype.substringData = function(/*long*/ offset, /*long*/ count) { if (offset < 0 || count < 0 || offset > this.length) { //値が負か、データの長さよりoffsetが長いとき、サイズエラーを起こす - throw (new DOMException(INDEX_SIZE_ERR)); + throw (new DOMException(/*INDEX_SIZE_ERR*/ 1)); } if (offset + count > this.length) { //offsetとcountの和が文字全体の長さを超える場合、offsetから最後までのを取り出す count = this.length - offset; @@ -533,7 +534,7 @@ CharacterData.prototype.length = 0; }; /*void*/ CharacterData.prototype.replaceData = function( /*long*/ offset, /*long*/ count, /*string*/ arg) { if (offset < 0 || count < 0 || offset > this.length) { //値が負か、データの長さよりoffsetが長いとき、サイズエラーを起こす - throw (new DOMException(INDEX_SIZE_ERR)); + throw (new DOMException(/*INDEX_SIZE_ERR*/ 1)); } this.deleteData(offset, count); this.insertData(offset, arg); @@ -608,7 +609,7 @@ Element.prototype.nodeValue = null; }; /*Attr*/ Element.prototype.setAttributeNodeNS = function( /*Attr*/ newAttr){ if (newAttr.ownerDocument !== this.ownerDocument) { //所属ドキュメントが違う場合 - throw (new DOMException(DOMException.WRONG_DOCUMENT_ERR)); + throw (new DOMException(/*DOMException.WRONG_DOCUMENT_ERR*/ 4)); } var s = this.attributes.setNamedItemNS(newAttr); newAttr.ownerElement = this; @@ -942,7 +943,7 @@ Document.constructor = Node; s.publicId = importedNode.publicId; s.systemId = importedNode.systemId; } else { - throw (new DOMException(DOMException.NOT_SUPPORTED_ERR)); + throw (new DOMException(/*DOMException.NOT_SUPPORTED_ERR*/ 9)); } importedNode = deep = imn = attr = att = fi = n = uri = ch = void 0; return s; @@ -956,7 +957,7 @@ Document.constructor = Node; prefix = null, localName = null; if (!qualifiedName) { - throw (new DOMException(DOMException.INVALID_CHARACTER_ERR)); + throw (new DOMException(/*DOMException.INVALID_CHARACTER_ERR*/ 5)); } if (qualifiedName.indexOf(":") !== -1){ var p = qualifiedName.split(":"); diff --git a/org/w3c/dom/css.js b/org/w3c/dom/css.js index b520012..ee5e4c0 100644 --- a/org/w3c/dom/css.js +++ b/org/w3c/dom/css.js @@ -408,7 +408,7 @@ t.prototype = new CSSValue(); this._em = this._ex = this["_%"] = null; //emが単位の場合、getComputedStyleメソッドなどで使う /*void*/ this.setFloatValue = function(/*short*/ unitType, /*float*/ floatValue) { if ((/*CSSPrimitiveValue.CSS_UNKNOWN*/ 0 >= unitType) && (unitType >= /*CSSPrimitiveValue.CSS_STRING*/ 19)) { //浮動小数点数単位型をサポートしないCSS単位である場合 - throw new DOMException(DOMException.INVALID_ACCESS_ERR); + throw new DOMException(/*DOMException.INVALID_ACCESS_ERR*/ 15); } this.primitiveType = unitType; this._value = floatValue * this._n[unitType-1]; //値はあらかじめ、利用しやすいように変換しておく @@ -419,7 +419,7 @@ t.prototype = new CSSValue(); this._regd = /[\d\.]+/; /*float*/ this.getFloatValue = function(/*short*/ unitType) { if ((/*CSSPrimitiveValue.CSS_UNKNOWN*/ 0 >= unitType) && (unitType >= /*CSSPrimitiveValue.CSS_STRING*/ 19)) { //浮動小数点数単位型をサポートしないCSS単位である場合 - throw new DOMException(DOMException.INVALID_ACCESS_ERR); + throw new DOMException(/*DOMException.INVALID_ACCESS_ERR*/ 15); } if (this._value || (this._value === 0)) { //すでに、setFloatValueメソッドによって_valueプロパティが設定されていた場合 return (this._value / this._n[unitType-1]); @@ -463,31 +463,31 @@ t.prototype = new CSSValue(); }; /*void*/ this.setStringValue = function(/*short*/ stringType, /*string*/ stringValue) { if (CSSPrimitiveValue.CSS_DIMENSION >= stringType && stringType >= CSSPrimitiveValue.CSS_COUNTER) { //文字列型をサポートしないCSS単位である場合 - throw new DOMException(DOMException.INVALID_ACCESS_ERR); + throw new DOMException(/*DOMException.INVALID_ACCESS_ERR*/ 15); } this._value = stringValue; }; /*string*/ this.getStringValue = function(/*short*/ stringType) { if (CSSPrimitiveValue.CSS_DIMENSION >= stringType && stringType >= CSSPrimitiveValue.CSS_COUNTER) { //文字列型をサポートしないCSS単位である場合 - throw new DOMException(DOMException.INVALID_ACCESS_ERR); + throw new DOMException(/*DOMException.INVALID_ACCESS_ERR*/ 15); } return (this._value); }; /*Counter*/ this.getCounterValue = function() { if (this.primitiveType !== CSSPrimitiveValue.CSS_COUNTER) { //Counter型ではないとき - throw new DOMException(DOMException.INVALID_ACCESS_ERR); + throw new DOMException(/*DOMException.INVALID_ACCESS_ERR*/ 15); } return (new Counter()); }; /*Rect*/ this.getRectValue = function() { if (this.primitiveType !== CSSPrimitiveValue.CSS_RECT) { //Rect型ではないとき - throw new DOMException(DOMException.INVALID_ACCESS_ERR); + throw new DOMException(/*DOMException.INVALID_ACCESS_ERR*/ 15); } return (new Rect()); }; /*RGBColor*/ this.getRGBColorValue = function() { if (this.primitiveType !== CSSPrimitiveValue.CSS_RGBCOLOR) { //RGBColor型ではないとき - throw new DOMException(DOMException.INVALID_ACCESS_ERR); + throw new DOMException(/*DOMException.INVALID_ACCESS_ERR*/ 15); } var s = new RGBColor(); var rgbColor = this.cssText; diff --git a/org/w3c/dom/events.js b/org/w3c/dom/events.js index 6ad6d38..8ef7081 100644 --- a/org/w3c/dom/events.js +++ b/org/w3c/dom/events.js @@ -354,7 +354,7 @@ MutationEvent.prototype = new Event(); */ /*Attr*/ Element.prototype.setAttributeNodeNS = function( /*Attr*/ newAttr){ if (newAttr.ownerDocument !== this.ownerDocument) { //所属ドキュメントが違う場合 - throw (new DOMException(DOMException.WRONG_DOCUMENT_ERR)); + throw (new DOMException(/*DOMException.WRONG_DOCUMENT_ERR*/ 4)); } var s = this.attributes.setNamedItemNS(newAttr); newAttr.ownerElement = this; @@ -387,13 +387,13 @@ MutationEvent.prototype = new Event(); if (tp) { while (!tp) { //先祖をたどっていく if (tp === n) { //先祖要素が追加ノードならばエラー - throw (new DOMException(DOMException.HIERARCHY_REQUEST_ERR)); + throw (new DOMException(/*DOMException.HIERARCHY_REQUEST_ERR*/ 3)); } tp = tp.parentNode; } } if (this.ownerDocument !== n.ownerDocument) { //所属Documentの生成元が違うならば - throw (new DOMException(DOMException.WRONG_DOCUMENT_ERR)); + throw (new DOMException(/*DOMException.WRONG_DOCUMENT_ERR*/ 4)); } if (np === this) { //入力した要素が子要素ならば this.removeChild(n); @@ -411,7 +411,7 @@ MutationEvent.prototype = new Event(); } } else { if (ref.parentNode !== this) { //参照ノードが子要素でない場合 - throw (new DOMException(DOMException.NOT_FOUND_ERR)); + throw (new DOMException(/*DOMException.NOT_FOUND_ERR*/ 8)); } this.childNodes.splice(ref._num,1,n,ref); //Arrayのspliceを利用して、リストにnノードを追加 rp = ref.previousSibling; @@ -514,7 +514,7 @@ MutationEvent.prototype = new Event(); ele.previousSibling && (ele.previousSibling.nextSibling = ele.nextSibling); ele.nextSibling && (ele.nextSibling.previousSibling = ele.previousSibling); } else { //親が違う場合 - throw (new DOMException(DOMException.NOT_FOUND_ERR)); + throw (new DOMException(/*DOMException.NOT_FOUND_ERR*/ 8)); } if (ele.ownerDocument !== this.ownerDocument) { //所属ドキュメントが違う場合 throw (new Error()); diff --git a/org/w3c/dom/svg.js b/org/w3c/dom/svg.js index 1245d1d..2e68bdc 100644 --- a/org/w3c/dom/svg.js +++ b/org/w3c/dom/svg.js @@ -447,7 +447,7 @@ SVGStringList.prototype = new Array(); }; /*DOMString*/ this.getItem = function(/*unsigned long*/ index ) { if (index >= this.numberOfItems || index < 0) { - throw (new DOMException(DOMException.INDEX_SIZE_ERR)); + throw (new DOMException(/*DOMException.INDEX_SIZE_ERR*/ 1)); } else { return (this[index]); } @@ -463,7 +463,7 @@ SVGStringList.prototype = new Array(); }; /*DOMString*/ this.replaceItem = function(/*DOMString*/ newItem, /*unsigned long*/ index ){ if (index >= this.numberOfItems || index < 0) { - throw (new DOMException(DOMException.INDEX_SIZE_ERR)); + throw (new DOMException(/*DOMException.INDEX_SIZE_ERR*/ 1)); } else { this.splice(index, 1, newItem); } @@ -472,7 +472,7 @@ SVGStringList.prototype = new Array(); //raises( DOMException, SVGException ); /*DOMString*/ this.removeItem = function(/*unsigned long*/ index ){ if (index >= this.numberOfItems || index < 0) { - throw (new DOMException(DOMException.INDEX_SIZE_ERR)); + throw (new DOMException(/*DOMException.INDEX_SIZE_ERR*/ 1)); } else { this.splice(index, 1); --this.numberOfItems; @@ -580,7 +580,7 @@ SVGLength.prototype = { n = 15; _s = "pc"; } else { - throw new DOMException(DOMException.NOT_SUPPORTED_ERR); + throw new DOMException(/*DOMException.NOT_SUPPORTED_ERR*/ 9); } this.unitType = unitType; this.value = valueInSpecifiedUnits * n; @@ -655,7 +655,7 @@ SVGAngle.prototype = { n = 9 / 10; _s = "grad"; } else { - throw new DOMException(DOMException.NOT_SUPPORTED_ERR); + throw new DOMException(/*DOMException.NOT_SUPPORTED_ERR*/ 9); } this.unitType = unitType; this.value = valueInSpecifiedUnits * n; @@ -3947,7 +3947,7 @@ t.prototype = new SVGElement(); } /*SVGPoint*/ t.prototype.getStartPositionOfChar = function (/*unsigned long*/ charnum ) { if (charnum > this.getNumberOfChars() || charnum < 0) { - throw (new DOMException(DOMException.INDEX_SIZE_ERR)); + throw (new DOMException(/*DOMException.INDEX_SIZE_ERR*/ 1)); } else { var tar = this, ti = tar.firstChild, @@ -4105,7 +4105,7 @@ t.prototype = new SVGElement(); }; /*SVGPoint*/ t.prototype.getEndPositionOfChar = function(/*unsigned long*/ charnum ) { if (charnum > this.getNumberOfChars() || charnum < 0) { - throw (new DOMException(DOMException.INDEX_SIZE_ERR)); + throw (new DOMException(/*DOMException.INDEX_SIZE_ERR*/ 1)); } else { var s = this.getStartPositionOfChar(charnum); //アドバンス値(すなわちフォントの大きさ)をCTMの行列式を用いて、算出する @@ -5354,7 +5354,7 @@ function SVGAnimationElement(es) { } } catch (e) { tar.endElementAt(1); - throw new DOMException(DOMException.INVALID_STATE_ERR); + throw new DOMException(/*DOMException.INVALID_STATE_ERR*/ 11); } if ((ac || (ac === 0)) && isFinite(ac)) { /*endの値がすでにある場合は、二重指定を避ける*/ @@ -5647,7 +5647,7 @@ SVGAnimationElement.prototype._getOffset = function(/*string*/ val) { if (this._starting || (this._starting === 0)) { return (this._starting); } else { - throw new DOMException(DOMException.INVALID_STATE_ERR); + throw new DOMException(/*DOMException.INVALID_STATE_ERR*/ 11); } }; /*getCurrentTimeメソッド @@ -5659,7 +5659,7 @@ SVGAnimationElement.prototype._getOffset = function(/*string*/ val) { }; /*float*/ SVGAnimationElement.prototype.getSimpleDuration = function(){ if (!this._dur && !this._finish && (this._dur === "indefinite")) { - throw new DOMException(DOMException.NOT_SUPPORTED_ERR); + throw new DOMException(/*DOMException.NOT_SUPPORTED_ERR*/ 9); } else { return (this._getOffset(this._dur)); }