Bug 692031 - DOMTemplate async loops do not drop the loop element; r=rcampbell

This commit is contained in:
Joe Walker 2011-10-12 14:09:38 -03:00
parent d6c2b7750f
commit d170c3da5e
2 changed files with 10 additions and 19 deletions

View File

@ -1,5 +1,3 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -13,11 +11,11 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Bespin.
* The Original Code is GCLI
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
@ -39,14 +37,10 @@
* ***** END LICENSE BLOCK ***** */
var EXPORTED_SYMBOLS = ["Templater"];
var EXPORTED_SYMBOLS = [ "Templater" ];
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
const Node = Ci.nsIDOMNode;
Components.utils.import("resource://gre/modules/Services.jsm");
const Node = Components.interfaces.nsIDOMNode;
// WARNING: do not 'use_strict' without reading the notes in _envEval();
@ -263,9 +257,9 @@ Templater.prototype._processForEachMember = function(member, template, siblingNo
try {
this._handleAsync(member, siblingNode, function(reply, node) {
data[paramName] = reply;
if (node.nodeName.toLowerCase() === 'loop') {
for (var i = 0; i < node.childNodes.length; i++) {
var clone = node.childNodes[i].cloneNode(true);
if (template.nodeName.toLowerCase() === 'loop') {
for (var i = 0; i < template.childNodes.length; i++) {
var clone = template.childNodes[i].cloneNode(true);
node.parentNode.insertBefore(clone, node);
this.processNode(clone, data);
}
@ -331,7 +325,7 @@ Templater.prototype._toNode = function(thing, document) {
if (thing == null) {
thing = '' + thing;
}
// if (isDOMElement(reply)) { ... }
// if thing isn't a DOM element then wrap its string value in one
if (typeof thing.cloneNode !== 'function') {
thing = document.createTextNode(thing.toString());
}
@ -387,7 +381,7 @@ Templater.prototype._stripBraces = function(str) {
* </ul>
* @param path An array of strings indicating the path through the data, or
* a string to be cut into an array using <tt>split('.')</tt>
* @param data An object to look in for the <tt>path</tt> argument
* @param data the data to use for node processing
* @param newValue (optional) If defined, this value will replace the
* original value for the data at the path specified.
* @return The value pointed to by <tt>path</tt> before any
@ -470,4 +464,3 @@ Templater.prototype._handleError = function(message, ex) {
Templater.prototype._logError = function(message) {
Services.console.logStringMessage(message);
};

View File

@ -128,7 +128,6 @@ var tests = [
};},
// Bug 692031: DOMTemplate async loops do not drop the loop element
/*
function() { return {
name: 'asyncLoopElement',
template: '<loop foreach="i in ${array}">${i}</loop>',
@ -136,7 +135,6 @@ var tests = [
result: '<span></span>',
later: '123'
};},
//*/
function() { return {
name: 'saveElement',