[Pkg-javascript-commits] [dojo] 69/87: Fixes #12342. Refactor destroy and empty to work with IE9/10 and avoid multi-doc exceptions. Backported attr_reconnect test to 1.7 to work with IE10.

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:39:22 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.7.5
in repository dojo.

commit 346137aed340c79a032df75d4a6c4eb31eefdb5d
Author: Douglas Hays <doughays at dojotoolkit.org>
Date:   Fri Nov 30 23:33:05 2012 +0000

    Fixes #12342.  Refactor destroy and empty to work with IE9/10 and avoid multi-doc exceptions.  Backported attr_reconnect test to 1.7 to work with IE10.
    
    git-svn-id: http://svn.dojotoolkit.org/src/branches/1.7/dojo@30096 560b804f-0ae3-0310-86f3-f6aa0a117693
---
 dom-construct.js      | 58 +++++++++++++++++++++++++--------------------------
 tests/_base/html.html | 16 ++++++++------
 2 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/dom-construct.js b/dom-construct.js
index b3ccc0e..3617cdd 100644
--- a/dom-construct.js
+++ b/dom-construct.js
@@ -247,14 +247,6 @@ define(["exports", "./_base/kernel", "./_base/sniff", "./_base/window", "./dom",
 		}
 	}
 
-	var _destroyContainer = null,
-		_destroyDoc;
-	//>>excludeStart("webkitMobile", kwArgs.webkitMobile);
-	on(window, "unload", function(){
-		_destroyContainer = null; //prevent IE leak
-	});
-	//>>excludeEnd("webkitMobile");
-
 	exports.toDom = function toDom(frag, doc){
 		doc = doc || win.doc;
 		var masterId = doc[masterName];
@@ -288,7 +280,7 @@ define(["exports", "./_base/kernel", "./_base/sniff", "./_base/window", "./dom",
 
 		// return multiple nodes as a document fragment
 		df = doc.createDocumentFragment();
-		while(fc = master.firstChild){ // intentional assignment
+		while((fc = master.firstChild)){ // intentional assignment
 			df.appendChild(fc);
 		}
 		return df; // DOMNode
@@ -348,33 +340,39 @@ define(["exports", "./_base/kernel", "./_base/sniff", "./_base/window", "./dom",
 		return tag; // DomNode
 	};
 
-	exports.empty =
+	var _empty =
 		//>>excludeStart("webkitMobile", kwArgs.webkitMobile);
-		has("ie") ? function(node){
-			node = dom.byId(node);
-			for(var c; c = node.lastChild;){ // intentional assignment
-				exports.destroy(c);
+		has("ie") ?
+		function(/*DomNode*/ node){
+			try{
+				node.innerHTML = ""; // really fast when it works
+			}catch(e){ // IE can generate Unknown Error
+				for(var c; c = node.lastChild;){ // intentional assignment
+					_destroy(c, node); // destroy is better than removeChild so TABLE elements are removed in proper order
+				}
 			}
 		} :
 		//>>excludeEnd("webkitMobile");
-		function(node){
-			dom.byId(node).innerHTML = "";
+		function(/*DomNode*/ node){
+			node.innerHTML = "";
 		};
 
-	exports.destroy = function destroy(/*DOMNode|String*/node){
-		node = dom.byId(node);
-		try{
-			var doc = node.ownerDocument;
-			// cannot use _destroyContainer.ownerDocument since this can throw an exception on IE
-			if(!_destroyContainer || _destroyDoc != doc){
-				_destroyContainer = doc.createElement("div");
-				_destroyDoc = doc;
-			}
-			_destroyContainer.appendChild(node.parentNode ? node.parentNode.removeChild(node) : node);
-			// NOTE: see http://trac.dojotoolkit.org/ticket/2931. This may be a bug and not a feature
-			_destroyContainer.innerHTML = "";
-		}catch(e){
-			/* squelch */
+	exports.empty = function empty(/*DOMNode|String*/ node){
+		_empty(dom.byId(node));
+	};
+
+
+	function _destroy(/*DomNode*/ node, /*DomNode*/ parent){
+		if(node.firstChild){
+			_empty(node);
+		}
+		if(parent){
+			parent.removeChild(node);
 		}
+	}
+	exports.destroy = function destroy(/*DOMNode|String*/ node){
+		node = dom.byId(node);
+		if(!node){ return; }
+		_destroy(node, node.parentNode);
 	};
 });
diff --git a/tests/_base/html.html b/tests/_base/html.html
index b26906b..a9444ee 100644
--- a/tests/_base/html.html
+++ b/tests/_base/html.html
@@ -466,13 +466,15 @@
 							return def;
 						},
 						function attr_reconnect(t){
-							var input = document.createElement("input");
+							var input = document.createElement("input"),
+								input2 = document.createElement("input");
 							var ctr = 0;
 							dojo.attr(input, "type", "text");
 							dojo.attr(input, "onfocus", function(e){ ctr++; });
 							dojo.attr(input, "onfocus", function(e){ ctr++; });
 							dojo.attr(input, "onfocus", function(e){ ctr++; });
 							dojo.body().appendChild(input);
+							dojo.body().appendChild(input2);
 							if(!dojo.isIE || dojo.isIE > 7){
 								// IE6/7 treats type="text" as missing, even if it was
 								// explicitly specified
@@ -482,11 +484,13 @@
 							var def = new doh.Deferred();
 							input.focus();
 							setTimeout(def.getTestErrback(function(){
-								doh.is(1, ctr);
-								input.blur();
-								input.focus();
-								setTimeout(def.getTestCallback(function(){
-									doh.is(2, ctr);
+								doh.is(1, ctr, "onfocus ctr == 1");
+								input2.focus();
+								setTimeout(def.getTestErrback(function(){
+									input.focus();
+									setTimeout(def.getTestCallback(function(){
+										doh.is(2, ctr, "onfocus ctr == 2");
+									}), 10);
 								}), 10);
 							}), 10);
 							return def;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list