Add a comment


Avatar: pieroxy

Re: node.js vs Java nashorn

I updated the test to include java 8u45 which includes optimistic typing. As for the command line I used, I just launched the test with java -cp . Interpreted

The code:

import java.nio.charset.*;
import java.nio.file.*;
import java.io.*;

import javax.script.*;

public class Interpreted {

  static String readFile(String path, Charset encoding) 
    throws IOException 
    byte[] encoded = Files.readAllBytes(Paths.get(path));
    return new String(encoded, encoding);

  public static void main(String[]args) throws Exception {
      ScriptEngineManager factory = new ScriptEngineManager();
      // Used for jdk8u05 and Java7: ScriptEngine engine = factory.getEngineByName("JavaScript");
      // Used for jdk8u45: ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine(new String[] {"-ot=true"});

      Bindings bindings = new SimpleBindings();
      bindings.put("console", new Console());
      System.out.println("Loading uglify");
      executeJs("uglifyjs-full.js",engine, bindings);
      System.out.println("Loading test");
      executeJs("test.js",engine, bindings);

  private static void executeJs(String fileName, ScriptEngine engine, Bindings bindings) throws Exception {
    String test = readFile(fileName, StandardCharsets.UTF_8);
    engine.put(ScriptEngine.FILENAME, fileName);
    engine.eval(test, bindings);


Re: node.js vs Java nashorn

HTML : b, strong, i, em, blockquote, br, p, pre, a href="", ul, ol, li, sub, sup
OpenID Login
E-mail address
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).