Opened 8 years ago

Closed 8 years ago

#17806 closed enhancement (patchwelcome)

[patch][cla] Compatibility with JDK Nashorn javascript engine

Reported by: Andrew Muraco Owned by: Colin Snover
Priority: high Milestone: 1.10
Component: BuildSystem Version: 1.8.1
Keywords: Cc:
Blocked By: Blocking:


Currently the build system is using Rhino, but due to performance enhancements in the JS execution engine included in Java 1.8+ we should support Nashorn, Rhino's replacement.

Here's what I had to add/change to make the dojo build system work with Nashorn

dojo/_base/configureRhino.js: missing "readFile" global function, line 20

+ if (typeof readFile !== "function") {
+ 		readFile = function(path,encoding){
+			var f = new;
+			return,java.nio.charset.Charset.forName(encoding));
+		};
+	}

util/build/main.js: line 65

-               has.add("is-windows", /indows/.test(environment[""]));
+               has.add("is-windows", /indows/.test(java.lang.System.getProperty("")));

util/build/rhino/fs.js: line 27

-                               os.write(contents);
+                               os.write(contents,0,contents.length);

util/build/rhino/fs.js: line 49

-                       return (new{ return (""); });
+                       return,function(item){ return (""); });

util/build/rhino/process.js: line 4

-                       return environment["user.dir"];
+                       return java.lang.System.getProperty("user.dir");

util/build/rhino/process.js: lines 17-34 (missing runCommand)

-                       for(var args = [], i = 0; i<arguments.length-3; i++){
-                               args.push(arguments[i]);
+                       for(var args = new java.lang.String[arguments.length-3] , i = 0; i<arguments.length-3; i++){
+                               args[i] = (arguments[i]);
                                errorMessage = arguments[i++],
                                bc = arguments[i++],
                                callback = arguments[i],
-                               options = {output:""};
-                       args.push(options);
+                               output;
-                               runCommand.apply(this, args);
-                               callback && callback(0, options.output);
+                               var ps = new java.lang.ProcessBuilder(args);
+                               ps.redirectErrorStream(true);
+                               var pr = ps.start();
+                               pr.waitFor();
+                               output =
+                               callback && callback(0, output);
-                               bc.log("execFailed", ["message", errorMessage, "output", options.output+"", "error", e]);
-                               callback && callback(-1, errorMessage + "\n" + options.output + "\n" + e);
+                               bc.log("execFailed", ["message", errorMessage, "output", output+"", "error", e]);
+                               callback && callback(-1, errorMessage + "\n" + output + "\n" + e);

util/build/transforms/writeOptimized.js: line 84

-                               JSSourceFilefromCode=java.lang.Class.forName('').getMethod('fromCode',[java.lang.String,java.lang.String]);
-                               closurefromCode = function(filename,content){
-                                       return JSSourceFilefromCode.invoke(null,[filename,content]);
-                               };
+                               closurefromCode =;

Some of the changes might require revision to work with both rhino and nashorn, but many changes should work with both.

Change History (6)

comment:1 Changed 8 years ago by dylan

Milestone: tbd1.10
Priority: undecidedhigh

Not sure we can address this for 1.10, but marking it so at least look at it for that release.

comment:2 Changed 8 years ago by Andrew Muraco

The changes to writeOptimized are probably the most troublesome, plus I think closureCompiler changed the class from JSSourceFile to just SourceFile? sometime in 2013, so there's quite a few permutations that should probably be handled.

The other changes all should work with Rhino, although I wrote a few of them using Guava utils, so that isn't ideal.

1.10 would be fantastic, but obviously it's not a blocker.

comment:3 Changed 8 years ago by dylan

Owner: set to Rawld Gill
Status: newassigned

comment:4 Changed 8 years ago by dylan

Summary: Compatibility with JDK Nashorn javascript engine[patch][cla] Compatibility with JDK Nashorn javascript engine

comment:5 Changed 8 years ago by dylan

Owner: changed from Rawld Gill to Colin Snover

comment:6 Changed 8 years ago by Colin Snover

Resolution: patchwelcome
Status: assignedclosed
Type: defectenhancement

This is not a defect but an enhancement. The path forward for fast builds at the moment is Node.js, not Java. It’s not likely that Java will be a supported build environment for Dojo 2. However, an updated PR on GitHub? that continues to be compatible with Rhino will be considered if such a thing is possible.

Note: See TracTickets for help on using tickets.