test/script/trusted/JDK-8008305.js

Thu, 26 Sep 2013 10:43:59 -0700

author
cl
date
Thu, 26 Sep 2013 10:43:59 -0700
changeset 558
d1e2050e575e
parent 99
d5f74bd2dc20
child 560
a62172fe5bae
permissions
-rw-r--r--

Added tag jdk8-b109 for changeset 6ec2f9e5ed5b

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * 
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  * 
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  * 
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  * 
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /**
    25  * JDK-8008305: ScriptEngine.eval should offer the ability to provide a codebase *
    26  * @test
    27  * @run
    28  */
    30 var URLReader = Java.type("jdk.nashorn.api.scripting.URLReader");
    31 var File = Java.type("java.io.File");
    32 var FileReader = Java.type("java.io.FileReader");
    33 var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager");
    34 var SecurityException = Java.type("java.lang.SecurityException");
    36 var m = new ScriptEngineManager();
    37 var e = m.getEngineByName("nashorn");
    40 // subtest script file
    41 var scriptFile = new File(__DIR__ + "JDK-8008305_subtest.js");
    43 // evaluate the subtest via a URLReader
    44 var res = e.eval(new URLReader(scriptFile.toURI().toURL()));
    46 // subtest should execute with AllPermission and so return absolute path
    47 if (! res.equals(new File(".").getAbsolutePath())) {
    48     fail("eval result is not equal to expected value");
    49 }
    51 // try same subtest without URLReader and so it runs with null code source
    52 try {
    53     e.eval(new FileReader(scriptFile));
    54     fail("Expected SecurityException from script!");
    55 } catch (e) {
    56     if (! (e instanceof SecurityException)) {
    57         faile("Expected SecurityException, but got " + e);
    58     }
    59 }

mercurial