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