nashorn/test/script/trusted/urlreader.js
author thartmann
Mon, 02 Jun 2014 08:07:29 +0200
changeset 24923 9631f7d691dc
parent 16522 d643e3ee819c
permissions -rw-r--r--
8034812: remove IDX_INIT macro hack in Node class Summary: The IDX_INIT macro used by Node::Node(...) to retrieve the Compile object is removed and replaced by a call to Compile::current(). The Node constructor, new operator and all calls to it are adapted accordingly. Reviewed-by: kvn, jrose, iveresov, goetz

/**
 * JDK-8008305: ScriptEngine.eval should offer the ability to provide a codebase
 *
 * @test
 * @run
 */

var URLReader = Java.type("jdk.nashorn.api.scripting.URLReader");
var URL = Java.type("java.net.URL");
var File = Java.type("java.io.File");
var JString = Java.type("java.lang.String");
var SourceHelper = Java.type("jdk.nashorn.test.models.SourceHelper");

var url = new File(__FILE__).toURI().toURL();
var reader = new URLReader(url);

// check URLReader.getURL() method
//Assert.assertEquals(url, reader.getURL());

// check URL read
// read URL content by directly reading from URL
var str = SourceHelper.readFully(url);
// read URL content via URLReader
var content = new JString(SourceHelper.readFully(reader));

// assert that the content is same
Assert.assertEquals(str, content);