[Sie-announce] SIEコード [2769] グローバルオブジェクトのdocumentをローカルにしておいて軽量化

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 6月 12日 (日) 19:58:48 JST


Revision: 2769
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2769
Author:   dhrname
Date:     2011-06-12 19:58:48 +0900 (Sun, 12 Jun 2011)

Log Message:
-----------
グローバルオブジェクトのdocumentをローカルにしておいて軽量化

Modified Paths:
--------------
    branches/08x/080/org/w3c/core.js
    branches/08x/080/org/w3c/dom/svg.js

Modified: branches/08x/080/org/w3c/core.js
===================================================================
--- branches/08x/080/org/w3c/core.js	2011-06-12 09:55:23 UTC (rev 2768)
+++ branches/08x/080/org/w3c/core.js	2011-06-12 10:58:48 UTC (rev 2769)
@@ -958,7 +958,7 @@
     }
   }
   if (isSpecified) {
-    ele = new (ti[namespaceURI][localName]);
+    ele = new (ti[namespaceURI][localName])(this._document_);
   } else {
     ele = new Element();
   }
@@ -970,6 +970,7 @@
   ti = namespaceURI = qualifiedName = prefix = localName = isSpecified = null;
   return ele;
 };
+Document.prototype._document_ = document
 /*createAttributeNSメソッド
  *属性ノードを作る。setAttributeNSで使うため、削除不可
  */

Modified: branches/08x/080/org/w3c/dom/svg.js
===================================================================
--- branches/08x/080/org/w3c/dom/svg.js	2011-06-12 09:55:23 UTC (rev 2768)
+++ branches/08x/080/org/w3c/dom/svg.js	2011-06-12 10:58:48 UTC (rev 2769)
@@ -1124,9 +1124,10 @@
 /*SVGSVGElement
  *svg要素をあらわすオブジェクト
  */
