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