#2516 Fantom JS Runner on Java8

SlimerDude Thu 25 Feb 2016

It's great being able to run pods and tests in JS from the command line:

C:\> fan compilerJs::Runner afAwesome

C:\> fant -js afAwesome

But I ran into errors when running Java8.

Digging around the JS code, I found several references to a global println method. It seems println is no longer supported in Nashorn and Java8 (but it was in Rhino and Java6). Nashorn does support print though:

C:\> jdk1.8.0_65\bin\jjs

jjs> print("Hello")http://fantom.org/forum/new/#
Hello

jjs> println("Hello")
<shell>:1 ReferenceError: "println" is not defined

So below is a small patch which simply replaces the 5 occurrences of println with print:

diff -r 245c05ba794e src/compilerJs/fan/runner/ScriptRunner.fan
--- a/src/compilerJs/fan/runner/ScriptRunner.fan	Thu Feb 25 14:46:29 2016 -0500
+++ b/src/compilerJs/fan/runner/ScriptRunner.fan	Thu Feb 25 21:03:46 2016 +0000
@@ -97,7 +97,7 @@
       $js
       fan.temp.Main.make().main();
       }
-      catch (err) { println('ERROR: ' + err); }
+      catch (err) { print('ERROR: ' + err + '\\n'); }
       ")
   }
 }
diff -r 245c05ba794e src/compilerJs/fan/runner/TestRunner.fan
--- a/src/compilerJs/fan/runner/TestRunner.fan	Thu Feb 25 14:46:29 2016 -0500
+++ b/src/compilerJs/fan/runner/TestRunner.fan	Thu Feb 25 21:03:46 2016 +0000
@@ -199,13 +199,13 @@
           var test;
           var doCatchErr = function(err)
           {
-            if (err == undefined) println('Undefined error');
+            if (err == undefined) print('Undefined error\n');
             else if (err.trace) err.trace();
             else
             {
               var file = err.fileName;   if (file == null) file = 'Unknown';
               var line = err.lineNumber; if (line == null) line = 'Unknown';
-              println(err + ' (' + file + ':' + line + ')');
+              print(err + ' (' + file + ':' + line + ')\n');
             }
           }
 
diff -r 245c05ba794e src/sys/js/fan/ObjUtil.js
--- a/src/sys/js/fan/ObjUtil.js	Thu Feb 25 14:46:29 2016 -0500
+++ b/src/sys/js/fan/ObjUtil.js	Thu Feb 25 21:03:46 2016 +0000
@@ -221,7 +221,7 @@
   try { console.log(s); }
   catch (e1)
   {
-    try { println(s); }
+    try { print(s + "\n"); }
     catch (e2) {} //alert(s); }
   }
 }
diff -r 245c05ba794e src/sys/js/fan/Pod.js
--- a/src/sys/js/fan/Pod.js	Thu Feb 25 14:46:29 2016 -0500
+++ b/src/sys/js/fan/Pod.js	Thu Feb 25 21:03:46 2016 +0000
@@ -96,7 +96,7 @@
   if (t == null && checked)
   {
     //fan.sys.ObjUtil.echo("UnknownType: " + this.m_name + "::" + name);
-    //println("# UnknownType: " + this.m_name + "::" + name);
+    //print("# UnknownType: " + this.m_name + "::" + name + "\n");
     throw fan.sys.UnknownTypeErr.make(this.m_name + "::" + name);
   }
   return t;
diff -r 245c05ba794e src/sys/js/fan/Test.js
--- a/src/sys/js/fan/Test.js	Thu Feb 25 14:46:29 2016 -0500
+++ b/src/sys/js/fan/Test.js	Thu Feb 25 21:03:46 2016 +0000
@@ -134,8 +134,8 @@
   {
     var e = fan.sys.Err.make(err);
     if (e.$typeof() == errType || errType == null) { this.verifyCount++; return; }
-    //if (verbose) System.out.println("  verifyErr: " + e);
-    println("  verifyErr: " + e);
+    //if (verbose) System.out.print("  verifyErr: " + e + "\n");
+    print("  verifyErr: " + e + "\n");
     this.fail(e.$typeof() + " thrown, expected " + errType);
   }
   this.fail("No err thrown, expected " + errType);
@@ -151,7 +151,7 @@
   {
     var e = fan.sys.Err.make(err);
     if (e.$typeof() != errType) {
-      println("  verifyErrMsg: " + e);
+      print("  verifyErrMsg: " + e + "\n");
       this.fail(e.$typeof() + " thrown, expected " + errType);
     }
     this.verifyCount++;

andy Thu 25 Feb 2016

I assume print is supported < 1.8 - so that patch is backwards compatible?

andy Fri 26 Feb 2016

Thanks Steve - merged

Login or Signup to reply.