8007715: Make sure that not all tests run with AllPermission

Thu, 07 Feb 2013 17:17:29 +0530

author
sundar
date
Thu, 07 Feb 2013 17:17:29 +0530
changeset 77
d7e83be6e7aa
parent 76
02f810c26ff9
child 78
bca3a64a4a82

8007715: Make sure that not all tests run with AllPermission
Reviewed-by: lagergren, attila

make/build.xml file | annotate | diff | comparison | revisions
make/project.properties file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/Context.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java file | annotate | diff | comparison | revisions
test/script/README file | annotate | diff | comparison | revisions
test/script/basic/JDK-8006424.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8006529.js file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-638.js file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-638.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-653.js file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-758.js file | annotate | diff | comparison | revisions
test/script/basic/getenv.js file | annotate | diff | comparison | revisions
test/script/basic/getenv.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/javaexceptions.js file | annotate | diff | comparison | revisions
test/script/basic/newexpr.js file | annotate | diff | comparison | revisions
test/script/sandbox/interfaceimpl.js file | annotate | diff | comparison | revisions
test/script/sandbox/loadcompat.js file | annotate | diff | comparison | revisions
test/script/trusted/JDK-8006424.js file | annotate | diff | comparison | revisions
test/script/trusted/JDK-8006529.js file | annotate | diff | comparison | revisions
test/script/trusted/NASHORN-638.js file | annotate | diff | comparison | revisions
test/script/trusted/NASHORN-638.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/trusted/NASHORN-653.js file | annotate | diff | comparison | revisions
test/script/trusted/README file | annotate | diff | comparison | revisions
test/script/trusted/getenv.js file | annotate | diff | comparison | revisions
test/script/trusted/getenv.js.EXPECTED file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/runtime/ContextTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/make/build.xml	Wed Feb 06 12:51:09 2013 -0400
     1.2 +++ b/make/build.xml	Thu Feb 07 17:17:29 2013 +0530
     1.3 @@ -198,25 +198,40 @@
     1.4             debug="${javac.debug}"
     1.5             encoding="${javac.encoding}"
     1.6             includeantruntime="false"/>
     1.7 +
     1.8 +    <!-- tests that check nashorn internals and internal API -->
     1.9 +    <jar jarfile="${nashorn.internal.tests.jar}">
    1.10 +      <fileset dir="${build.test.classes.dir}" excludes="**/api/scripting/*"/>
    1.11 +    </jar>
    1.12 +
    1.13 +    <!-- tests that check nashorn script engine (jsr-223) API -->
    1.14 +    <jar jarfile="${nashorn.api.tests.jar}">
    1.15 +      <fileset dir="${build.test.classes.dir}" includes="**/api/scripting/*"/>
    1.16 +    </jar>
    1.17 +
    1.18    </target>
    1.19  
    1.20    <target name="generate-policy-file">
    1.21      <!-- Generating nashorn.policy file -->
    1.22 -    <echo message="grant codeBase &quot;file:/${basedir}/dist/nashorn.jar&quot; {" file="${build.dir}/nashorn.policy"/>
    1.23 +
    1.24 +    <!-- nashorn internal tests jar requires AllPermission -->
    1.25 +    <echo message="grant codeBase &quot;file:/${basedir}/${nashorn.internal.tests.jar}&quot; {" file="${build.dir}/nashorn.policy"/>
    1.26      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.27 -    <echo message="permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    1.28 +    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    1.29      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.30      <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    1.31      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.32 -
    1.33 -    <echo message="grant codeBase &quot;file:/${basedir}/build/test/classes&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    1.34 +    
    1.35 +    <!-- TestNG framework jar needs AllPermission -->
    1.36 +    <echo message="grant codeBase &quot;file:/${basedir}/${file.reference.testng.jar}&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    1.37      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.38      <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    1.39      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.40      <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    1.41      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.42  
    1.43 -    <echo message="grant codeBase &quot;file:/${basedir}/${file.reference.testng.jar}&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    1.44 +    <!-- AllPermission to test/script/trusted tests -->
    1.45 +    <echo message="grant codeBase &quot;file:/${basedir}/test/script/trusted/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    1.46      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.47      <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    1.48      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.49 @@ -225,14 +240,11 @@
    1.50  
    1.51      <echo message="grant codeBase &quot;file:/${basedir}/test/script/basic/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    1.52      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.53 -    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    1.54 +    <!-- test/script/basic .js scripts load other script tests -->
    1.55 +    <echo message="    permission java.io.FilePermission &quot;${basedir}/test/script/-&quot;, &quot;read&quot;;" file="${build.dir}/nashorn.policy" append="true"/>
    1.56      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.57 -    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    1.58 -    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.59 -
    1.60 -    <echo message="grant codeBase &quot;file:/${basedir}/test/perf/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    1.61 -    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.62 -    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    1.63 +    <!-- test/script/basic .js scripts can read nashorn.test.* properties -->
    1.64 +    <echo message="    permission java.util.PropertyPermission &quot;nashorn.test.*&quot;, &quot;read&quot;;" file="${build.dir}/nashorn.policy" append="true"/>
    1.65      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    1.66      <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    1.67      <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
     2.1 --- a/make/project.properties	Wed Feb 06 12:51:09 2013 -0400
     2.2 +++ b/make/project.properties	Thu Feb 07 17:17:29 2013 +0530
     2.3 @@ -53,6 +53,10 @@
     2.4  
     2.5  # test classes directory
     2.6  build.test.classes.dir=${build.dir}/test/classes
     2.7 +# nashorn test jar - internal tests jar and api tests jar
     2.8 +nashorn.internal.tests.jar=${build.dir}/nashorn-internal-tests.jar
     2.9 +nashorn.api.tests.jar=${build.dir}/nashorn-api-tests.jar
    2.10 +
    2.11  # test results directory
    2.12  build.test.results.dir=${build.dir}/test/reports
    2.13  
    2.14 @@ -116,12 +120,13 @@
    2.15  test.basic.dir=test/script/basic
    2.16  test.error.dir=test/script/error
    2.17  test.sandbox.dir=test/script/sandbox
    2.18 +test.trusted.dir=test/script/trusted
    2.19  test.external.dir=test/script/external
    2.20  test262.dir=${test.external.dir}/test262
    2.21  test262.suite.dir=${test262.dir}/test/suite
    2.22  
    2.23  test-sys-prop.test.dir=${test.dir}
    2.24 -test-sys-prop.test.js.roots=${test.basic.dir} ${test.error.dir} ${test.sandbox.dir}
    2.25 +test-sys-prop.test.js.roots=${test.basic.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir}
    2.26  test-sys-prop.test262.suite.dir=${test262.suite.dir}
    2.27  test-sys-prop.es5conform.testcases.dir=${test.external.dir}/ES5Conform/TestCases
    2.28  test-sys-prop.test.basic.dir=${test.basic.dir}
    2.29 @@ -205,7 +210,9 @@
    2.30  
    2.31  run.test.classpath=\
    2.32      ${file.reference.testng.jar}:\
    2.33 -    ${build.test.classes.dir}
    2.34 +    ${nashorn.internal.tests.jar}:\
    2.35 +    ${nashorn.api.tests.jar}
    2.36 +
    2.37  src.dir=src
    2.38  test.src.dir=test/src
    2.39  
     3.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Wed Feb 06 12:51:09 2013 -0400
     3.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Thu Feb 07 17:17:29 2013 +0530
     3.3 @@ -607,24 +607,38 @@
     3.4          if (src instanceof String) {
     3.5              srcName = (String)src;
     3.6              final File file = new File((String)src);
     3.7 -            if (file.isFile()) {
     3.8 -                url = file.toURI().toURL();
     3.9 -            } else if (srcName.indexOf(':') != -1) {
    3.10 +            if (srcName.indexOf(':') != -1) {
    3.11                  try {
    3.12                      url = new URL((String)src);
    3.13                  } catch (final MalformedURLException e) {
    3.14                      // fallback URL - nashorn:foo.js - check under jdk/nashorn/internal/runtime/resources
    3.15 -                    String str = (String)src;
    3.16 +                    final String str = (String)src;
    3.17                      if (str.startsWith("nashorn:")) {
    3.18 -                        str = "resources/" + str.substring("nashorn:".length());
    3.19 -                        url = Context.class.getResource(str);
    3.20 -                        if (url == null) {
    3.21 +                        final String resource = "resources/" + str.substring("nashorn:".length());
    3.22 +                        // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
    3.23 +                        // These scripts are always available and are loaded from nashorn.jar's resources.
    3.24 +                        final Source code = AccessController.doPrivileged(
    3.25 +                                new PrivilegedAction<Source>() {
    3.26 +                                    @Override
    3.27 +                                    public Source run() {
    3.28 +                                        try {
    3.29 +                                            final URL resURL = Context.class.getResource(resource);
    3.30 +                                            return (resURL != null)? new Source(str, resURL) : null;
    3.31 +                                        } catch (final IOException exp) {
    3.32 +                                            return null;
    3.33 +                                        }
    3.34 +                                    }
    3.35 +                                });
    3.36 +                        if (code == null) {
    3.37                              throw e;
    3.38                          }
    3.39 +                        return evaluateSource(code, scope, scope);
    3.40                      } else {
    3.41                          throw e;
    3.42                      }
    3.43                  }
    3.44 +            } else if (file.isFile()) {
    3.45 +                url = file.toURI().toURL();
    3.46              }
    3.47              src = url;
    3.48          }
     4.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Wed Feb 06 12:51:09 2013 -0400
     4.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Thu Feb 07 17:17:29 2013 +0530
     4.3 @@ -456,6 +456,8 @@
     4.4      private static ClassLoader createClassLoader(final ClassLoader parentLoader, final String className,
     4.5              final byte[] classBytes, final String privilegedActionClassName) {
     4.6          return new AdapterLoader(parentLoader) {
     4.7 +            private final ProtectionDomain myProtectionDomain = getClass().getProtectionDomain();
     4.8 +
     4.9              @Override
    4.10              protected Class<?> findClass(final String name) throws ClassNotFoundException {
    4.11                  if(name.equals(className)) {
    4.12 @@ -463,7 +465,7 @@
    4.13                      return defineClass(name, bytes, 0, bytes.length, GENERATED_PROTECTION_DOMAIN);
    4.14                  } else if(name.equals(privilegedActionClassName)) {
    4.15                      final byte[] bytes = generatePrivilegedActionClassBytes(privilegedActionClassName.replace('.', '/'));
    4.16 -                    return defineClass(name, bytes, 0, bytes.length, getClass().getProtectionDomain());
    4.17 +                    return defineClass(name, bytes, 0, bytes.length, myProtectionDomain);
    4.18                  } else {
    4.19                      throw new ClassNotFoundException(name);
    4.20                  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/script/README	Thu Feb 07 17:17:29 2013 +0530
     5.3 @@ -0,0 +1,26 @@
     5.4 +basic:
     5.5 +
     5.6 +"basic" language and library tests. These need run only with File read 
     5.7 +permission to read files under "test/script" or subdirs and property read
     5.8 +permission to read properties named "nashorn.test.*"
     5.9 +
    5.10 +error:
    5.11 +
    5.12 +scripts that should result in compile-time error. The expected files check
    5.13 +for the error message format etc.
    5.14 +
    5.15 +currently-failing: 
    5.16 +
    5.17 +Tests that fail currently - but should pass eventually.
    5.18 +These are excluded for now.
    5.19 +
    5.20 +sandbox:
    5.21 +
    5.22 +Tests to check that sandbox scripts cannot access security sensitive resources.
    5.23 +Scripts under this directory run with no special permissions other than
    5.24 +what is given to all "sandbox" scripts.
    5.25 +
    5.26 +trusted:
    5.27 +
    5.28 +These tests run under AllPermission. Put only those scripts that really need
    5.29 +AllPermission - say for eg. creating class loader, full reflective access.
     6.1 --- a/test/script/basic/JDK-8006424.js	Wed Feb 06 12:51:09 2013 -0400
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,45 +0,0 @@
     6.4 -/*
     6.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     6.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 - * 
     6.8 - * This code is free software; you can redistribute it and/or modify it
     6.9 - * under the terms of the GNU General Public License version 2 only, as
    6.10 - * published by the Free Software Foundation.
    6.11 - * 
    6.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 - * version 2 for more details (a copy is included in the LICENSE file that
    6.16 - * accompanied this code).
    6.17 - * 
    6.18 - * You should have received a copy of the GNU General Public License version
    6.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 - * 
    6.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 - * or visit www.oracle.com if you need additional information or have any
    6.24 - * questions.
    6.25 - */
    6.26 -
    6.27 -/**
    6.28 - * JDK-8006424 : Passing null or undefined to adapter class constructors results in NPE or ClassCastException
    6.29 - *
    6.30 - * @test
    6.31 - * @run
    6.32 - */
    6.33 -
    6.34 -function check(callback) {
    6.35 -    try {
    6.36 -        callback();
    6.37 -        fail("should have thrown exception");
    6.38 -    } catch (e) {
    6.39 -        if (! (e instanceof TypeError)) {
    6.40 -            fail("TypeError expected, but got " + e);
    6.41 -        }
    6.42 -    }
    6.43 -}
    6.44 -
    6.45 -check(function() { new java.lang.ClassLoader(null) });
    6.46 -check(function() { new java.lang.ClassLoader(undefined) });
    6.47 -check(function() { new java.lang.Runnable(null) });
    6.48 -check(function() { new java.lang.Runnable(undefined) });
     7.1 --- a/test/script/basic/JDK-8006529.js	Wed Feb 06 12:51:09 2013 -0400
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,158 +0,0 @@
     7.4 -/*
     7.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     7.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 - * 
     7.8 - * This code is free software; you can redistribute it and/or modify it
     7.9 - * under the terms of the GNU General Public License version 2 only, as
    7.10 - * published by the Free Software Foundation.
    7.11 - * 
    7.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 - * version 2 for more details (a copy is included in the LICENSE file that
    7.16 - * accompanied this code).
    7.17 - * 
    7.18 - * You should have received a copy of the GNU General Public License version
    7.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 - * 
    7.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.23 - * or visit www.oracle.com if you need additional information or have any
    7.24 - * questions.
    7.25 - */
    7.26 -
    7.27 -/**
    7.28 - * JDK-8006529 : Methods should not always get callee parameter, and they
    7.29 - * should not be too eager in creation of scopes.
    7.30 - *
    7.31 - * @test
    7.32 - * @run
    7.33 - */
    7.34 -
    7.35 -// compile(script) -- compiles a script specified as a string with its 
    7.36 -// source code, returns a jdk.nashorn.internal.ir.FunctionNode object 
    7.37 -// representing it.
    7.38 -var compile = (function() {
    7.39 -    var Compiler       = Java.type("jdk.nashorn.internal.codegen.Compiler")
    7.40 -    var Context        = Java.type("jdk.nashorn.internal.runtime.Context")
    7.41 -    var Source         = Java.type("jdk.nashorn.internal.runtime.Source")
    7.42 -    var CompilerAccess = Java.type("jdk.nashorn.internal.codegen.CompilerAccess")
    7.43 -    return function(source) {
    7.44 -	    var compiler = Compiler.compiler(new Source("<no name>", source), Context.getContext())
    7.45 -        compiler.compile()
    7.46 -        return CompilerAccess.getScriptNode(compiler)
    7.47 -    }
    7.48 -})();
    7.49 -
    7.50 -var allAssertions = (function() {
    7.51 -    var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'varsInScope', 'isStrictMode']
    7.52 -    var allAssertions = {}
    7.53 -    for(var assertion in allAssertionList) {
    7.54 -        allAssertions[allAssertionList[assertion]] = true
    7.55 -    }
    7.56 -    return allAssertions;
    7.57 -})();
    7.58 -
    7.59 -// test(f[, assertions...]) tests whether all the specified assertions on the
    7.60 -// passed function node are true.
    7.61 -function test(f) {
    7.62 -    var assertions = {}
    7.63 -    for(var i = 1; i < arguments.length; ++i) {
    7.64 -        var assertion = arguments[i]
    7.65 -        if(!allAssertions[assertion]) {
    7.66 -            throw "Unknown assertion " + assertion + " for " + f;
    7.67 -        }
    7.68 -        assertions[assertion] = true
    7.69 -    }
    7.70 -    for(var assertion in allAssertions) {
    7.71 -        var expectedValue = !!assertions[assertion]
    7.72 -        if(f[assertion] == null) {
    7.73 -            throw "Can't find " + assertion + " on " + f;
    7.74 -        }
    7.75 -        if(f[assertion]() !== expectedValue) {
    7.76 -            throw "Expected " + assertion + " === " + expectedValue + " for " + f;
    7.77 -        }
    7.78 -    }
    7.79 -}
    7.80 -
    7.81 -// testFirstFn(script[, assertions...] tests whether all the specified
    7.82 -// assertions are true in the first function in the given script; "script"
    7.83 -// is a string with the source text of the script.
    7.84 -function testFirstFn(script) {
    7.85 -    arguments[0] = compile(script).functions[0]
    7.86 -    test.apply(null, arguments)
    7.87 -}
    7.88 -
    7.89 -// ---------------------------------- ACTUAL TESTS START HERE --------------
    7.90 -
    7.91 -// The simplest possible functions have no attributes set
    7.92 -testFirstFn("function f() { }")
    7.93 -testFirstFn("function f(x) { x }")
    7.94 -
    7.95 -// A function referencing a global needs parent scope, and it needs callee
    7.96 -// (because parent scope is passed through callee)
    7.97 -testFirstFn("function f() { x }", 'needsCallee', 'needsParentScope')
    7.98 -
    7.99 -// A function referencing "arguments" will have to be vararg. It also needs
   7.100 -// the callee, as it needs to fill out "arguments.callee".
   7.101 -testFirstFn("function f() { arguments }", 'needsCallee', 'isVarArg')
   7.102 -
   7.103 -// A function referencing "arguments" will have to be vararg. If it is
   7.104 -// strict, it will not have to have a callee, though.
   7.105 -testFirstFn("function f() {'use strict'; arguments }", 'isVarArg', 'isStrictMode')
   7.106 -
   7.107 -// A function defining "arguments" as a parameter will not be vararg.
   7.108 -testFirstFn("function f(arguments) { arguments }")
   7.109 -
   7.110 -// A function defining "arguments" as a nested function will not be vararg.
   7.111 -testFirstFn("function f() { function arguments() {}; arguments; }")
   7.112 -
   7.113 -// A function defining "arguments" as a local variable will be vararg.
   7.114 -testFirstFn("function f() { var arguments; arguments; }", 'isVarArg', 'needsCallee')
   7.115 -
   7.116 -// A self-referencing function defined as a statement doesn't need a self 
   7.117 -// symbol, as it'll rather obtain itself from the parent scope.
   7.118 -testFirstFn("function f() { f() }", 'needsCallee', 'needsParentScope')
   7.119 -
   7.120 -// A self-referencing function defined as an expression needs a self symbol,
   7.121 -// as it can't obtain itself from the parent scope.
   7.122 -testFirstFn("(function f() { f() })", 'needsCallee', 'needsSelfSymbol')
   7.123 -
   7.124 -// A child function accessing parent's variable triggers the need for scope
   7.125 -// in parent
   7.126 -testFirstFn("(function f() { var x; function g() { x } })", 'needsScope')
   7.127 -
   7.128 -// A child function accessing parent's parameter triggers the need for scope
   7.129 -// in parent
   7.130 -testFirstFn("(function f(x) { function g() { x } })", 'needsScope')
   7.131 -
   7.132 -// A child function accessing a global variable triggers the need for parent
   7.133 -// scope in parent
   7.134 -testFirstFn("(function f() { function g() { x } })", 'needsParentScope', 'needsCallee')
   7.135 -
   7.136 -// A child function redefining a local variable from its parent should not 
   7.137 -// affect the parent function in any way
   7.138 -testFirstFn("(function f() { var x; function g() { var x; x } })")
   7.139 -
   7.140 -// Using "with" unleashes a lot of needs: parent scope, callee, own scope, 
   7.141 -// and all variables in scope. Actually, we could make "with" less wasteful,
   7.142 -// and only put those variables in scope that it actually references, similar
   7.143 -// to what nested functions do with variables in their parents.
   7.144 -testFirstFn("(function f() { var o; with(o) {} })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasWith', 'hasDeepWithOrEval', 'varsInScope')
   7.145 -
   7.146 -// Using "eval" is as bad as using "with" with the added requirement of
   7.147 -// being vararg, 'cause we don't know if eval will be using "arguments".
   7.148 -testFirstFn("(function f() { eval() })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasEval', 'isVarArg', 'hasDeepWithOrEval', 'varsInScope')
   7.149 -
   7.150 -// Nested function using "with" is pretty much the same as the parent
   7.151 -// function needing with.
   7.152 -testFirstFn("(function f() { function g() { var o; with(o) {} } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
   7.153 -// Nested function using "eval" is almost the same as parent function using
   7.154 -// eval, but at least the parent doesn't have to be vararg.
   7.155 -testFirstFn("(function f() { function g() { eval() } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
   7.156 -
   7.157 -// Function with 250 named parameters is ordinary
   7.158 -testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250) { p250 = p249 }")
   7.159 -
   7.160 -// Function with 251 named parameters is variable arguments
   7.161 -testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251) { p250 = p251 }", 'isVarArg')
     8.1 --- a/test/script/basic/NASHORN-638.js	Wed Feb 06 12:51:09 2013 -0400
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,72 +0,0 @@
     8.4 -/*
     8.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     8.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 - * 
     8.8 - * This code is free software; you can redistribute it and/or modify it
     8.9 - * under the terms of the GNU General Public License version 2 only, as
    8.10 - * published by the Free Software Foundation.
    8.11 - * 
    8.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    8.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.15 - * version 2 for more details (a copy is included in the LICENSE file that
    8.16 - * accompanied this code).
    8.17 - * 
    8.18 - * You should have received a copy of the GNU General Public License version
    8.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    8.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.21 - * 
    8.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.23 - * or visit www.oracle.com if you need additional information or have any
    8.24 - * questions.
    8.25 - */
    8.26 -
    8.27 -/**
    8.28 - * NASHORN-638 : Callsite tracing and profiling are broken
    8.29 - *
    8.30 - * @test
    8.31 - * @run
    8.32 - */
    8.33 -
    8.34 -/*
    8.35 - * creates new script engine initialized with given options and
    8.36 - * runs given code on it. Returns standard output captured.
    8.37 - */
    8.38 -
    8.39 -function runScriptEngine(opts, code) {
    8.40 -    var imports = new JavaImporter(
    8.41 -        Packages.jdk.nashorn.api.scripting,
    8.42 -        java.io, java.lang, java.util);
    8.43 -
    8.44 -    with(imports) {
    8.45 -        var fac = new NashornScriptEngineFactory();
    8.46 -        // get current System.err
    8.47 -        var oldErr = System.err;
    8.48 -        var baos = new ByteArrayOutputStream();
    8.49 -        var newErr = new PrintStream(baos);
    8.50 -        try {
    8.51 -            // set new standard err
    8.52 -            System.setErr(newErr);
    8.53 -            var strType = Java.type("java.lang.String");
    8.54 -            var engine = fac.getScriptEngine(Java.toJavaArray(opts, strType));
    8.55 -            engine.eval(code);
    8.56 -            newErr.flush();
    8.57 -            return new java.lang.String(baos.toByteArray());
    8.58 -        } finally {
    8.59 -            // restore System.err to old value
    8.60 -            System.setErr(oldErr);
    8.61 -        }
    8.62 -    }
    8.63 -}
    8.64 -
    8.65 -var str = runScriptEngine([ "-tcs=all" ], "new Date");
    8.66 -print("hello, world!");
    8.67 -
    8.68 -if (str.indexOf(" ENTER ") == -1) {
    8.69 -    fail("expected 'ENTER' in trace mode output");
    8.70 -}
    8.71 -
    8.72 -if (str.indexOf(" EXIT ") == -1) {
    8.73 -    fail("expected 'EXIT' in trace mode output");
    8.74 -}
    8.75 -
     9.1 --- a/test/script/basic/NASHORN-638.js.EXPECTED	Wed Feb 06 12:51:09 2013 -0400
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,1 +0,0 @@
     9.4 -hello, world!
    10.1 --- a/test/script/basic/NASHORN-653.js	Wed Feb 06 12:51:09 2013 -0400
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,104 +0,0 @@
    10.4 -/*
    10.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    10.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 - * 
    10.8 - * This code is free software; you can redistribute it and/or modify it
    10.9 - * under the terms of the GNU General Public License version 2 only, as
   10.10 - * published by the Free Software Foundation.
   10.11 - * 
   10.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
   10.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.15 - * version 2 for more details (a copy is included in the LICENSE file that
   10.16 - * accompanied this code).
   10.17 - * 
   10.18 - * You should have received a copy of the GNU General Public License version
   10.19 - * 2 along with this work; if not, write to the Free Software Foundation,
   10.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.21 - * 
   10.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.23 - * or visit www.oracle.com if you need additional information or have any
   10.24 - * questions.
   10.25 - */
   10.26 -
   10.27 -/**
   10.28 - * NASHORN-653 : Various problems with isTerminal and dead code generation from ASM
   10.29 - *
   10.30 - * @test
   10.31 - * @run
   10.32 - */
   10.33 -
   10.34 -var script = "   \
   10.35 -function a() {   \
   10.36 -    return true; \
   10.37 -}                \
   10.38 -                 \
   10.39 -function b() {   \
   10.40 -    while (x) {      \
   10.41 -	return true; \
   10.42 -    }                \
   10.43 -}                    \
   10.44 -                     \
   10.45 -function c() {       \
   10.46 -    while (true) {   \
   10.47 -	return true; \
   10.48 -    }                \
   10.49 - }                   \
   10.50 -                     \
   10.51 -function d() {       \
   10.52 -    do {             \
   10.53 -	return true; \
   10.54 -    } while (x);     \
   10.55 -} \
   10.56 -\
   10.57 -function f() {       \
   10.58 -    for (;;) {       \
   10.59 -	return true; \
   10.60 -    } \
   10.61 -} \
   10.62 -\
   10.63 -function e() { \
   10.64 -    for (;;) { \
   10.65 -	return true; \
   10.66 -    } \
   10.67 -} \
   10.68 -\
   10.69 -function g() { \
   10.70 -    for(;;) { \
   10.71 -	print('goes on and on and on ... '); \
   10.72 -    } \
   10.73 -    print('x'); \
   10.74 -} \
   10.75 -";
   10.76 -
   10.77 -function runScriptEngine(opts, code) {
   10.78 -    var imports = new JavaImporter(
   10.79 -        Packages.jdk.nashorn.api.scripting,
   10.80 -        java.io, java.lang, java.util);
   10.81 -
   10.82 -    with(imports) {
   10.83 -        var fac = new NashornScriptEngineFactory();
   10.84 -        // get current System.err
   10.85 -        var oldErr = System.err;
   10.86 -        var baos = new ByteArrayOutputStream();
   10.87 -        var newErr = new PrintStream(baos);
   10.88 -        try {
   10.89 -            // set new standard err
   10.90 -            System.setErr(newErr);
   10.91 -            var strType = Java.type("java.lang.String");
   10.92 -            var engine = fac.getScriptEngine(Java.toJavaArray(opts, strType));
   10.93 -            engine.eval(code);
   10.94 -            newErr.flush();
   10.95 -            return new java.lang.String(baos.toByteArray());
   10.96 -        } finally {
   10.97 -            // restore System.err to old value
   10.98 -            System.setErr(oldErr);
   10.99 -        }
  10.100 -    }
  10.101 -}
  10.102 -
  10.103 -var result = runScriptEngine([ "--print-code" ], script);
  10.104 -
  10.105 -if (result.indexOf("NOP") != -1) {
  10.106 -    fail("ASM genenerates NOP*/ATHROW sequences - dead code is still in the script");
  10.107 -}
    11.1 --- a/test/script/basic/NASHORN-758.js	Wed Feb 06 12:51:09 2013 -0400
    11.2 +++ b/test/script/basic/NASHORN-758.js	Thu Feb 07 17:17:29 2013 +0530
    11.3 @@ -25,16 +25,16 @@
    11.4   * NASHORN-758 : nashorn shell command line options improvements
    11.5   *
    11.6   * @test
    11.7 - * @option -Dfoo=bar
    11.8 - * @option -Dhello=world
    11.9 + * @option -Dnashorn.test.foo=bar
   11.10 + * @option -Dnashorn.test.hello=world
   11.11   * @run
   11.12   */
   11.13  
   11.14  
   11.15 -if (java.lang.System.getProperty("foo") != "bar") {
   11.16 -    fail("System property 'foo' != 'bar'");
   11.17 +if (java.lang.System.getProperty("nashorn.test.foo") != "bar") {
   11.18 +    fail("System property 'nashorn.test.foo' != 'bar'");
   11.19  }
   11.20  
   11.21 -if (java.lang.System.getProperty("hello") != "world") {
   11.22 -    fail("System property 'hello' != 'world'");
   11.23 +if (java.lang.System.getProperty("nashorn.test.hello") != "world") {
   11.24 +    fail("System property 'nashorn.test.hello' != 'world'");
   11.25  }
    12.1 --- a/test/script/basic/getenv.js	Wed Feb 06 12:51:09 2013 -0400
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,31 +0,0 @@
    12.4 -/*
    12.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    12.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.7 - * 
    12.8 - * This code is free software; you can redistribute it and/or modify it
    12.9 - * under the terms of the GNU General Public License version 2 only, as
   12.10 - * published by the Free Software Foundation.
   12.11 - * 
   12.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
   12.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.15 - * version 2 for more details (a copy is included in the LICENSE file that
   12.16 - * accompanied this code).
   12.17 - * 
   12.18 - * You should have received a copy of the GNU General Public License version
   12.19 - * 2 along with this work; if not, write to the Free Software Foundation,
   12.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   12.21 - * 
   12.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   12.23 - * or visit www.oracle.com if you need additional information or have any
   12.24 - * questions.
   12.25 - */
   12.26 -
   12.27 -/**
   12.28 - * Verifies Map methods do not generate NPE
   12.29 - *
   12.30 - * @test
   12.31 - * @run
   12.32 - */
   12.33 -
   12.34 -print(java.lang.System.getenv().isEmpty());
    13.1 --- a/test/script/basic/getenv.js.EXPECTED	Wed Feb 06 12:51:09 2013 -0400
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,1 +0,0 @@
    13.4 -false
    14.1 --- a/test/script/basic/javaexceptions.js	Wed Feb 06 12:51:09 2013 -0400
    14.2 +++ b/test/script/basic/javaexceptions.js	Thu Feb 07 17:17:29 2013 +0530
    14.3 @@ -31,7 +31,7 @@
    14.4  try {
    14.5      new java.io.FileInputStream("non_existent_file");
    14.6  } catch (e) {
    14.7 -    print(e instanceof java.io.FileNotFoundException);
    14.8 +    print(e instanceof java.io.FileNotFoundException || e instanceof java.lang.SecurityException);
    14.9  }
   14.10  
   14.11  try {
    15.1 --- a/test/script/basic/newexpr.js	Wed Feb 06 12:51:09 2013 -0400
    15.2 +++ b/test/script/basic/newexpr.js	Thu Feb 07 17:17:29 2013 +0530
    15.3 @@ -29,7 +29,7 @@
    15.4   */
    15.5  
    15.6  var File = java.io.File;
    15.7 -print(new File(".").isDirectory());
    15.8 +print(! new File(".").toString().isEmpty());
    15.9  
   15.10  var obj = {
   15.11     foo : function (x) {
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/script/sandbox/interfaceimpl.js	Thu Feb 07 17:17:29 2013 +0530
    16.3 @@ -0,0 +1,63 @@
    16.4 +/*
    16.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 + * 
    16.8 + * This code is free software; you can redistribute it and/or modify it
    16.9 + * under the terms of the GNU General Public License version 2 only, as
   16.10 + * published by the Free Software Foundation.
   16.11 + * 
   16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.15 + * version 2 for more details (a copy is included in the LICENSE file that
   16.16 + * accompanied this code).
   16.17 + * 
   16.18 + * You should have received a copy of the GNU General Public License version
   16.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.21 + * 
   16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   16.23 + * or visit www.oracle.com if you need additional information or have any
   16.24 + * questions.
   16.25 + */
   16.26 +
   16.27 +/**
   16.28 + * Check that user defined interface can be implemented.
   16.29 + *
   16.30 + * @test
   16.31 + * @run
   16.32 + * @security
   16.33 + */
   16.34 +
   16.35 +var Window = Java.type("jdk.nashorn.api.scripting.Window");
   16.36 +var WindowEventHandler = Java.type("jdk.nashorn.api.scripting.WindowEventHandler");
   16.37 +
   16.38 +var w = new Window();
   16.39 +
   16.40 +var loadedFuncReached = false;
   16.41 +// try function to SAM converter
   16.42 +w.onload = function() {
   16.43 +    loadedFuncReached = true;
   16.44 +    return true;
   16.45 +}
   16.46 +
   16.47 +w.onload.loaded();
   16.48 +if (! loadedFuncReached) {
   16.49 +    fail("Interface method impl. not called");
   16.50 +}
   16.51 +
   16.52 +// reset
   16.53 +loadedFuncReached = false;
   16.54 +
   16.55 +// try direct interface implementation
   16.56 +w.onload = new WindowEventHandler() {
   16.57 +    loaded: function() {
   16.58 +        loadedFuncReached = true;
   16.59 +        return true;
   16.60 +    }
   16.61 +};
   16.62 +
   16.63 +w.onload.loaded();
   16.64 +if (! loadedFuncReached) {
   16.65 +    fail("Interface method impl. not called");
   16.66 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/script/sandbox/loadcompat.js	Thu Feb 07 17:17:29 2013 +0530
    17.3 @@ -0,0 +1,50 @@
    17.4 +/*
    17.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 + * 
    17.8 + * This code is free software; you can redistribute it and/or modify it
    17.9 + * under the terms of the GNU General Public License version 2 only, as
   17.10 + * published by the Free Software Foundation.
   17.11 + * 
   17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.15 + * version 2 for more details (a copy is included in the LICENSE file that
   17.16 + * accompanied this code).
   17.17 + * 
   17.18 + * You should have received a copy of the GNU General Public License version
   17.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.21 + * 
   17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   17.23 + * or visit www.oracle.com if you need additional information or have any
   17.24 + * questions.
   17.25 + */
   17.26 +
   17.27 +/**
   17.28 + * Check that nashorn mozilla compatibility script can be loaded in sandbox.
   17.29 + *
   17.30 + * @test
   17.31 + * @run
   17.32 + * @security
   17.33 + */
   17.34 +
   17.35 +load("nashorn:mozilla_compat.js");
   17.36 +
   17.37 +var obj = {};
   17.38 +if (obj.__proto__ !== Object.prototype) {
   17.39 +    fail("__proto__ does not work as expected");
   17.40 +}
   17.41 +
   17.42 +var array = [];
   17.43 +if (array.__proto__ !== Array.prototype) {
   17.44 +    fail("__proto__ does not work as expected");
   17.45 +}
   17.46 +
   17.47 +if (typeof JavaAdapter != 'function') {
   17.48 +    fail("JavaAdapter constructor is missing in compatibility script");
   17.49 +}
   17.50 +
   17.51 +if (typeof importPackage != 'function') {
   17.52 +    fail("importPackage function is missing in compatibility script");
   17.53 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/test/script/trusted/JDK-8006424.js	Thu Feb 07 17:17:29 2013 +0530
    18.3 @@ -0,0 +1,45 @@
    18.4 +/*
    18.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.7 + * 
    18.8 + * This code is free software; you can redistribute it and/or modify it
    18.9 + * under the terms of the GNU General Public License version 2 only, as
   18.10 + * published by the Free Software Foundation.
   18.11 + * 
   18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   18.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18.15 + * version 2 for more details (a copy is included in the LICENSE file that
   18.16 + * accompanied this code).
   18.17 + * 
   18.18 + * You should have received a copy of the GNU General Public License version
   18.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18.21 + * 
   18.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   18.23 + * or visit www.oracle.com if you need additional information or have any
   18.24 + * questions.
   18.25 + */
   18.26 +
   18.27 +/**
   18.28 + * JDK-8006424 : Passing null or undefined to adapter class constructors results in NPE or ClassCastException
   18.29 + *
   18.30 + * @test
   18.31 + * @run
   18.32 + */
   18.33 +
   18.34 +function check(callback) {
   18.35 +    try {
   18.36 +        callback();
   18.37 +        fail("should have thrown exception");
   18.38 +    } catch (e) {
   18.39 +        if (! (e instanceof TypeError)) {
   18.40 +            fail("TypeError expected, but got " + e);
   18.41 +        }
   18.42 +    }
   18.43 +}
   18.44 +
   18.45 +check(function() { new java.lang.ClassLoader(null) });
   18.46 +check(function() { new java.lang.ClassLoader(undefined) });
   18.47 +check(function() { new java.lang.Runnable(null) });
   18.48 +check(function() { new java.lang.Runnable(undefined) });
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/test/script/trusted/JDK-8006529.js	Thu Feb 07 17:17:29 2013 +0530
    19.3 @@ -0,0 +1,158 @@
    19.4 +/*
    19.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    19.7 + * 
    19.8 + * This code is free software; you can redistribute it and/or modify it
    19.9 + * under the terms of the GNU General Public License version 2 only, as
   19.10 + * published by the Free Software Foundation.
   19.11 + * 
   19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   19.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   19.15 + * version 2 for more details (a copy is included in the LICENSE file that
   19.16 + * accompanied this code).
   19.17 + * 
   19.18 + * You should have received a copy of the GNU General Public License version
   19.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   19.21 + * 
   19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   19.23 + * or visit www.oracle.com if you need additional information or have any
   19.24 + * questions.
   19.25 + */
   19.26 +
   19.27 +/**
   19.28 + * JDK-8006529 : Methods should not always get callee parameter, and they
   19.29 + * should not be too eager in creation of scopes.
   19.30 + *
   19.31 + * @test
   19.32 + * @run
   19.33 + */
   19.34 +
   19.35 +// compile(script) -- compiles a script specified as a string with its 
   19.36 +// source code, returns a jdk.nashorn.internal.ir.FunctionNode object 
   19.37 +// representing it.
   19.38 +var compile = (function() {
   19.39 +    var Compiler       = Java.type("jdk.nashorn.internal.codegen.Compiler")
   19.40 +    var Context        = Java.type("jdk.nashorn.internal.runtime.Context")
   19.41 +    var Source         = Java.type("jdk.nashorn.internal.runtime.Source")
   19.42 +    var CompilerAccess = Java.type("jdk.nashorn.internal.codegen.CompilerAccess")
   19.43 +    return function(source) {
   19.44 +	    var compiler = Compiler.compiler(new Source("<no name>", source), Context.getContext())
   19.45 +        compiler.compile()
   19.46 +        return CompilerAccess.getScriptNode(compiler)
   19.47 +    }
   19.48 +})();
   19.49 +
   19.50 +var allAssertions = (function() {
   19.51 +    var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'varsInScope', 'isStrictMode']
   19.52 +    var allAssertions = {}
   19.53 +    for(var assertion in allAssertionList) {
   19.54 +        allAssertions[allAssertionList[assertion]] = true
   19.55 +    }
   19.56 +    return allAssertions;
   19.57 +})();
   19.58 +
   19.59 +// test(f[, assertions...]) tests whether all the specified assertions on the
   19.60 +// passed function node are true.
   19.61 +function test(f) {
   19.62 +    var assertions = {}
   19.63 +    for(var i = 1; i < arguments.length; ++i) {
   19.64 +        var assertion = arguments[i]
   19.65 +        if(!allAssertions[assertion]) {
   19.66 +            throw "Unknown assertion " + assertion + " for " + f;
   19.67 +        }
   19.68 +        assertions[assertion] = true
   19.69 +    }
   19.70 +    for(var assertion in allAssertions) {
   19.71 +        var expectedValue = !!assertions[assertion]
   19.72 +        if(f[assertion] == null) {
   19.73 +            throw "Can't find " + assertion + " on " + f;
   19.74 +        }
   19.75 +        if(f[assertion]() !== expectedValue) {
   19.76 +            throw "Expected " + assertion + " === " + expectedValue + " for " + f;
   19.77 +        }
   19.78 +    }
   19.79 +}
   19.80 +
   19.81 +// testFirstFn(script[, assertions...] tests whether all the specified
   19.82 +// assertions are true in the first function in the given script; "script"
   19.83 +// is a string with the source text of the script.
   19.84 +function testFirstFn(script) {
   19.85 +    arguments[0] = compile(script).functions[0]
   19.86 +    test.apply(null, arguments)
   19.87 +}
   19.88 +
   19.89 +// ---------------------------------- ACTUAL TESTS START HERE --------------
   19.90 +
   19.91 +// The simplest possible functions have no attributes set
   19.92 +testFirstFn("function f() { }")
   19.93 +testFirstFn("function f(x) { x }")
   19.94 +
   19.95 +// A function referencing a global needs parent scope, and it needs callee
   19.96 +// (because parent scope is passed through callee)
   19.97 +testFirstFn("function f() { x }", 'needsCallee', 'needsParentScope')
   19.98 +
   19.99 +// A function referencing "arguments" will have to be vararg. It also needs
  19.100 +// the callee, as it needs to fill out "arguments.callee".
  19.101 +testFirstFn("function f() { arguments }", 'needsCallee', 'isVarArg')
  19.102 +
  19.103 +// A function referencing "arguments" will have to be vararg. If it is
  19.104 +// strict, it will not have to have a callee, though.
  19.105 +testFirstFn("function f() {'use strict'; arguments }", 'isVarArg', 'isStrictMode')
  19.106 +
  19.107 +// A function defining "arguments" as a parameter will not be vararg.
  19.108 +testFirstFn("function f(arguments) { arguments }")
  19.109 +
  19.110 +// A function defining "arguments" as a nested function will not be vararg.
  19.111 +testFirstFn("function f() { function arguments() {}; arguments; }")
  19.112 +
  19.113 +// A function defining "arguments" as a local variable will be vararg.
  19.114 +testFirstFn("function f() { var arguments; arguments; }", 'isVarArg', 'needsCallee')
  19.115 +
  19.116 +// A self-referencing function defined as a statement doesn't need a self 
  19.117 +// symbol, as it'll rather obtain itself from the parent scope.
  19.118 +testFirstFn("function f() { f() }", 'needsCallee', 'needsParentScope')
  19.119 +
  19.120 +// A self-referencing function defined as an expression needs a self symbol,
  19.121 +// as it can't obtain itself from the parent scope.
  19.122 +testFirstFn("(function f() { f() })", 'needsCallee', 'needsSelfSymbol')
  19.123 +
  19.124 +// A child function accessing parent's variable triggers the need for scope
  19.125 +// in parent
  19.126 +testFirstFn("(function f() { var x; function g() { x } })", 'needsScope')
  19.127 +
  19.128 +// A child function accessing parent's parameter triggers the need for scope
  19.129 +// in parent
  19.130 +testFirstFn("(function f(x) { function g() { x } })", 'needsScope')
  19.131 +
  19.132 +// A child function accessing a global variable triggers the need for parent
  19.133 +// scope in parent
  19.134 +testFirstFn("(function f() { function g() { x } })", 'needsParentScope', 'needsCallee')
  19.135 +
  19.136 +// A child function redefining a local variable from its parent should not 
  19.137 +// affect the parent function in any way
  19.138 +testFirstFn("(function f() { var x; function g() { var x; x } })")
  19.139 +
  19.140 +// Using "with" unleashes a lot of needs: parent scope, callee, own scope, 
  19.141 +// and all variables in scope. Actually, we could make "with" less wasteful,
  19.142 +// and only put those variables in scope that it actually references, similar
  19.143 +// to what nested functions do with variables in their parents.
  19.144 +testFirstFn("(function f() { var o; with(o) {} })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasWith', 'hasDeepWithOrEval', 'varsInScope')
  19.145 +
  19.146 +// Using "eval" is as bad as using "with" with the added requirement of
  19.147 +// being vararg, 'cause we don't know if eval will be using "arguments".
  19.148 +testFirstFn("(function f() { eval() })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasEval', 'isVarArg', 'hasDeepWithOrEval', 'varsInScope')
  19.149 +
  19.150 +// Nested function using "with" is pretty much the same as the parent
  19.151 +// function needing with.
  19.152 +testFirstFn("(function f() { function g() { var o; with(o) {} } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
  19.153 +// Nested function using "eval" is almost the same as parent function using
  19.154 +// eval, but at least the parent doesn't have to be vararg.
  19.155 +testFirstFn("(function f() { function g() { eval() } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
  19.156 +
  19.157 +// Function with 250 named parameters is ordinary
  19.158 +testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250) { p250 = p249 }")
  19.159 +
  19.160 +// Function with 251 named parameters is variable arguments
  19.161 +testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251) { p250 = p251 }", 'isVarArg')
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/test/script/trusted/NASHORN-638.js	Thu Feb 07 17:17:29 2013 +0530
    20.3 @@ -0,0 +1,72 @@
    20.4 +/*
    20.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    20.7 + * 
    20.8 + * This code is free software; you can redistribute it and/or modify it
    20.9 + * under the terms of the GNU General Public License version 2 only, as
   20.10 + * published by the Free Software Foundation.
   20.11 + * 
   20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   20.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   20.15 + * version 2 for more details (a copy is included in the LICENSE file that
   20.16 + * accompanied this code).
   20.17 + * 
   20.18 + * You should have received a copy of the GNU General Public License version
   20.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20.21 + * 
   20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   20.23 + * or visit www.oracle.com if you need additional information or have any
   20.24 + * questions.
   20.25 + */
   20.26 +
   20.27 +/**
   20.28 + * NASHORN-638 : Callsite tracing and profiling are broken
   20.29 + *
   20.30 + * @test
   20.31 + * @run
   20.32 + */
   20.33 +
   20.34 +/*
   20.35 + * creates new script engine initialized with given options and
   20.36 + * runs given code on it. Returns standard output captured.
   20.37 + */
   20.38 +
   20.39 +function runScriptEngine(opts, code) {
   20.40 +    var imports = new JavaImporter(
   20.41 +        Packages.jdk.nashorn.api.scripting,
   20.42 +        java.io, java.lang, java.util);
   20.43 +
   20.44 +    with(imports) {
   20.45 +        var fac = new NashornScriptEngineFactory();
   20.46 +        // get current System.err
   20.47 +        var oldErr = System.err;
   20.48 +        var baos = new ByteArrayOutputStream();
   20.49 +        var newErr = new PrintStream(baos);
   20.50 +        try {
   20.51 +            // set new standard err
   20.52 +            System.setErr(newErr);
   20.53 +            var strType = Java.type("java.lang.String");
   20.54 +            var engine = fac.getScriptEngine(Java.toJavaArray(opts, strType));
   20.55 +            engine.eval(code);
   20.56 +            newErr.flush();
   20.57 +            return new java.lang.String(baos.toByteArray());
   20.58 +        } finally {
   20.59 +            // restore System.err to old value
   20.60 +            System.setErr(oldErr);
   20.61 +        }
   20.62 +    }
   20.63 +}
   20.64 +
   20.65 +var str = runScriptEngine([ "-tcs=all" ], "new Date");
   20.66 +print("hello, world!");
   20.67 +
   20.68 +if (str.indexOf(" ENTER ") == -1) {
   20.69 +    fail("expected 'ENTER' in trace mode output");
   20.70 +}
   20.71 +
   20.72 +if (str.indexOf(" EXIT ") == -1) {
   20.73 +    fail("expected 'EXIT' in trace mode output");
   20.74 +}
   20.75 +
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/test/script/trusted/NASHORN-638.js.EXPECTED	Thu Feb 07 17:17:29 2013 +0530
    21.3 @@ -0,0 +1,1 @@
    21.4 +hello, world!
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/test/script/trusted/NASHORN-653.js	Thu Feb 07 17:17:29 2013 +0530
    22.3 @@ -0,0 +1,104 @@
    22.4 +/*
    22.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    22.7 + * 
    22.8 + * This code is free software; you can redistribute it and/or modify it
    22.9 + * under the terms of the GNU General Public License version 2 only, as
   22.10 + * published by the Free Software Foundation.
   22.11 + * 
   22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   22.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   22.15 + * version 2 for more details (a copy is included in the LICENSE file that
   22.16 + * accompanied this code).
   22.17 + * 
   22.18 + * You should have received a copy of the GNU General Public License version
   22.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   22.21 + * 
   22.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22.23 + * or visit www.oracle.com if you need additional information or have any
   22.24 + * questions.
   22.25 + */
   22.26 +
   22.27 +/**
   22.28 + * NASHORN-653 : Various problems with isTerminal and dead code generation from ASM
   22.29 + *
   22.30 + * @test
   22.31 + * @run
   22.32 + */
   22.33 +
   22.34 +var script = "   \
   22.35 +function a() {   \
   22.36 +    return true; \
   22.37 +}                \
   22.38 +                 \
   22.39 +function b() {   \
   22.40 +    while (x) {      \
   22.41 +	return true; \
   22.42 +    }                \
   22.43 +}                    \
   22.44 +                     \
   22.45 +function c() {       \
   22.46 +    while (true) {   \
   22.47 +	return true; \
   22.48 +    }                \
   22.49 + }                   \
   22.50 +                     \
   22.51 +function d() {       \
   22.52 +    do {             \
   22.53 +	return true; \
   22.54 +    } while (x);     \
   22.55 +} \
   22.56 +\
   22.57 +function f() {       \
   22.58 +    for (;;) {       \
   22.59 +	return true; \
   22.60 +    } \
   22.61 +} \
   22.62 +\
   22.63 +function e() { \
   22.64 +    for (;;) { \
   22.65 +	return true; \
   22.66 +    } \
   22.67 +} \
   22.68 +\
   22.69 +function g() { \
   22.70 +    for(;;) { \
   22.71 +	print('goes on and on and on ... '); \
   22.72 +    } \
   22.73 +    print('x'); \
   22.74 +} \
   22.75 +";
   22.76 +
   22.77 +function runScriptEngine(opts, code) {
   22.78 +    var imports = new JavaImporter(
   22.79 +        Packages.jdk.nashorn.api.scripting,
   22.80 +        java.io, java.lang, java.util);
   22.81 +
   22.82 +    with(imports) {
   22.83 +        var fac = new NashornScriptEngineFactory();
   22.84 +        // get current System.err
   22.85 +        var oldErr = System.err;
   22.86 +        var baos = new ByteArrayOutputStream();
   22.87 +        var newErr = new PrintStream(baos);
   22.88 +        try {
   22.89 +            // set new standard err
   22.90 +            System.setErr(newErr);
   22.91 +            var strType = Java.type("java.lang.String");
   22.92 +            var engine = fac.getScriptEngine(Java.toJavaArray(opts, strType));
   22.93 +            engine.eval(code);
   22.94 +            newErr.flush();
   22.95 +            return new java.lang.String(baos.toByteArray());
   22.96 +        } finally {
   22.97 +            // restore System.err to old value
   22.98 +            System.setErr(oldErr);
   22.99 +        }
  22.100 +    }
  22.101 +}
  22.102 +
  22.103 +var result = runScriptEngine([ "--print-code" ], script);
  22.104 +
  22.105 +if (result.indexOf("NOP") != -1) {
  22.106 +    fail("ASM genenerates NOP*/ATHROW sequences - dead code is still in the script");
  22.107 +}
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/test/script/trusted/README	Thu Feb 07 17:17:29 2013 +0530
    23.3 @@ -0,0 +1,4 @@
    23.4 +This directory contains tests that need AllPermission to run.
    23.5 +
    23.6 +Scripts that need to create classloaders, need to reflectively access
    23.7 +declared members of other classes etc. should go here.
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/test/script/trusted/getenv.js	Thu Feb 07 17:17:29 2013 +0530
    24.3 @@ -0,0 +1,31 @@
    24.4 +/*
    24.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    24.7 + * 
    24.8 + * This code is free software; you can redistribute it and/or modify it
    24.9 + * under the terms of the GNU General Public License version 2 only, as
   24.10 + * published by the Free Software Foundation.
   24.11 + * 
   24.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   24.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   24.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   24.15 + * version 2 for more details (a copy is included in the LICENSE file that
   24.16 + * accompanied this code).
   24.17 + * 
   24.18 + * You should have received a copy of the GNU General Public License version
   24.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   24.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   24.21 + * 
   24.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   24.23 + * or visit www.oracle.com if you need additional information or have any
   24.24 + * questions.
   24.25 + */
   24.26 +
   24.27 +/**
   24.28 + * Verifies Map methods do not generate NPE
   24.29 + *
   24.30 + * @test
   24.31 + * @run
   24.32 + */
   24.33 +
   24.34 +print(java.lang.System.getenv().isEmpty());
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/test/script/trusted/getenv.js.EXPECTED	Thu Feb 07 17:17:29 2013 +0530
    25.3 @@ -0,0 +1,1 @@
    25.4 +false
    26.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Wed Feb 06 12:51:09 2013 -0400
    26.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Thu Feb 07 17:17:29 2013 +0530
    26.3 @@ -972,46 +972,6 @@
    26.4          }
    26.5      }
    26.6  
    26.7 -    private static class MyClassLoader extends ClassLoader {
    26.8 -        // to check if script engine uses the specified class loader
    26.9 -        private final boolean[] reached = new boolean[1];
   26.10 -
   26.11 -        @Override
   26.12 -        protected Class findClass(final String name) throws ClassNotFoundException {
   26.13 -            // flag that it reached here
   26.14 -            reached[0] = true;
   26.15 -            return super.findClass(name);
   26.16 -        }
   26.17 -
   26.18 -        public boolean reached() {
   26.19 -            return reached[0];
   26.20 -        }
   26.21 -    };
   26.22 -
   26.23 -    @Test
   26.24 -    public void factoryClassLoaderTest() {
   26.25 -        final ScriptEngineManager sm = new ScriptEngineManager();
   26.26 -        for (ScriptEngineFactory fac : sm.getEngineFactories()) {
   26.27 -            if (fac instanceof NashornScriptEngineFactory) {
   26.28 -                final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
   26.29 -                final MyClassLoader loader = new MyClassLoader();
   26.30 -                // set the classloader as app class loader
   26.31 -                final ScriptEngine e = nfac.getScriptEngine(loader);
   26.32 -                try {
   26.33 -                    e.eval("Packages.foo");
   26.34 -                    // check that the class loader was attempted
   26.35 -                    assertTrue(loader.reached(), "did not reach class loader!");
   26.36 -                } catch (final ScriptException se) {
   26.37 -                    se.printStackTrace();
   26.38 -                    fail(se.getMessage());
   26.39 -                }
   26.40 -                return;
   26.41 -            }
   26.42 -        }
   26.43 -
   26.44 -        fail("Cannot find nashorn factory!");
   26.45 -    }
   26.46 -
   26.47      @Test
   26.48      public void factoryOptionsTest() {
   26.49          final ScriptEngineManager sm = new ScriptEngineManager();
   26.50 @@ -1033,38 +993,4 @@
   26.51  
   26.52          fail("Cannot find nashorn factory!");
   26.53      }
   26.54 -
   26.55 -    @Test
   26.56 -    public void factoryClassLoaderAndOptionsTest() {
   26.57 -        final ScriptEngineManager sm = new ScriptEngineManager();
   26.58 -        for (ScriptEngineFactory fac : sm.getEngineFactories()) {
   26.59 -            if (fac instanceof NashornScriptEngineFactory) {
   26.60 -                final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
   26.61 -                final String[] options = new String[] { "-strict" };
   26.62 -                final MyClassLoader loader = new MyClassLoader();
   26.63 -                // set the classloader as app class loader
   26.64 -                final ScriptEngine e = nfac.getScriptEngine(options, loader);
   26.65 -                try {
   26.66 -                    e.eval("Packages.foo");
   26.67 -                    // check that the class loader was attempted
   26.68 -                    assertTrue(loader.reached(), "did not reach class loader!");
   26.69 -                } catch (final ScriptException se) {
   26.70 -                    se.printStackTrace();
   26.71 -                    fail(se.getMessage());
   26.72 -                }
   26.73 -
   26.74 -                try {
   26.75 -                    // strict mode - delete of a var should throw SyntaxError
   26.76 -                    e.eval("var d = 2; delete d;");
   26.77 -                } catch (final ScriptException se) {
   26.78 -                    // check that the error message contains "SyntaxError"
   26.79 -                    assertTrue(se.getMessage().contains("SyntaxError"));
   26.80 -                }
   26.81 -
   26.82 -                return;
   26.83 -            }
   26.84 -        }
   26.85 -
   26.86 -        fail("Cannot find nashorn factory!");
   26.87 -    }
   26.88  }
    27.1 --- a/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Wed Feb 06 12:51:09 2013 -0400
    27.2 +++ b/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Thu Feb 07 17:17:29 2013 +0530
    27.3 @@ -27,8 +27,15 @@
    27.4  
    27.5  import static org.testng.Assert.assertEquals;
    27.6  import static org.testng.Assert.assertTrue;
    27.7 +import static org.testng.Assert.fail;
    27.8  
    27.9  import java.util.Map;
   27.10 +import javax.script.ScriptEngine;
   27.11 +import javax.script.ScriptEngineFactory;
   27.12 +import javax.script.ScriptEngineManager;
   27.13 +import javax.script.ScriptException;
   27.14 +import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
   27.15 +import jdk.nashorn.api.scripting.ScriptEngineTest;
   27.16  import jdk.nashorn.internal.runtime.options.Options;
   27.17  import org.testng.annotations.Test;
   27.18  
   27.19 @@ -107,4 +114,83 @@
   27.20          final ScriptFunction func = cx.compileScript(source, global, cx._strict);
   27.21          return func != null ? ScriptRuntime.apply(func, global) : null;
   27.22      }
   27.23 +
   27.24 +    // Tests for trusted client usage of nashorn script engine factory extension API
   27.25 +
   27.26 +    private static class MyClassLoader extends ClassLoader {
   27.27 +        // to check if script engine uses the specified class loader
   27.28 +        private final boolean[] reached = new boolean[1];
   27.29 +
   27.30 +        @Override
   27.31 +        protected Class findClass(final String name) throws ClassNotFoundException {
   27.32 +            // flag that it reached here
   27.33 +            reached[0] = true;
   27.34 +            return super.findClass(name);
   27.35 +        }
   27.36 +
   27.37 +        public boolean reached() {
   27.38 +            return reached[0];
   27.39 +        }
   27.40 +    };
   27.41 +
   27.42 +    // These are for "private" extension API of NashornScriptEngineFactory that
   27.43 +    // accepts a ClassLoader and/or command line options.
   27.44 +
   27.45 +    @Test
   27.46 +    public void factoryClassLoaderTest() {
   27.47 +        final ScriptEngineManager sm = new ScriptEngineManager();
   27.48 +        for (ScriptEngineFactory fac : sm.getEngineFactories()) {
   27.49 +            if (fac instanceof NashornScriptEngineFactory) {
   27.50 +                final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
   27.51 +                final MyClassLoader loader = new MyClassLoader();
   27.52 +                // set the classloader as app class loader
   27.53 +                final ScriptEngine e = nfac.getScriptEngine(loader);
   27.54 +                try {
   27.55 +                    e.eval("Packages.foo");
   27.56 +                    // check that the class loader was attempted
   27.57 +                    assertTrue(loader.reached(), "did not reach class loader!");
   27.58 +                } catch (final ScriptException se) {
   27.59 +                    se.printStackTrace();
   27.60 +                    fail(se.getMessage());
   27.61 +                }
   27.62 +                return;
   27.63 +            }
   27.64 +        }
   27.65 +
   27.66 +        fail("Cannot find nashorn factory!");
   27.67 +    }
   27.68 +
   27.69 +    @Test
   27.70 +    public void factoryClassLoaderAndOptionsTest() {
   27.71 +        final ScriptEngineManager sm = new ScriptEngineManager();
   27.72 +        for (ScriptEngineFactory fac : sm.getEngineFactories()) {
   27.73 +            if (fac instanceof NashornScriptEngineFactory) {
   27.74 +                final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
   27.75 +                final String[] options = new String[] { "-strict" };
   27.76 +                final MyClassLoader loader = new MyClassLoader();
   27.77 +                // set the classloader as app class loader
   27.78 +                final ScriptEngine e = nfac.getScriptEngine(options, loader);
   27.79 +                try {
   27.80 +                    e.eval("Packages.foo");
   27.81 +                    // check that the class loader was attempted
   27.82 +                    assertTrue(loader.reached(), "did not reach class loader!");
   27.83 +                } catch (final ScriptException se) {
   27.84 +                    se.printStackTrace();
   27.85 +                    fail(se.getMessage());
   27.86 +                }
   27.87 +
   27.88 +                try {
   27.89 +                    // strict mode - delete of a var should throw SyntaxError
   27.90 +                    e.eval("var d = 2; delete d;");
   27.91 +                } catch (final ScriptException se) {
   27.92 +                    // check that the error message contains "SyntaxError"
   27.93 +                    assertTrue(se.getMessage().contains("SyntaxError"));
   27.94 +                }
   27.95 +
   27.96 +                return;
   27.97 +            }
   27.98 +        }
   27.99 +
  27.100 +        fail("Cannot find nashorn factory!");
  27.101 +    }
  27.102  }

mercurial