Sat, 15 Dec 2018 09:34:42 -0800
Added tag jdk8u201-b09 for changeset bf5c40b0e9d8
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 |
mhaupt@1391 | 75 | TestNG library and placing its jar file into the test/lib subdirectory. This is |
mhaupt@1391 | 76 | done automatically when executing the "ant externals" command to get external |
mhaupt@1391 | 77 | test suites (see below). |
jlaskey@3 | 78 | |
mhaupt@1391 | 79 | Once TestNG is properly installed, you can run the tests using: |
jlaskey@3 | 80 | cd make |
sundar@775 | 81 | ant clean test |
jlaskey@3 | 82 | |
jlaskey@3 | 83 | You can also run the ECMA-262 test suite with Nashorn. In order to do |
jlaskey@3 | 84 | that, you will need to get a copy of it and put it in |
jlaskey@3 | 85 | test/script/external/test262 directory. A convenient way to do it is: |
jlaskey@3 | 86 | |
sundar@775 | 87 | git clone https://github.com/tc39/test262 test/script/external/test262 |
jlaskey@3 | 88 | |
jlaskey@3 | 89 | Alternatively, you can check it out elsewhere and make |
jlaskey@3 | 90 | test/script/external/test262 a symbolic link to that directory. After |
jlaskey@3 | 91 | you've done this, you can run the ECMA-262 tests using: |
jlaskey@3 | 92 | |
jlaskey@3 | 93 | cd nashorn~jdk8/nashorn/make |
jlaskey@3 | 94 | ant test262 |
sundar@775 | 95 | |
sundar@775 | 96 | Ant target to get/update external test suites: |
sundar@775 | 97 | |
sundar@775 | 98 | ant externals |
sundar@775 | 99 | ant update-externals |
jlaskey@3 | 100 | |
jlaskey@3 | 101 | These tests take time, so we have a parallelized runner for them that |
jlaskey@3 | 102 | takes advantage of all processor cores on the computer: |
jlaskey@3 | 103 | |
jlaskey@3 | 104 | cd nashorn~jdk8/nashorn/make |
jlaskey@3 | 105 | ant test262parallel |
jlaskey@3 | 106 | |
jlaskey@3 | 107 | - How to write your own test? |
jlaskey@3 | 108 | |
jlaskey@3 | 109 | Nashorn uses it's own simple test framework. Any .js file dropped under |
jlaskey@3 | 110 | nashorn/test directory is considered as a test. A test file can |
jlaskey@3 | 111 | optionally have .js.EXPECTED (foo.js.EXPECTED for foo.js) associated |
jlaskey@3 | 112 | with it. The .EXPECTED file, if exists, should contain the output |
jlaskey@3 | 113 | expected from compiling and/or running the test file. |
jlaskey@3 | 114 | |
jlaskey@3 | 115 | The test runner crawls these directories for .js files and looks for |
jlaskey@3 | 116 | JTReg-style @foo comments to identify tests. |
jlaskey@3 | 117 | |
jlaskey@3 | 118 | * @test - A test is tagged with @test. |
jlaskey@3 | 119 | |
jlaskey@3 | 120 | * @test/fail - Tests that are supposed to fail (compiling, see @run/fail |
jlaskey@3 | 121 | for runtime) are tagged with @test/fail. |
jlaskey@3 | 122 | |
jlaskey@3 | 123 | * @test/compile-error - Test expects compilation to fail, compares |
jlaskey@3 | 124 | output. |
jlaskey@3 | 125 | |
jlaskey@3 | 126 | * @test/warning - Test expects compiler warnings, compares output. |
jlaskey@3 | 127 | |
jlaskey@3 | 128 | * @test/nocompare - Test expects to compile [and/or run?] |
jlaskey@3 | 129 | successfully(may be warnings), does not compare output. |
jlaskey@3 | 130 | |
jlaskey@3 | 131 | * @subtest - denotes necessary file for a main test file; itself is not |
jlaskey@3 | 132 | a test. |
jlaskey@3 | 133 | |
jlaskey@3 | 134 | * @run - A test that should be run is also tagged with @run (otherwise |
jlaskey@3 | 135 | the test runner only compiles the test). |
jlaskey@3 | 136 | |
jlaskey@3 | 137 | * @run/fail - A test that should compile but fail with a runtime error. |
jlaskey@3 | 138 | |
jlaskey@3 | 139 | * @run/ignore-std-error - script may produce output on stderr, ignore |
jlaskey@3 | 140 | this output. |
jlaskey@3 | 141 | |
jlaskey@3 | 142 | * @argument - pass an argument to script. |
jlaskey@3 | 143 | |
jlaskey@3 | 144 | * @option \ - pass option to engine, sample. |
jlaskey@3 | 145 | |
jlaskey@3 | 146 | /** |
jlaskey@3 | 147 | * @option --dump-ir-graph |
jlaskey@3 | 148 | * @test |
jlaskey@3 | 149 | */ |