Author: [email protected]
Date: Fri Jun 12 15:49:54 2009
New Revision: 5554
Modified:
trunk/dev/core/src/com/google/gwt/core/ext/linker/CompilationResult.java
trunk/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java
trunk/dev/core/test/com/google/gwt/core/linker/ScriptChunkingTest.java
Log:
Allow CompilationResult.getStatementRanges() to return null,
and have it do so by default.
Review by: jat
Modified:
trunk/dev/core/src/com/google/gwt/core/ext/linker/CompilationResult.java
==============================================================================
---
trunk/dev/core/src/com/google/gwt/core/ext/linker/CompilationResult.java
(original)
+++
trunk/dev/core/src/com/google/gwt/core/ext/linker/CompilationResult.java
Fri Jun 12 15:49:54 2009
@@ -51,9 +51,12 @@
/**
* Returns the statement ranges for the JavaScript returned by
- * {...@link #getJavaScript()}.
+ * {...@link #getJavaScript()}. Some subclasses return <code>null</code>, in
+ * which case there is no statement range information available.
*/
- public abstract StatementRanges[] getStatementRanges();
+ public StatementRanges[] getStatementRanges() {
+ return null;
+ }
/**
* Return a string that uniquely identifies this compilation result.
Typically
Modified: trunk/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java
(original)
+++ trunk/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java Fri Jun
12 15:49:54 2009
@@ -58,10 +58,16 @@
* Split a JavaScript string into multiple chunks, at statement
boundaries.
* Insert and end-script tag and a start-script tag in between each
chunk.
* This method is made default access for testing.
+ *
+ * @param ranges Describes where the statements are located within the
+ * JavaScript code. If <code>null</code>, then return
<code>js</code>
+ * unchanged.
+ * @param js The JavaScript code to be split up.
+ * @param charsPerChunk The number of characters to be put in each
script tag
*/
static String splitPrimaryJavaScript(StatementRanges ranges, String js,
int charsPerChunk) {
- if (charsPerChunk < 0) {
+ if (charsPerChunk < 0 || ranges == null) {
return js;
}
@@ -72,8 +78,7 @@
int start = ranges.start(i);
int end = ranges.end(i);
int length = end - start;
- if (bytesInCurrentTag > 0
- && bytesInCurrentTag + length > charsPerChunk) {
+ if (bytesInCurrentTag > 0 && bytesInCurrentTag + length >
charsPerChunk) {
if (lastChar(sb) != '\n') {
sb.append('\n');
}
Modified:
trunk/dev/core/test/com/google/gwt/core/linker/ScriptChunkingTest.java
==============================================================================
--- trunk/dev/core/test/com/google/gwt/core/linker/ScriptChunkingTest.java
(original)
+++ trunk/dev/core/test/com/google/gwt/core/linker/ScriptChunkingTest.java
Fri Jun 12 15:49:54 2009
@@ -118,4 +118,23 @@
builder.getJavaScript(), -1);
assertEquals(builder.getJavaScript(), split);
}
+
+ /**
+ * Test with statement ranges not present, which should disable the
chunking.
+ */
+ public void testNullStatementRanges() {
+ ScriptWithRangesBuilder builder = new ScriptWithRangesBuilder();
+ builder.addNonStatement("{");
+ builder.addNonStatement("{");
+ builder.addStatement("x=1;");
+ builder.addStatement("function x(){x = 2}\n");
+ builder.addStatement("x=3");
+ builder.addNonStatement("}\n{");
+ builder.addStatement("x=5");
+ builder.addNonStatement("}");
+
+ String split = IFrameLinker.splitPrimaryJavaScript(null,
+ builder.getJavaScript(), 5);
+ assertEquals(builder.getJavaScript(), split);
+ }
}
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---