Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #490 from jannehietamaki/coffeescript_compiler_opt…

…imization

Precompile CoffeeScript to reduce startup time
  • Loading branch information...
commit e80092a32dd46ec400928eafbd505e3cd67476fd 2 parents f11813d + 9aad95e
@purplefox purplefox authored
View
14 vertx-lang/vertx-lang-rhino/build.gradle
@@ -15,6 +15,7 @@
*/
apply from: "$rootDir/gradle/maven.gradle"
+apply plugin: 'java'
sourceSets {
main {
@@ -32,4 +33,17 @@ dependencies {
artifacts {
platform jar
+}
+
+compileJava {
+ javaexec {
+ classpath sourceSets.main.compileClasspath
+ main = "org.mozilla.javascript.tools.jsc.Main"
+ args = [
+ '-opt', '9',
+ '-d', 'build/classes/main/',
+ '-package', 'org.vertx.java.deploy.impl.rhino',
+ 'src/main/coffeescript/coffee-script.js'
+ ]
+ }
}
View
23 vertx-lang/vertx-lang-rhino/src/main/java/org/vertx/java/deploy/impl/rhino/CoffeeScriptCompiler.java
@@ -18,6 +18,7 @@
import org.mozilla.javascript.Context;
import org.mozilla.javascript.JavaScriptException;
+import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import java.io.*;
@@ -35,30 +36,18 @@
private final Scriptable globalScope;
public CoffeeScriptCompiler(ClassLoader classLoader) {
- InputStream inputStream = classLoader.getResourceAsStream("coffee-script.js");
try {
- Reader reader = new InputStreamReader(inputStream, "UTF-8");
+ Context context = Context.enter();
try {
- Context context = Context.enter();
- context.setOptimizationLevel(-1); // Without this, Rhino hits a 64K bytecode limit and fails
- try {
- globalScope = context.initStandardObjects();
- context.evaluateReader(globalScope, reader, "coffee-script.js", 0, null);
- } finally {
- Context.exit();
- }
+ globalScope = context.initStandardObjects();
+ Script coffeeCompiler = (Script) Class.forName("org.vertx.java.deploy.impl.rhino.coffee_script").newInstance();
+ coffeeCompiler.exec(context, globalScope);
} finally {
- reader.close();
+ Context.exit();
}
} catch (Exception e) {
throw new RuntimeException(e);
- } finally {
- try {
- inputStream.close();
- } catch (IOException e) {
- }
}
-
}
public URI coffeeScriptToJavaScript(URI coffeeScript) throws JavaScriptException,
Please sign in to comment.
Something went wrong with that request. Please try again.