Index: src/com/google/caja/lang/html/HtmlDefinitions.java
===================================================================
--- src/com/google/caja/lang/html/HtmlDefinitions.java (revision 5149)
+++ src/com/google/caja/lang/html/HtmlDefinitions.java (working copy)
@@ -128,10 +128,34 @@
"v", new ParseTreeNodeContainer(values)));
}
+ /**
+ * Generate a JS object-building statement from the given Map, whose keys
+ * should stringify to the JS keys and whose values are mapped by the function
+ * {@code codegen}.
+ */
+ private static ExpressionStmt mapFromMap(
+ Map, T> entries, String key, Function codegen) {
+ final FilePosition unk = FilePosition.UNKNOWN;
+ List keys = new ArrayList();
+ List values = new ArrayList();
+ for (Map.Entry, T> e : entries.entrySet()) {
+ keys.add(StringLiteral.valueOf(unk, e.getKey().toString()));
+ values.add(codegen.apply(e.getValue()));
+ }
+ ExpressionStmt def = new ExpressionStmt(unk, (Expression)
+ QuasiBuilder.substV(
+ "html4.@i = { @k*: @v* };",
+ "i", new Reference(new Identifier(unk, key)),
+ "k", new ParseTreeNodeContainer(keys),
+ "v", new ParseTreeNodeContainer(values)));
+ return def;
+ }
+
public static Block generateJavascriptDefinitions(HtmlSchema schema) {
final FilePosition unk = FilePosition.UNKNOWN;
Map atypes = attributeTypes(schema);
Map> eflags = elementFlags(schema);
+ Map einterfaces = elementDOMInterfaces(schema);
Map uriEffects = uriEffects(schema);
Map ltypes = loaderTypes(schema);
@@ -188,23 +212,28 @@
})
);
- {
- List keys = new ArrayList();
- List values = new ArrayList();
- for (Map.Entry> e : eflags.entrySet()) {
- ElKey key = e.getKey();
- int value = 0;
- for (EFlag f : e.getValue()) { value |= f.bitMask; }
- keys.add(StringLiteral.valueOf(unk, key.toString()));
- values.add(new IntegerLiteral(unk, value));
- }
- definitions.appendChild(new ExpressionStmt(unk, (Expression)
- QuasiBuilder.substV(
- "html4.ELEMENTS = { @k*: @v* };",
- "k", new ParseTreeNodeContainer(keys),
- "v", new ParseTreeNodeContainer(values))));
- }
+ definitions.appendChild(mapFromMap(
+ eflags,
+ "ELEMENTS",
+ new Function, Expression>() {
+ public Expression apply(EnumSet flags) {
+ int value = 0;
+ for (EFlag f : flags) { value |= f.bitMask; }
+ return new IntegerLiteral(unk, value);
+ }
+ })
+ );
+ definitions.appendChild(mapFromMap(
+ einterfaces,
+ "ELEMENT_DOM_INTERFACES",
+ new Function() {
+ public Expression apply(String domInterface) {
+ return new StringLiteral(unk, domInterface);
+ }
+ })
+ );
+
definitions.appendChild(mapFromEnum(
EnumSet.allOf(UriEffect.class),
"ueffects",
@@ -432,6 +461,15 @@
return elementFlags;
}
+ private static Map elementDOMInterfaces(HtmlSchema schema) {
+ Map data = Maps.newTreeMap();
+ for (ElKey elementName : schema.getElementNames()) {
+ HTML.Element el = schema.lookupElement(elementName);
+ data.put(elementName, el.getDOMInterface());
+ }
+ return data;
+ }
+
public static class Builder implements BuildCommand {
public boolean build(List inputs, List deps, Map options,
File output) throws IOException {
@@ -510,6 +548,8 @@
out.write("// exports for Closure Compiler\n");
out.write("html4['ATTRIBS'] = html4.ATTRIBS;\n");
out.write("html4['ELEMENTS'] = html4.ELEMENTS;\n");
+ out.write("html4['ELEMENT_DOM_INTERFACES'] = " +
+ "html4.ELEMENT_DOM_INTERFACES;\n");
out.write("html4['URIEFFECTS'] = html4.URIEFFECTS;\n");
out.write("html4['LOADERTYPES'] = html4.LOADERTYPES;\n");
out.write("html4['atype'] = html4.atype;\n");