Revision: 3805
Author: mikesamuel
Date: Fri Oct 16 18:52:25 2009
Log: Some cleanup, mostly html-emitter related.
http://codereview.appspot.com/132054
[email protected]
http://code.google.com/p/google-caja/source/detail?r=3805
Modified:
/trunk/src/com/google/caja/plugin/html-emitter.js
/trunk/src/com/google/caja/util/Sets.java
/trunk/tests/com/google/caja/reporting/SnippetProducerTest.java
=======================================
--- /trunk/src/com/google/caja/plugin/html-emitter.js Thu Oct 15 15:42:13
2009
+++ /trunk/src/com/google/caja/plugin/html-emitter.js Fri Oct 16 18:52:25
2009
@@ -24,7 +24,7 @@
*
* @author [email protected]
* @provides HtmlEmitter
- * @requires bridal
+ * @requires bridal html html4 ___
*/
/**
@@ -296,6 +296,8 @@
return;
}
tameDoc.sanitizeAttrs___(tagName, attribs);
+ // TODO(mikesamuel): use the insertionPoint's ownerDocument
+ // to create the element.
var el = bridal.createElement(tagName, attribs);
if ((eltype & html4.eflags.OPTIONAL_ENDTAG)
&& el.tagName === insertionPoint.tagName) {
@@ -317,11 +319,12 @@
}
},
pcdata: function (text) {
- insertionPoint.appendChild(
- document.createTextNode(html.unescapeEntities(text)));
+
insertionPoint.appendChild(insertionPoint.ownerDocument.createTextNode(
+ html.unescapeEntities(text)));
},
cdata: function (text) {
- insertionPoint.appendChild(document.createTextNode(text));
+ insertionPoint.appendChild(
+ insertionPoint.ownerDocument.createTextNode(text));
}
};
documentWriter.rcdata = documentWriter.pcdata;
@@ -342,7 +345,7 @@
/**
* A tame version of document.write.
* @param html_varargs according to HTML5, the input to document.write
is
- * an varargs, and the HTML is the concatenation of all the
arguments.
+ * varargs, and the HTML is the concatenation of all the arguments.
*/
var tameDocWrite = function write(html_varargs) {
var htmlText = concat(arguments);
@@ -350,7 +353,7 @@
// Handles case 3 where the document has been closed.
insertionPoint = base;
}
- var lexer = html.makeSaxParser(documentWriter);
+ var lexer = html.makeSaxParser(documentWriter);
lexer(htmlText);
};
tameDoc.write = ___.markFuncFreeze(tameDocWrite, 'write');
=======================================
--- /trunk/src/com/google/caja/util/Sets.java Thu Oct 15 15:42:13 2009
+++ /trunk/src/com/google/caja/util/Sets.java Fri Oct 16 18:52:25 2009
@@ -143,7 +143,7 @@
/** <tt>a U b</tt> */
public static <T> Set<T> union(
Collection<? extends T> a, Collection<? extends T> b) {
- Set<T> u = new LinkedHashSet<T>(a);
+ Set<T> u = newLinkedHashSet(a);
u.addAll(b);
return u;
}
@@ -156,7 +156,7 @@
a = b;
b = t;
}
- Set<T> i = new LinkedHashSet<T>(b);
+ Set<T> i = newLinkedHashSet(b);
i.retainAll(a);
return i;
}
@@ -164,7 +164,7 @@
/** <tt>(pos - neg)</tt>. */
public static <T> Set<T> difference(
Collection<? extends T> pos, Collection<? extends T> neg) {
- Set<T> d = new LinkedHashSet<T>(pos);
+ Set<T> d = newLinkedHashSet(pos);
d.removeAll(neg);
return d;
}
=======================================
--- /trunk/tests/com/google/caja/reporting/SnippetProducerTest.java Thu Jul
23 09:16:30 2009
+++ /trunk/tests/com/google/caja/reporting/SnippetProducerTest.java Fri Oct
16 18:52:25 2009
@@ -17,11 +17,11 @@
import com.google.caja.lexer.CharProducer;
import com.google.caja.lexer.FilePosition;
import com.google.caja.lexer.InputSource;
+import com.google.caja.util.Maps;
import java.io.IOException;
import java.io.StringReader;
import java.net.URI;
-import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
@@ -36,7 +36,7 @@
+ "\r\n"
+ "f1 line 3\n");
- static final String F2_TEXT = "f2 line 1";
+ static final String F2_TEXT = "f2\tline 1";
static final String F3_TEXT =
"123456789.abcdefghi.123456789.ABCDEFGHI.";
@@ -50,8 +50,7 @@
@Override
public void setUp() throws Exception {
super.setUp();
- Map<InputSource, String> originalSource
- = new HashMap<InputSource, String>();
+ Map<InputSource, String> originalSource = Maps.newHashMap();
originalSource.put(f1, F1_TEXT);
originalSource.put(f2, F2_TEXT);
originalSource.put(f3, F3_TEXT);
@@ -106,9 +105,9 @@
Message msg = new Message(
TestMessageType.ONE,
FilePosition.instance(f2, 1, 4, 4, 4));
- assertEquals(
- ("f2:1: f2 line 1\n" +
- " ^^^^"),
+ assertEquals( // Tabs expanded
+ ("f2:1: f2 line 1\n" +
+ " ^^^^"),
s.getSnippet(msg));
}
@@ -126,7 +125,7 @@
1 + F1_TEXT.indexOf(" line 3"))
);
assertEquals(
- ("f2:1: f2 line 1\n" +
+ ("f2:1: f2 line 1\n" +
" ^^\n" +
"f1:3: f1 line 3\n" +
" ^^"),
@@ -137,7 +136,7 @@
Message msg = new Message(
TestMessageType.ONE, FilePosition.instance(f2, 1, 3, 3));
assertEquals(
- ("f2:1: f2 line 1\n" +
+ ("f2:1: f2 line 1\n" +
" ^"),
s.getSnippet(msg));
}
@@ -159,8 +158,8 @@
TestMessageType.ONE,
FilePosition.instance(f2, 1, endPos, endPos));
assertEquals(
- ("f2:1: f2 line 1\n" +
- " ^"),
+ ("f2:1: f2 line 1\n" +
+ " ^"),
s.getSnippet(msg));
}