-function SVGSVGElement() {
+function SVGSVGElement(_doc) {
   SVGElement.apply(this, arguments);
-  this._tar = document.createElement("v:group");
+  this._tar = _doc.createElement("v:group");
+  _doc = null;
   /*_svgload_limitedはSVGLoadイベントを発火させる判定基準。
    * Xlink言語が使われていない限り0であり、SVGLoadイベントが発火される*/
   this._svgload_limited = 0;
@@ -1423,9 +1424,10 @@
 SVGViewSpec.constructor = SVGFitToViewBox;
 SVGViewSpec.prototype = new SVGFitToViewBox();
 
-function SVGGElement() {
+function SVGGElement(_doc) {
   SVGElement.apply(this);
-  this._tar = document.createElement("v:group");
+  this._tar = _doc.createElement("v:group");
+  _doc = null;
   /*以下の処理は、この子要素ノードがDOMツリーに追加されて初めて、
    *描画が開始されることを示す。つまり、appendChildで挿入されない限り、描画をしない。
    */
@@ -1578,9 +1580,10 @@
 /*SVGElementInstance*/ SVGElementInstanceList.prototype.item = function(/*unsigned long*/ index ) {
   return (this[index]);
 }
-function SVGImageElement() {
+function SVGImageElement(_doc) {
   SVGElement.apply(this, arguments);
-  this._tar = document.createElement("v:image");
+  this._tar = _doc.createElement("v:image");
+  _doc = null;
   //以下は、与えられた属性の値に対応する
   /*readonly SVGAnimatedLength*/ this.x = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.y = new SVGAnimatedLength();
@@ -1901,7 +1904,7 @@
 /*SVGStyleElement
  *style要素をあらわすオブジェクト
  */
-function SVGStyleElement() {
+function SVGStyleElement(_doc) {
   SVGElement.apply(this);
   LinkStyle.apply(this);
   /*LinkStyleに関しては、以下の仕様を参照のこと。なお、これはSVG DOMでは継承されていないので要注意。
@@ -1929,13 +1932,13 @@
         sheet = tar.sheet,
         styleText = tar._text,
         tod = tar.ownerDocument,
-        style = document.createElement("style"),
+        style = _doc.createElement("style"),
         ri, rsc, scri, rsi;
     NAIBU._temp_doc = tod;
     sheet = tod.styleSheets[tod.styleSheets.length] = DOMImplementation.createCSSStyleSheet(tar.title, tar.media);
     sheet.ownerNode = tar;
     /*以下は、IEのCSSパーサを使って、スタイルシートのルールを実装していく*/
-    document.documentElement.firstChild.appendChild(style);
+    _doc.documentElement.firstChild.appendChild(style);
     style.styleSheet.cssText = styleText;
     for (var i=0, rules=style.styleSheet.rules, rli=rules.length;i<rli;++i) {
       ri = rules[i];
@@ -2479,6 +2482,7 @@
    *処理を行う。SVGPaintインターフェースをも用いる
    */
   var tod = tar.ownerDocument,
+      _doc = tod._document_,
       el = tar._tar,
       style = tod.defaultView.getComputedStyle(tar, ""),
       fill = style.getPropertyCSSValue("fill"),
@@ -2599,10 +2603,10 @@
    } else if (disp && !disp._isDefault && (disp.indexOf("inline-block") === -1)) {
     el.style.display = "inline-block";
   }
-  tod = el = fill = stroke = sp = fp = style = cursor = tar = matrix = vis = disp = num = null;
+  tod = _doc = el = fill = stroke = sp = fp = style = cursor = tar = matrix = vis = disp = num = null;
 };
 
-function SVGPathElement() {
+function SVGPathElement(_doc) {
   SVGElement.apply(this);
   this._tar = _doc.createElement("v:shape");
   //interface SVGAnimatedPathData
@@ -3269,9 +3273,10 @@
   NAIBU.SVGPathElement = SVGPathElement; //IE8では、SVGPathElementはローカル変数
 })(document, parseInt, Math);
 
-function SVGRectElement() {
+function SVGRectElement(_doc) {
   SVGElement.apply(this);
-  this._tar = document.createElement("v:shape");
+  this._tar = _doc.createElement("v:shape");
+  _doc = null;
   /*readonly SVGAnimatedLength*/ this.x = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.y = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.width = new SVGAnimatedLength();
@@ -3369,9 +3374,9 @@
 SVGRectElement.constructor = SVGElement;
 SVGRectElement.prototype = new SVGElement();
 
-function SVGCircleElement() { 
+function SVGCircleElement(_doc) { 
   SVGElement.apply(this);
-  this._tar = document.createElement("v:shape");
+  this._tar = _doc.createElement("v:shape");
   /*readonly SVGAnimatedLength*/ this.cx = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.cy = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.r = new SVGAnimatedLength();
@@ -3445,9 +3450,10 @@
 SVGCircleElement.constructor = SVGElement;
 SVGCircleElement.prototype = new SVGElement();
 
-function SVGEllipseElement() { 
+function SVGEllipseElement(_doc) { 
   SVGElement.apply(this);
-  this._tar = document.createElement("v:shape");
+  this._tar = _doc.createElement("v:shape");
+  _doc = null;
   /*readonly SVGAnimatedLength*/ this.cx = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.cy = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.rx = new SVGAnimatedLength();
@@ -3523,9 +3529,10 @@
 SVGEllipseElement.constructor = SVGElement;
 SVGEllipseElement.prototype = new SVGElement();
 
-function SVGLineElement() { 
+function SVGLineElement(_doc) { 
   SVGElement.apply(this);
-  this._tar = document.createElement("v:shape");
+  this._tar = _doc.createElement("v:shape");
+  _doc = null;
   /*readonly SVGAnimatedLength*/ this.x1 = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.y1 = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.x2 = new SVGAnimatedLength();
@@ -3591,9 +3598,10 @@
 SVGLineElement.constructor = SVGElement;
 SVGLineElement.prototype = new SVGElement();
 
-function SVGPolylineElement() {
+function SVGPolylineElement(_doc) {
   SVGElement.apply(this);
-  this._tar = document.createElement("v:shape");
+  this._tar = _doc.createElement("v:shape");
+  _doc = null;
   //interface SVGAnimatedPoints
   /*readonly SVGPointList*/   this.animatedPoints = this.points = new SVGPointList();
   this.addEventListener("DOMAttrModified", function(evt){
@@ -3669,9 +3677,10 @@
 SVGPolylineElement.constructor = SVGElement;
 SVGPolylineElement.prototype = new SVGElement();
 
-function SVGPolygonElement() {
+function SVGPolygonElement(_doc) {
   SVGElement.apply(this);
-  this._tar = document.createElement("v:shape");
+  this._tar = _doc.createElement("v:shape");
+  _doc = null;
   //interface SVGAnimatedPoints
   /*readonly SVGPointList*/   this.animatedPoints = this.points = new SVGPointList();
   this.addEventListener("DOMAttrModified", function(evt){
@@ -3751,7 +3760,7 @@
 SVGPolygonElement.constructor = SVGElement;
 SVGPolygonElement.prototype = new SVGElement();
 
-function SVGTextContentElement() { 
+function SVGTextContentElement(_doc) { 
   SVGElement.apply(this);
   this._list = null;         //文字の位置を格納しておくリストのキャッシュ
   this._length = 0;          //全文字数
@@ -3776,13 +3785,13 @@
       tar.data = data;
       data = data.split('');
       for (var i=0, tdli=data.length;i<tdli;++i) {
-        var d = document.createElement("div"), dstyle = d.style;
+        var d = _doc.createElement("div"), dstyle = d.style;
         dstyle.position = "absolute";
         dstyle.marginLeft = dstyle.marginRight = dstyle.marginTop = "0px";
         dstyle.paddingTop = dstyle.paddingLeft = "0px";
         dstyle.whiteSpace = "nowrap";
         dstyle.textIndent = "0px";
-        d.appendChild(document.createTextNode(data[i]));
+        d.appendChild(_doc.createTextNode(data[i]));
         tar._tars[tar._tars.length] = d;
       }
       data = null;
@@ -4012,8 +4021,8 @@
   
 };
 
-function SVGTextPositioningElement() { 
-  SVGTextContentElement.apply(this);
+function SVGTextPositioningElement(_doc) { 
+  SVGTextContentElement.apply(this, arguments);
   /*readonly SVGAnimatedLengthList*/ this.x = new SVGAnimatedLengthList();
   /*readonly SVGAnimatedLengthList*/ this.y = new SVGAnimatedLengthList();
   /*readonly SVGAnimatedLengthList*/ this.dx = new SVGAnimatedLengthList();
@@ -4083,9 +4092,9 @@
 SVGTextPositioningElement.constructor = SVGTextContentElement;
 SVGTextPositioningElement.prototype = new SVGTextContentElement();
 
-function SVGTextElement() {
-  SVGTextPositioningElement.apply(this);
-  this._tar = document.createElement("v:group");
+function SVGTextElement(_doc) {
+  SVGTextPositioningElement.apply(this, arguments);
+  this._tar = _doc.createElement("v:group");
   this.addEventListener("DOMNodeInserted", function(evt){
     if (evt.eventPhase === /*Event.BUBBLING_PHASE*/ 3) {
       return; //強制終了させる
@@ -4196,7 +4205,7 @@
         isRect = false;
       }
       if (!isRect) {
-        var backr = document.createElement("v:rect");
+        var backr = _doc.createElement("v:rect");
         var backrs = backr.style; //ずれを修正するためのもの
         backrs.width = "1px";
         backrs.height = "1px";
@@ -4479,7 +4488,7 @@
 SVGLinearGradientElement.constructor = SVGGradientElement;
 SVGLinearGradientElement.prototype = new SVGGradientElement();
 
-function SVGRadialGradientElement() { 
+function SVGRadialGradientElement(_doc) { 
   SVGGradientElement.apply(this);
   /*readonly SVGAnimatedLength*/ this.cx = new SVGAnimatedLength();
   /*readonly SVGAnimatedLength*/ this.cy = new SVGAnimatedLength();
@@ -4545,8 +4554,8 @@
         p = pmt = null;
       }
       var ellipse = list.join(" ");
-      var outline = document.getElementById("_NAIBU_outline");
-      var background = document.createElement("div"), bstyle = background.style;
+      var outline = _doc.getElementById("_NAIBU_outline");
+      var background = _doc.createElement("div"), bstyle = background.style;
       bstyle.position = "absolute";
       bstyle.display = "inline-block";
       var w = vi.width, h = vi.height;
@@ -4698,9 +4707,10 @@
 SVGCursorElement.constructor = SVGElement;
 SVGCursorElement.prototype = new SVGElement();
 
-function SVGAElement() {
+function SVGAElement(_doc) {
   SVGElement.apply(this);
-  this._tar = document.createElement("a");
+  this._tar = _doc.createElement("a");
+  _doc = null;
   /*readonly SVGAnimatedString*/ this.target = new SVGAnimatedString();
   this.addEventListener("DOMAttrModified", function(evt){
     var tar = evt.target;
@@ -5885,7 +5895,7 @@
   if (isMSIE) {
     var rand = "n" +Math.random();
     ti._tar.firstChild.setAttribute("id", rand);
-    var titf = document.getElementById(rand);
+    var titf = ti.ownerDocument._document_.getElementById(rand);
     /*IEのみ、font-sizeは自動で調整されている(つまり、DOMからよびだされた)ものを使った方がよい*/
     fontSize = parseFloat(titf.currentStyle.fontSize);
     fe = fontSize / em;




Sie-announce メーリングリストの案内
Back to archive index