README

Thu, 31 Aug 2017 15:30:47 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:30:47 +0800
changeset 952
6d5471a497fb
parent 775
267e9e895282
parent 0
b1a7da25b547
child 1490
d85f981c8cf8
permissions
-rw-r--r--

merge

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

mercurial