Mon, 22 Jul 2013 17:40:26 -0700
Merge
jlaskey@3 | 1 | - What is Nashorn? |
jlaskey@3 | 2 | |
jlaskey@3 | 3 | Nashorn is a runtime environment for programs written in ECMAScript 5.1 |
jlaskey@3 | 4 | that runs on top of JVM. |
jlaskey@3 | 5 | |
jlaskey@3 | 6 | - How to find out more about ECMAScript 5.1? |
jlaskey@3 | 7 | |
jlaskey@3 | 8 | The specification can be found at |
jlaskey@3 | 9 | |
jlaskey@3 | 10 | http://www.ecma-international.org/publications/standards/Ecma-262.htm |
jlaskey@3 | 11 | |
jlaskey@3 | 12 | - How to checkout sources of Nashorn project? |
jlaskey@3 | 13 | |
jlaskey@3 | 14 | Nashorn project uses Mercurial source code control system. You can |
jlaskey@3 | 15 | download Mercurial from http://mercurial.selenic.com/wiki/Download |
jlaskey@3 | 16 | |
jlaskey@3 | 17 | Information about the forest extension can be found at |
jlaskey@3 | 18 | |
jlaskey@3 | 19 | http://mercurial.selenic.com/wiki/ForestExtension |
jlaskey@3 | 20 | |
jlaskey@3 | 21 | and downlaoded using |
jlaskey@3 | 22 | |
jlaskey@3 | 23 | hg clone https://bitbucket.org/gxti/hgforest |
jlaskey@3 | 24 | |
jlaskey@3 | 25 | You can clone Nashorn Mercurial forest using this command: |
jlaskey@3 | 26 | |
jlaskey@3 | 27 | hg fclone http://hg.openjdk.java.net/nashorn/jdk8 nashorn~jdk8 |
jlaskey@3 | 28 | |
jlaskey@3 | 29 | To update your copy of the forest (fwith the latest code: |
jlaskey@3 | 30 | |
jlaskey@3 | 31 | (cd nashorn~jdk8 ; hg fpull) |
jlaskey@3 | 32 | |
jlaskey@3 | 33 | Or just the nashorn subdirectory with |
jlaskey@3 | 34 | |
jlaskey@3 | 35 | (cd nashorn~jdk8/nashorn ; hg pull -u) |
jlaskey@3 | 36 | |
jlaskey@3 | 37 | To learn about Mercurial in detail, please visit http://hgbook.red-bean.com. |
jlaskey@3 | 38 | |
jlaskey@3 | 39 | - How to build? |
jlaskey@3 | 40 | |
jlaskey@3 | 41 | To build Nashorn, you need to install JDK 8. You may use the Nashorn |
jlaskey@3 | 42 | forest build (recommended) or down load from java.net. You will need to |
jlaskey@3 | 43 | set JAVA_HOME environmental variable to point to your JDK installation |
jlaskey@3 | 44 | directory. |
jlaskey@3 | 45 | |
jlaskey@3 | 46 | cd nashorn~jdk8/nashorn/make |
jlaskey@3 | 47 | ant clean; ant |
jlaskey@3 | 48 | |
jlaskey@3 | 49 | - How to run? |
jlaskey@3 | 50 | |
jlaskey@3 | 51 | Use the jjs script (see RELESE_README): |
jlaskey@3 | 52 | |
jlaskey@3 | 53 | cd nashorn~jdk8/nashorn |
jlaskey@3 | 54 | sh bin/jjs <your .js file> |
jlaskey@3 | 55 | |
jlaskey@3 | 56 | Nashorn supports javax.script API. It is possible to drop nashorn.jar in |
jlaskey@3 | 57 | class path and request for "nashorn" script engine from |
jlaskey@3 | 58 | javax.script.ScriptEngineManager. |
jlaskey@3 | 59 | |
jlaskey@3 | 60 | Look for samples under the directory test/src/jdk/nashorn/api/scripting/. |
jlaskey@3 | 61 | |
jlaskey@3 | 62 | - Documentation |
jlaskey@3 | 63 | |
jlaskey@3 | 64 | Comprehensive development documentation is found in the Nashorn JavaDoc. You can |
jlaskey@3 | 65 | build it using: |
jlaskey@3 | 66 | |
jlaskey@3 | 67 | cd nashorn~jdk8/nashorn/make |
jlaskey@3 | 68 | ant javadoc |
jlaskey@3 | 69 | |
jlaskey@3 | 70 | after which you can view the generated documentation at dist/javadoc/index.html. |
jlaskey@3 | 71 | |
jlaskey@3 | 72 | - Running tests |
jlaskey@3 | 73 | |
jlaskey@3 | 74 | Nashorn tests are TestNG based. Running tests requires downloading the |
jlaskey@3 | 75 | TestNG library and placing its jar file into the lib subdirectory: |
jlaskey@3 | 76 | |
jlaskey@3 | 77 | # download and install TestNG |
jlaskey@3 | 78 | wget http://testng.org/testng-x.y.z.zip |
jlaskey@3 | 79 | unzip testng-x.y.z.zip |
jlaskey@3 | 80 | cp testng-x.y.z/testng-x.y.z.jar test/lib/testng.jar |
jlaskey@3 | 81 | |
jlaskey@3 | 82 | After that, you can run the tests using: |
jlaskey@3 | 83 | cd make |
jlaskey@3 | 84 | ant test |
jlaskey@3 | 85 | |
jlaskey@3 | 86 | You can also run the ECMA-262 test suite with Nashorn. In order to do |
jlaskey@3 | 87 | that, you will need to get a copy of it and put it in |
jlaskey@3 | 88 | test/script/external/test262 directory. A convenient way to do it is: |
jlaskey@3 | 89 | |
jlaskey@3 | 90 | hg clone http://hg.ecmascript.org/tests/test262/ test/script/external/test262 |
jlaskey@3 | 91 | |
jlaskey@3 | 92 | Alternatively, you can check it out elsewhere and make |
jlaskey@3 | 93 | test/script/external/test262 a symbolic link to that directory. After |
jlaskey@3 | 94 | you've done this, you can run the ECMA-262 tests using: |
jlaskey@3 | 95 | |
jlaskey@3 | 96 | cd nashorn~jdk8/nashorn/make |
jlaskey@3 | 97 | ant test262 |
jlaskey@3 | 98 | |
jlaskey@3 | 99 | These tests take time, so we have a parallelized runner for them that |
jlaskey@3 | 100 | takes advantage of all processor cores on the computer: |
jlaskey@3 | 101 | |
jlaskey@3 | 102 | cd nashorn~jdk8/nashorn/make |
jlaskey@3 | 103 | ant test262parallel |
jlaskey@3 | 104 | |
jlaskey@3 | 105 | - How to write your own test? |
jlaskey@3 | 106 | |
jlaskey@3 | 107 | Nashorn uses it's own simple test framework. Any .js file dropped under |
jlaskey@3 | 108 | nashorn/test directory is considered as a test. A test file can |
jlaskey@3 | 109 | optionally have .js.EXPECTED (foo.js.EXPECTED for foo.js) associated |
jlaskey@3 | 110 | with it. The .EXPECTED file, if exists, should contain the output |
jlaskey@3 | 111 | expected from compiling and/or running the test file. |
jlaskey@3 | 112 | |
jlaskey@3 | 113 | The test runner crawls these directories for .js files and looks for |
jlaskey@3 | 114 | JTReg-style @foo comments to identify tests. |
jlaskey@3 | 115 | |
jlaskey@3 | 116 | * @test - A test is tagged with @test. |
jlaskey@3 | 117 | |
jlaskey@3 | 118 | * @test/fail - Tests that are supposed to fail (compiling, see @run/fail |
jlaskey@3 | 119 | for runtime) are tagged with @test/fail. |
jlaskey@3 | 120 | |
jlaskey@3 | 121 | * @test/compile-error - Test expects compilation to fail, compares |
jlaskey@3 | 122 | output. |
jlaskey@3 | 123 | |
jlaskey@3 | 124 | * @test/warning - Test expects compiler warnings, compares output. |
jlaskey@3 | 125 | |
jlaskey@3 | 126 | * @test/nocompare - Test expects to compile [and/or run?] |
jlaskey@3 | 127 | successfully(may be warnings), does not compare output. |
jlaskey@3 | 128 | |
jlaskey@3 | 129 | * @subtest - denotes necessary file for a main test file; itself is not |
jlaskey@3 | 130 | a test. |
jlaskey@3 | 131 | |
jlaskey@3 | 132 | * @run - A test that should be run is also tagged with @run (otherwise |
jlaskey@3 | 133 | the test runner only compiles the test). |
jlaskey@3 | 134 | |
jlaskey@3 | 135 | * @run/fail - A test that should compile but fail with a runtime error. |
jlaskey@3 | 136 | |
jlaskey@3 | 137 | * @run/ignore-std-error - script may produce output on stderr, ignore |
jlaskey@3 | 138 | this output. |
jlaskey@3 | 139 | |
jlaskey@3 | 140 | * @argument - pass an argument to script. |
jlaskey@3 | 141 | |
jlaskey@3 | 142 | * @option \ - pass option to engine, sample. |
jlaskey@3 | 143 | |
jlaskey@3 | 144 | /** |
jlaskey@3 | 145 | * @option --dump-ir-graph |
jlaskey@3 | 146 | * @test |
jlaskey@3 | 147 | */ |