jlaskey@3: - What is Nashorn? jlaskey@3: jlaskey@3: Nashorn is a runtime environment for programs written in ECMAScript 5.1 jlaskey@3: that runs on top of JVM. jlaskey@3: jlaskey@3: - How to find out more about ECMAScript 5.1? jlaskey@3: jlaskey@3: The specification can be found at jlaskey@3: jlaskey@3: http://www.ecma-international.org/publications/standards/Ecma-262.htm jlaskey@3: jlaskey@3: - How to checkout sources of Nashorn project? jlaskey@3: jlaskey@3: Nashorn project uses Mercurial source code control system. You can jlaskey@3: download Mercurial from http://mercurial.selenic.com/wiki/Download jlaskey@3: jlaskey@3: Information about the forest extension can be found at jlaskey@3: jlaskey@3: http://mercurial.selenic.com/wiki/ForestExtension jlaskey@3: jlaskey@3: and downlaoded using jlaskey@3: jlaskey@3: hg clone https://bitbucket.org/gxti/hgforest jlaskey@3: jlaskey@3: You can clone Nashorn Mercurial forest using this command: jlaskey@3: jlaskey@3: hg fclone http://hg.openjdk.java.net/nashorn/jdk8 nashorn~jdk8 jlaskey@3: jlaskey@3: To update your copy of the forest (fwith the latest code: jlaskey@3: jlaskey@3: (cd nashorn~jdk8 ; hg fpull) jlaskey@3: jlaskey@3: Or just the nashorn subdirectory with jlaskey@3: jlaskey@3: (cd nashorn~jdk8/nashorn ; hg pull -u) jlaskey@3: jlaskey@3: To learn about Mercurial in detail, please visit http://hgbook.red-bean.com. jlaskey@3: jlaskey@3: - How to build? jlaskey@3: jlaskey@3: To build Nashorn, you need to install JDK 8. You may use the Nashorn jlaskey@3: forest build (recommended) or down load from java.net. You will need to jlaskey@3: set JAVA_HOME environmental variable to point to your JDK installation jlaskey@3: directory. jlaskey@3: jlaskey@3: cd nashorn~jdk8/nashorn/make jlaskey@3: ant clean; ant jlaskey@3: jlaskey@3: - How to run? jlaskey@3: jlaskey@3: Use the jjs script (see RELESE_README): jlaskey@3: jlaskey@3: cd nashorn~jdk8/nashorn jlaskey@3: sh bin/jjs jlaskey@3: jlaskey@3: Nashorn supports javax.script API. It is possible to drop nashorn.jar in jlaskey@3: class path and request for "nashorn" script engine from jlaskey@3: javax.script.ScriptEngineManager. jlaskey@3: jlaskey@3: Look for samples under the directory test/src/jdk/nashorn/api/scripting/. jlaskey@3: jlaskey@3: - Documentation jlaskey@3: jlaskey@3: Comprehensive development documentation is found in the Nashorn JavaDoc. You can jlaskey@3: build it using: jlaskey@3: jlaskey@3: cd nashorn~jdk8/nashorn/make jlaskey@3: ant javadoc jlaskey@3: jlaskey@3: after which you can view the generated documentation at dist/javadoc/index.html. jlaskey@3: jlaskey@3: - Running tests jlaskey@3: jlaskey@3: Nashorn tests are TestNG based. Running tests requires downloading the mhaupt@1391: TestNG library and placing its jar file into the test/lib subdirectory. This is mhaupt@1391: done automatically when executing the "ant externals" command to get external mhaupt@1391: test suites (see below). jlaskey@3: mhaupt@1391: Once TestNG is properly installed, you can run the tests using: jlaskey@3: cd make sundar@775: ant clean test jlaskey@3: jlaskey@3: You can also run the ECMA-262 test suite with Nashorn. In order to do jlaskey@3: that, you will need to get a copy of it and put it in jlaskey@3: test/script/external/test262 directory. A convenient way to do it is: jlaskey@3: sundar@775: git clone https://github.com/tc39/test262 test/script/external/test262 jlaskey@3: jlaskey@3: Alternatively, you can check it out elsewhere and make jlaskey@3: test/script/external/test262 a symbolic link to that directory. After jlaskey@3: you've done this, you can run the ECMA-262 tests using: jlaskey@3: jlaskey@3: cd nashorn~jdk8/nashorn/make jlaskey@3: ant test262 sundar@775: sundar@775: Ant target to get/update external test suites: sundar@775: sundar@775: ant externals sundar@775: ant update-externals jlaskey@3: jlaskey@3: These tests take time, so we have a parallelized runner for them that jlaskey@3: takes advantage of all processor cores on the computer: jlaskey@3: jlaskey@3: cd nashorn~jdk8/nashorn/make jlaskey@3: ant test262parallel jlaskey@3: jlaskey@3: - How to write your own test? jlaskey@3: jlaskey@3: Nashorn uses it's own simple test framework. Any .js file dropped under jlaskey@3: nashorn/test directory is considered as a test. A test file can jlaskey@3: optionally have .js.EXPECTED (foo.js.EXPECTED for foo.js) associated jlaskey@3: with it. The .EXPECTED file, if exists, should contain the output jlaskey@3: expected from compiling and/or running the test file. jlaskey@3: jlaskey@3: The test runner crawls these directories for .js files and looks for jlaskey@3: JTReg-style @foo comments to identify tests. jlaskey@3: jlaskey@3: * @test - A test is tagged with @test. jlaskey@3: jlaskey@3: * @test/fail - Tests that are supposed to fail (compiling, see @run/fail jlaskey@3: for runtime) are tagged with @test/fail. jlaskey@3: jlaskey@3: * @test/compile-error - Test expects compilation to fail, compares jlaskey@3: output. jlaskey@3: jlaskey@3: * @test/warning - Test expects compiler warnings, compares output. jlaskey@3: jlaskey@3: * @test/nocompare - Test expects to compile [and/or run?] jlaskey@3: successfully(may be warnings), does not compare output. jlaskey@3: jlaskey@3: * @subtest - denotes necessary file for a main test file; itself is not jlaskey@3: a test. jlaskey@3: jlaskey@3: * @run - A test that should be run is also tagged with @run (otherwise jlaskey@3: the test runner only compiles the test). jlaskey@3: jlaskey@3: * @run/fail - A test that should compile but fail with a runtime error. jlaskey@3: jlaskey@3: * @run/ignore-std-error - script may produce output on stderr, ignore jlaskey@3: this output. jlaskey@3: jlaskey@3: * @argument - pass an argument to script. jlaskey@3: jlaskey@3: * @option \ - pass option to engine, sample. jlaskey@3: jlaskey@3: /** jlaskey@3: * @option --dump-ir-graph jlaskey@3: * @test jlaskey@3: */