8007715: Make sure that not all tests run with AllPermission
authorsundar
Thu, 07 Feb 2013 17:17:29 +0530
changeset 16221 38ac51eba133
parent 16220 f5502e7b3b71
child 16222 3e057d4357e0
8007715: Make sure that not all tests run with AllPermission Reviewed-by: lagergren, attila
nashorn/make/build.xml
nashorn/make/project.properties
nashorn/src/jdk/nashorn/internal/runtime/Context.java
nashorn/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java
nashorn/test/script/README
nashorn/test/script/basic/JDK-8006424.js
nashorn/test/script/basic/JDK-8006529.js
nashorn/test/script/basic/NASHORN-638.js
nashorn/test/script/basic/NASHORN-638.js.EXPECTED
nashorn/test/script/basic/NASHORN-653.js
nashorn/test/script/basic/NASHORN-758.js
nashorn/test/script/basic/getenv.js
nashorn/test/script/basic/getenv.js.EXPECTED
nashorn/test/script/basic/javaexceptions.js
nashorn/test/script/basic/newexpr.js
nashorn/test/script/sandbox/interfaceimpl.js
nashorn/test/script/sandbox/loadcompat.js
nashorn/test/script/trusted/JDK-8006424.js
nashorn/test/script/trusted/JDK-8006529.js
nashorn/test/script/trusted/NASHORN-638.js
nashorn/test/script/trusted/NASHORN-638.js.EXPECTED
nashorn/test/script/trusted/NASHORN-653.js
nashorn/test/script/trusted/README
nashorn/test/script/trusted/getenv.js
nashorn/test/script/trusted/getenv.js.EXPECTED
nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java
nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java
--- a/nashorn/make/build.xml	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/make/build.xml	Thu Feb 07 17:17:29 2013 +0530
@@ -198,25 +198,40 @@
            debug="${javac.debug}"
            encoding="${javac.encoding}"
            includeantruntime="false"/>
+
+    <!-- tests that check nashorn internals and internal API -->
+    <jar jarfile="${nashorn.internal.tests.jar}">
+      <fileset dir="${build.test.classes.dir}" excludes="**/api/scripting/*"/>
+    </jar>
+
+    <!-- tests that check nashorn script engine (jsr-223) API -->
+    <jar jarfile="${nashorn.api.tests.jar}">
+      <fileset dir="${build.test.classes.dir}" includes="**/api/scripting/*"/>
+    </jar>
+
   </target>
 
   <target name="generate-policy-file">
     <!-- Generating nashorn.policy file -->
-    <echo message="grant codeBase &quot;file:/${basedir}/dist/nashorn.jar&quot; {" file="${build.dir}/nashorn.policy"/>
+
+    <!-- nashorn internal tests jar requires AllPermission -->
+    <echo message="grant codeBase &quot;file:/${basedir}/${nashorn.internal.tests.jar}&quot; {" file="${build.dir}/nashorn.policy"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
-    <echo message="permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
+    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
-
-    <echo message="grant codeBase &quot;file:/${basedir}/build/test/classes&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
+    
+    <!-- TestNG framework jar needs AllPermission -->
+    <echo message="grant codeBase &quot;file:/${basedir}/${file.reference.testng.jar}&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
 
-    <echo message="grant codeBase &quot;file:/${basedir}/${file.reference.testng.jar}&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
+    <!-- AllPermission to test/script/trusted tests -->
+    <echo message="grant codeBase &quot;file:/${basedir}/test/script/trusted/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
@@ -225,14 +240,11 @@
 
     <echo message="grant codeBase &quot;file:/${basedir}/test/script/basic/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
-    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
-    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
-    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
+    <!-- test/script/basic .js scripts load other script tests -->
+    <echo message="    permission java.io.FilePermission &quot;${basedir}/test/script/-&quot;, &quot;read&quot;;" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
-
-    <echo message="grant codeBase &quot;file:/${basedir}/test/perf/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
-    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
-    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
+    <!-- test/script/basic .js scripts can read nashorn.test.* properties -->
+    <echo message="    permission java.util.PropertyPermission &quot;nashorn.test.*&quot;, &quot;read&quot;;" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
--- a/nashorn/make/project.properties	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/make/project.properties	Thu Feb 07 17:17:29 2013 +0530
@@ -53,6 +53,10 @@
 
 # test classes directory
 build.test.classes.dir=${build.dir}/test/classes
+# nashorn test jar - internal tests jar and api tests jar
+nashorn.internal.tests.jar=${build.dir}/nashorn-internal-tests.jar
+nashorn.api.tests.jar=${build.dir}/nashorn-api-tests.jar
+
 # test results directory
 build.test.results.dir=${build.dir}/test/reports
 
@@ -116,12 +120,13 @@
 test.basic.dir=test/script/basic
 test.error.dir=test/script/error
 test.sandbox.dir=test/script/sandbox
+test.trusted.dir=test/script/trusted
 test.external.dir=test/script/external
 test262.dir=${test.external.dir}/test262
 test262.suite.dir=${test262.dir}/test/suite
 
 test-sys-prop.test.dir=${test.dir}
-test-sys-prop.test.js.roots=${test.basic.dir} ${test.error.dir} ${test.sandbox.dir}
+test-sys-prop.test.js.roots=${test.basic.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir}
 test-sys-prop.test262.suite.dir=${test262.suite.dir}
 test-sys-prop.es5conform.testcases.dir=${test.external.dir}/ES5Conform/TestCases
 test-sys-prop.test.basic.dir=${test.basic.dir}
@@ -205,7 +210,9 @@
 
 run.test.classpath=\
     ${file.reference.testng.jar}:\
-    ${build.test.classes.dir}
+    ${nashorn.internal.tests.jar}:\
+    ${nashorn.api.tests.jar}
+
 src.dir=src
 test.src.dir=test/src
 
--- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Thu Feb 07 17:17:29 2013 +0530
@@ -607,24 +607,38 @@
         if (src instanceof String) {
             srcName = (String)src;
             final File file = new File((String)src);
-            if (file.isFile()) {
-                url = file.toURI().toURL();
-            } else if (srcName.indexOf(':') != -1) {
+            if (srcName.indexOf(':') != -1) {
                 try {
                     url = new URL((String)src);
                 } catch (final MalformedURLException e) {
                     // fallback URL - nashorn:foo.js - check under jdk/nashorn/internal/runtime/resources
-                    String str = (String)src;
+                    final String str = (String)src;
                     if (str.startsWith("nashorn:")) {
-                        str = "resources/" + str.substring("nashorn:".length());
-                        url = Context.class.getResource(str);
-                        if (url == null) {
+                        final String resource = "resources/" + str.substring("nashorn:".length());
+                        // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
+                        // These scripts are always available and are loaded from nashorn.jar's resources.
+                        final Source code = AccessController.doPrivileged(
+                                new PrivilegedAction<Source>() {
+                                    @Override
+                                    public Source run() {
+                                        try {
+                                            final URL resURL = Context.class.getResource(resource);
+                                            return (resURL != null)? new Source(str, resURL) : null;
+                                        } catch (final IOException exp) {
+                                            return null;
+                                        }
+                                    }
+                                });
+                        if (code == null) {
                             throw e;
                         }
+                        return evaluateSource(code, scope, scope);
                     } else {
                         throw e;
                     }
                 }
+            } else if (file.isFile()) {
+                url = file.toURI().toURL();
             }
             src = url;
         }
--- a/nashorn/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Thu Feb 07 17:17:29 2013 +0530
@@ -456,6 +456,8 @@
     private static ClassLoader createClassLoader(final ClassLoader parentLoader, final String className,
             final byte[] classBytes, final String privilegedActionClassName) {
         return new AdapterLoader(parentLoader) {
+            private final ProtectionDomain myProtectionDomain = getClass().getProtectionDomain();
+
             @Override
             protected Class<?> findClass(final String name) throws ClassNotFoundException {
                 if(name.equals(className)) {
@@ -463,7 +465,7 @@
                     return defineClass(name, bytes, 0, bytes.length, GENERATED_PROTECTION_DOMAIN);
                 } else if(name.equals(privilegedActionClassName)) {
                     final byte[] bytes = generatePrivilegedActionClassBytes(privilegedActionClassName.replace('.', '/'));
-                    return defineClass(name, bytes, 0, bytes.length, getClass().getProtectionDomain());
+                    return defineClass(name, bytes, 0, bytes.length, myProtectionDomain);
                 } else {
                     throw new ClassNotFoundException(name);
                 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/README	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,26 @@
+basic:
+
+"basic" language and library tests. These need run only with File read 
+permission to read files under "test/script" or subdirs and property read
+permission to read properties named "nashorn.test.*"
+
+error:
+
+scripts that should result in compile-time error. The expected files check
+for the error message format etc.
+
+currently-failing: 
+
+Tests that fail currently - but should pass eventually.
+These are excluded for now.
+
+sandbox:
+
+Tests to check that sandbox scripts cannot access security sensitive resources.
+Scripts under this directory run with no special permissions other than
+what is given to all "sandbox" scripts.
+
+trusted:
+
+These tests run under AllPermission. Put only those scripts that really need
+AllPermission - say for eg. creating class loader, full reflective access.
--- a/nashorn/test/script/basic/JDK-8006424.js	Wed Feb 06 12:51:09 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- * 
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- * 
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * JDK-8006424 : Passing null or undefined to adapter class constructors results in NPE or ClassCastException
- *
- * @test
- * @run
- */
-
-function check(callback) {
-    try {
-        callback();
-        fail("should have thrown exception");
-    } catch (e) {
-        if (! (e instanceof TypeError)) {
-            fail("TypeError expected, but got " + e);
-        }
-    }
-}
-
-check(function() { new java.lang.ClassLoader(null) });
-check(function() { new java.lang.ClassLoader(undefined) });
-check(function() { new java.lang.Runnable(null) });
-check(function() { new java.lang.Runnable(undefined) });
--- a/nashorn/test/script/basic/JDK-8006529.js	Wed Feb 06 12:51:09 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- * 
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- * 
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * JDK-8006529 : Methods should not always get callee parameter, and they
- * should not be too eager in creation of scopes.
- *
- * @test
- * @run
- */
-
-// compile(script) -- compiles a script specified as a string with its 
-// source code, returns a jdk.nashorn.internal.ir.FunctionNode object 
-// representing it.
-var compile = (function() {
-    var Compiler       = Java.type("jdk.nashorn.internal.codegen.Compiler")
-    var Context        = Java.type("jdk.nashorn.internal.runtime.Context")
-    var Source         = Java.type("jdk.nashorn.internal.runtime.Source")
-    var CompilerAccess = Java.type("jdk.nashorn.internal.codegen.CompilerAccess")
-    return function(source) {
-	    var compiler = Compiler.compiler(new Source("<no name>", source), Context.getContext())
-        compiler.compile()
-        return CompilerAccess.getScriptNode(compiler)
-    }
-})();
-
-var allAssertions = (function() {
-    var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'varsInScope', 'isStrictMode']
-    var allAssertions = {}
-    for(var assertion in allAssertionList) {
-        allAssertions[allAssertionList[assertion]] = true
-    }
-    return allAssertions;
-})();
-
-// test(f[, assertions...]) tests whether all the specified assertions on the
-// passed function node are true.
-function test(f) {
-    var assertions = {}
-    for(var i = 1; i < arguments.length; ++i) {
-        var assertion = arguments[i]
-        if(!allAssertions[assertion]) {
-            throw "Unknown assertion " + assertion + " for " + f;
-        }
-        assertions[assertion] = true
-    }
-    for(var assertion in allAssertions) {
-        var expectedValue = !!assertions[assertion]
-        if(f[assertion] == null) {
-            throw "Can't find " + assertion + " on " + f;
-        }
-        if(f[assertion]() !== expectedValue) {
-            throw "Expected " + assertion + " === " + expectedValue + " for " + f;
-        }
-    }
-}
-
-// testFirstFn(script[, assertions...] tests whether all the specified
-// assertions are true in the first function in the given script; "script"
-// is a string with the source text of the script.
-function testFirstFn(script) {
-    arguments[0] = compile(script).functions[0]
-    test.apply(null, arguments)
-}
-
-// ---------------------------------- ACTUAL TESTS START HERE --------------
-
-// The simplest possible functions have no attributes set
-testFirstFn("function f() { }")
-testFirstFn("function f(x) { x }")
-
-// A function referencing a global needs parent scope, and it needs callee
-// (because parent scope is passed through callee)
-testFirstFn("function f() { x }", 'needsCallee', 'needsParentScope')
-
-// A function referencing "arguments" will have to be vararg. It also needs
-// the callee, as it needs to fill out "arguments.callee".
-testFirstFn("function f() { arguments }", 'needsCallee', 'isVarArg')
-
-// A function referencing "arguments" will have to be vararg. If it is
-// strict, it will not have to have a callee, though.
-testFirstFn("function f() {'use strict'; arguments }", 'isVarArg', 'isStrictMode')
-
-// A function defining "arguments" as a parameter will not be vararg.
-testFirstFn("function f(arguments) { arguments }")
-
-// A function defining "arguments" as a nested function will not be vararg.
-testFirstFn("function f() { function arguments() {}; arguments; }")
-
-// A function defining "arguments" as a local variable will be vararg.
-testFirstFn("function f() { var arguments; arguments; }", 'isVarArg', 'needsCallee')
-
-// A self-referencing function defined as a statement doesn't need a self 
-// symbol, as it'll rather obtain itself from the parent scope.
-testFirstFn("function f() { f() }", 'needsCallee', 'needsParentScope')
-
-// A self-referencing function defined as an expression needs a self symbol,
-// as it can't obtain itself from the parent scope.
-testFirstFn("(function f() { f() })", 'needsCallee', 'needsSelfSymbol')
-
-// A child function accessing parent's variable triggers the need for scope
-// in parent
-testFirstFn("(function f() { var x; function g() { x } })", 'needsScope')
-
-// A child function accessing parent's parameter triggers the need for scope
-// in parent
-testFirstFn("(function f(x) { function g() { x } })", 'needsScope')
-
-// A child function accessing a global variable triggers the need for parent
-// scope in parent
-testFirstFn("(function f() { function g() { x } })", 'needsParentScope', 'needsCallee')
-
-// A child function redefining a local variable from its parent should not 
-// affect the parent function in any way
-testFirstFn("(function f() { var x; function g() { var x; x } })")
-
-// Using "with" unleashes a lot of needs: parent scope, callee, own scope, 
-// and all variables in scope. Actually, we could make "with" less wasteful,
-// and only put those variables in scope that it actually references, similar
-// to what nested functions do with variables in their parents.
-testFirstFn("(function f() { var o; with(o) {} })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasWith', 'hasDeepWithOrEval', 'varsInScope')
-
-// Using "eval" is as bad as using "with" with the added requirement of
-// being vararg, 'cause we don't know if eval will be using "arguments".
-testFirstFn("(function f() { eval() })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasEval', 'isVarArg', 'hasDeepWithOrEval', 'varsInScope')
-
-// Nested function using "with" is pretty much the same as the parent
-// function needing with.
-testFirstFn("(function f() { function g() { var o; with(o) {} } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
-// Nested function using "eval" is almost the same as parent function using
-// eval, but at least the parent doesn't have to be vararg.
-testFirstFn("(function f() { function g() { eval() } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
-
-// Function with 250 named parameters is ordinary
-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 }")
-
-// Function with 251 named parameters is variable arguments
-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')
--- a/nashorn/test/script/basic/NASHORN-638.js	Wed Feb 06 12:51:09 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- * 
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- * 
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * NASHORN-638 : Callsite tracing and profiling are broken
- *
- * @test
- * @run
- */
-
-/*
- * creates new script engine initialized with given options and
- * runs given code on it. Returns standard output captured.
- */
-
-function runScriptEngine(opts, code) {
-    var imports = new JavaImporter(
-        Packages.jdk.nashorn.api.scripting,
-        java.io, java.lang, java.util);
-
-    with(imports) {
-        var fac = new NashornScriptEngineFactory();
-        // get current System.err
-        var oldErr = System.err;
-        var baos = new ByteArrayOutputStream();
-        var newErr = new PrintStream(baos);
-        try {
-            // set new standard err
-            System.setErr(newErr);
-            var strType = Java.type("java.lang.String");
-            var engine = fac.getScriptEngine(Java.toJavaArray(opts, strType));
-            engine.eval(code);
-            newErr.flush();
-            return new java.lang.String(baos.toByteArray());
-        } finally {
-            // restore System.err to old value
-            System.setErr(oldErr);
-        }
-    }
-}
-
-var str = runScriptEngine([ "-tcs=all" ], "new Date");
-print("hello, world!");
-
-if (str.indexOf(" ENTER ") == -1) {
-    fail("expected 'ENTER' in trace mode output");
-}
-
-if (str.indexOf(" EXIT ") == -1) {
-    fail("expected 'EXIT' in trace mode output");
-}
-
--- a/nashorn/test/script/basic/NASHORN-638.js.EXPECTED	Wed Feb 06 12:51:09 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-hello, world!
--- a/nashorn/test/script/basic/NASHORN-653.js	Wed Feb 06 12:51:09 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- * 
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- * 
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * NASHORN-653 : Various problems with isTerminal and dead code generation from ASM
- *
- * @test
- * @run
- */
-
-var script = "   \
-function a() {   \
-    return true; \
-}                \
-                 \
-function b() {   \
-    while (x) {      \
-	return true; \
-    }                \
-}                    \
-                     \
-function c() {       \
-    while (true) {   \
-	return true; \
-    }                \
- }                   \
-                     \
-function d() {       \
-    do {             \
-	return true; \
-    } while (x);     \
-} \
-\
-function f() {       \
-    for (;;) {       \
-	return true; \
-    } \
-} \
-\
-function e() { \
-    for (;;) { \
-	return true; \
-    } \
-} \
-\
-function g() { \
-    for(;;) { \
-	print('goes on and on and on ... '); \
-    } \
-    print('x'); \
-} \
-";
-
-function runScriptEngine(opts, code) {
-    var imports = new JavaImporter(
-        Packages.jdk.nashorn.api.scripting,
-        java.io, java.lang, java.util);
-
-    with(imports) {
-        var fac = new NashornScriptEngineFactory();
-        // get current System.err
-        var oldErr = System.err;
-        var baos = new ByteArrayOutputStream();
-        var newErr = new PrintStream(baos);
-        try {
-            // set new standard err
-            System.setErr(newErr);
-            var strType = Java.type("java.lang.String");
-            var engine = fac.getScriptEngine(Java.toJavaArray(opts, strType));
-            engine.eval(code);
-            newErr.flush();
-            return new java.lang.String(baos.toByteArray());
-        } finally {
-            // restore System.err to old value
-            System.setErr(oldErr);
-        }
-    }
-}
-
-var result = runScriptEngine([ "--print-code" ], script);
-
-if (result.indexOf("NOP") != -1) {
-    fail("ASM genenerates NOP*/ATHROW sequences - dead code is still in the script");
-}
--- a/nashorn/test/script/basic/NASHORN-758.js	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/test/script/basic/NASHORN-758.js	Thu Feb 07 17:17:29 2013 +0530
@@ -25,16 +25,16 @@
  * NASHORN-758 : nashorn shell command line options improvements
  *
  * @test
- * @option -Dfoo=bar
- * @option -Dhello=world
+ * @option -Dnashorn.test.foo=bar
+ * @option -Dnashorn.test.hello=world
  * @run
  */
 
 
-if (java.lang.System.getProperty("foo") != "bar") {
-    fail("System property 'foo' != 'bar'");
+if (java.lang.System.getProperty("nashorn.test.foo") != "bar") {
+    fail("System property 'nashorn.test.foo' != 'bar'");
 }
 
-if (java.lang.System.getProperty("hello") != "world") {
-    fail("System property 'hello' != 'world'");
+if (java.lang.System.getProperty("nashorn.test.hello") != "world") {
+    fail("System property 'nashorn.test.hello' != 'world'");
 }
--- a/nashorn/test/script/basic/getenv.js	Wed Feb 06 12:51:09 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- * 
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- * 
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * Verifies Map methods do not generate NPE
- *
- * @test
- * @run
- */
-
-print(java.lang.System.getenv().isEmpty());
--- a/nashorn/test/script/basic/getenv.js.EXPECTED	Wed Feb 06 12:51:09 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-false
--- a/nashorn/test/script/basic/javaexceptions.js	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/test/script/basic/javaexceptions.js	Thu Feb 07 17:17:29 2013 +0530
@@ -31,7 +31,7 @@
 try {
     new java.io.FileInputStream("non_existent_file");
 } catch (e) {
-    print(e instanceof java.io.FileNotFoundException);
+    print(e instanceof java.io.FileNotFoundException || e instanceof java.lang.SecurityException);
 }
 
 try {
--- a/nashorn/test/script/basic/newexpr.js	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/test/script/basic/newexpr.js	Thu Feb 07 17:17:29 2013 +0530
@@ -29,7 +29,7 @@
  */
 
 var File = java.io.File;
-print(new File(".").isDirectory());
+print(! new File(".").toString().isEmpty());
 
 var obj = {
    foo : function (x) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/sandbox/interfaceimpl.js	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Check that user defined interface can be implemented.
+ *
+ * @test
+ * @run
+ * @security
+ */
+
+var Window = Java.type("jdk.nashorn.api.scripting.Window");
+var WindowEventHandler = Java.type("jdk.nashorn.api.scripting.WindowEventHandler");
+
+var w = new Window();
+
+var loadedFuncReached = false;
+// try function to SAM converter
+w.onload = function() {
+    loadedFuncReached = true;
+    return true;
+}
+
+w.onload.loaded();
+if (! loadedFuncReached) {
+    fail("Interface method impl. not called");
+}
+
+// reset
+loadedFuncReached = false;
+
+// try direct interface implementation
+w.onload = new WindowEventHandler() {
+    loaded: function() {
+        loadedFuncReached = true;
+        return true;
+    }
+};
+
+w.onload.loaded();
+if (! loadedFuncReached) {
+    fail("Interface method impl. not called");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/sandbox/loadcompat.js	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Check that nashorn mozilla compatibility script can be loaded in sandbox.
+ *
+ * @test
+ * @run
+ * @security
+ */
+
+load("nashorn:mozilla_compat.js");
+
+var obj = {};
+if (obj.__proto__ !== Object.prototype) {
+    fail("__proto__ does not work as expected");
+}
+
+var array = [];
+if (array.__proto__ !== Array.prototype) {
+    fail("__proto__ does not work as expected");
+}
+
+if (typeof JavaAdapter != 'function') {
+    fail("JavaAdapter constructor is missing in compatibility script");
+}
+
+if (typeof importPackage != 'function') {
+    fail("importPackage function is missing in compatibility script");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/trusted/JDK-8006424.js	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8006424 : Passing null or undefined to adapter class constructors results in NPE or ClassCastException
+ *
+ * @test
+ * @run
+ */
+
+function check(callback) {
+    try {
+        callback();
+        fail("should have thrown exception");
+    } catch (e) {
+        if (! (e instanceof TypeError)) {
+            fail("TypeError expected, but got " + e);
+        }
+    }
+}
+
+check(function() { new java.lang.ClassLoader(null) });
+check(function() { new java.lang.ClassLoader(undefined) });
+check(function() { new java.lang.Runnable(null) });
+check(function() { new java.lang.Runnable(undefined) });
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/trusted/JDK-8006529.js	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8006529 : Methods should not always get callee parameter, and they
+ * should not be too eager in creation of scopes.
+ *
+ * @test
+ * @run
+ */
+
+// compile(script) -- compiles a script specified as a string with its 
+// source code, returns a jdk.nashorn.internal.ir.FunctionNode object 
+// representing it.
+var compile = (function() {
+    var Compiler       = Java.type("jdk.nashorn.internal.codegen.Compiler")
+    var Context        = Java.type("jdk.nashorn.internal.runtime.Context")
+    var Source         = Java.type("jdk.nashorn.internal.runtime.Source")
+    var CompilerAccess = Java.type("jdk.nashorn.internal.codegen.CompilerAccess")
+    return function(source) {
+	    var compiler = Compiler.compiler(new Source("<no name>", source), Context.getContext())
+        compiler.compile()
+        return CompilerAccess.getScriptNode(compiler)
+    }
+})();
+
+var allAssertions = (function() {
+    var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'varsInScope', 'isStrictMode']
+    var allAssertions = {}
+    for(var assertion in allAssertionList) {
+        allAssertions[allAssertionList[assertion]] = true
+    }
+    return allAssertions;
+})();
+
+// test(f[, assertions...]) tests whether all the specified assertions on the
+// passed function node are true.
+function test(f) {
+    var assertions = {}
+    for(var i = 1; i < arguments.length; ++i) {
+        var assertion = arguments[i]
+        if(!allAssertions[assertion]) {
+            throw "Unknown assertion " + assertion + " for " + f;
+        }
+        assertions[assertion] = true
+    }
+    for(var assertion in allAssertions) {
+        var expectedValue = !!assertions[assertion]
+        if(f[assertion] == null) {
+            throw "Can't find " + assertion + " on " + f;
+        }
+        if(f[assertion]() !== expectedValue) {
+            throw "Expected " + assertion + " === " + expectedValue + " for " + f;
+        }
+    }
+}
+
+// testFirstFn(script[, assertions...] tests whether all the specified
+// assertions are true in the first function in the given script; "script"
+// is a string with the source text of the script.
+function testFirstFn(script) {
+    arguments[0] = compile(script).functions[0]
+    test.apply(null, arguments)
+}
+
+// ---------------------------------- ACTUAL TESTS START HERE --------------
+
+// The simplest possible functions have no attributes set
+testFirstFn("function f() { }")
+testFirstFn("function f(x) { x }")
+
+// A function referencing a global needs parent scope, and it needs callee
+// (because parent scope is passed through callee)
+testFirstFn("function f() { x }", 'needsCallee', 'needsParentScope')
+
+// A function referencing "arguments" will have to be vararg. It also needs
+// the callee, as it needs to fill out "arguments.callee".
+testFirstFn("function f() { arguments }", 'needsCallee', 'isVarArg')
+
+// A function referencing "arguments" will have to be vararg. If it is
+// strict, it will not have to have a callee, though.
+testFirstFn("function f() {'use strict'; arguments }", 'isVarArg', 'isStrictMode')
+
+// A function defining "arguments" as a parameter will not be vararg.
+testFirstFn("function f(arguments) { arguments }")
+
+// A function defining "arguments" as a nested function will not be vararg.
+testFirstFn("function f() { function arguments() {}; arguments; }")
+
+// A function defining "arguments" as a local variable will be vararg.
+testFirstFn("function f() { var arguments; arguments; }", 'isVarArg', 'needsCallee')
+
+// A self-referencing function defined as a statement doesn't need a self 
+// symbol, as it'll rather obtain itself from the parent scope.
+testFirstFn("function f() { f() }", 'needsCallee', 'needsParentScope')
+
+// A self-referencing function defined as an expression needs a self symbol,
+// as it can't obtain itself from the parent scope.
+testFirstFn("(function f() { f() })", 'needsCallee', 'needsSelfSymbol')
+
+// A child function accessing parent's variable triggers the need for scope
+// in parent
+testFirstFn("(function f() { var x; function g() { x } })", 'needsScope')
+
+// A child function accessing parent's parameter triggers the need for scope
+// in parent
+testFirstFn("(function f(x) { function g() { x } })", 'needsScope')
+
+// A child function accessing a global variable triggers the need for parent
+// scope in parent
+testFirstFn("(function f() { function g() { x } })", 'needsParentScope', 'needsCallee')
+
+// A child function redefining a local variable from its parent should not 
+// affect the parent function in any way
+testFirstFn("(function f() { var x; function g() { var x; x } })")
+
+// Using "with" unleashes a lot of needs: parent scope, callee, own scope, 
+// and all variables in scope. Actually, we could make "with" less wasteful,
+// and only put those variables in scope that it actually references, similar
+// to what nested functions do with variables in their parents.
+testFirstFn("(function f() { var o; with(o) {} })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasWith', 'hasDeepWithOrEval', 'varsInScope')
+
+// Using "eval" is as bad as using "with" with the added requirement of
+// being vararg, 'cause we don't know if eval will be using "arguments".
+testFirstFn("(function f() { eval() })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasEval', 'isVarArg', 'hasDeepWithOrEval', 'varsInScope')
+
+// Nested function using "with" is pretty much the same as the parent
+// function needing with.
+testFirstFn("(function f() { function g() { var o; with(o) {} } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
+// Nested function using "eval" is almost the same as parent function using
+// eval, but at least the parent doesn't have to be vararg.
+testFirstFn("(function f() { function g() { eval() } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'varsInScope')
+
+// Function with 250 named parameters is ordinary
+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 }")
+
+// Function with 251 named parameters is variable arguments
+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')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/trusted/NASHORN-638.js	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * NASHORN-638 : Callsite tracing and profiling are broken
+ *
+ * @test
+ * @run
+ */
+
+/*
+ * creates new script engine initialized with given options and
+ * runs given code on it. Returns standard output captured.
+ */
+
+function runScriptEngine(opts, code) {
+    var imports = new JavaImporter(
+        Packages.jdk.nashorn.api.scripting,
+        java.io, java.lang, java.util);
+
+    with(imports) {
+        var fac = new NashornScriptEngineFactory();
+        // get current System.err
+        var oldErr = System.err;
+        var baos = new ByteArrayOutputStream();
+        var newErr = new PrintStream(baos);
+        try {
+            // set new standard err
+            System.setErr(newErr);
+            var strType = Java.type("java.lang.String");
+            var engine = fac.getScriptEngine(Java.toJavaArray(opts, strType));
+            engine.eval(code);
+            newErr.flush();
+            return new java.lang.String(baos.toByteArray());
+        } finally {
+            // restore System.err to old value
+            System.setErr(oldErr);
+        }
+    }
+}
+
+var str = runScriptEngine([ "-tcs=all" ], "new Date");
+print("hello, world!");
+
+if (str.indexOf(" ENTER ") == -1) {
+    fail("expected 'ENTER' in trace mode output");
+}
+
+if (str.indexOf(" EXIT ") == -1) {
+    fail("expected 'EXIT' in trace mode output");
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/trusted/NASHORN-638.js.EXPECTED	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,1 @@
+hello, world!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/trusted/NASHORN-653.js	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * NASHORN-653 : Various problems with isTerminal and dead code generation from ASM
+ *
+ * @test
+ * @run
+ */
+
+var script = "   \
+function a() {   \
+    return true; \
+}                \
+                 \
+function b() {   \
+    while (x) {      \
+	return true; \
+    }                \
+}                    \
+                     \
+function c() {       \
+    while (true) {   \
+	return true; \
+    }                \
+ }                   \
+                     \
+function d() {       \
+    do {             \
+	return true; \
+    } while (x);     \
+} \
+\
+function f() {       \
+    for (;;) {       \
+	return true; \
+    } \
+} \
+\
+function e() { \
+    for (;;) { \
+	return true; \
+    } \
+} \
+\
+function g() { \
+    for(;;) { \
+	print('goes on and on and on ... '); \
+    } \
+    print('x'); \
+} \
+";
+
+function runScriptEngine(opts, code) {
+    var imports = new JavaImporter(
+        Packages.jdk.nashorn.api.scripting,
+        java.io, java.lang, java.util);
+
+    with(imports) {
+        var fac = new NashornScriptEngineFactory();
+        // get current System.err
+        var oldErr = System.err;
+        var baos = new ByteArrayOutputStream();
+        var newErr = new PrintStream(baos);
+        try {
+            // set new standard err
+            System.setErr(newErr);
+            var strType = Java.type("java.lang.String");
+            var engine = fac.getScriptEngine(Java.toJavaArray(opts, strType));
+            engine.eval(code);
+            newErr.flush();
+            return new java.lang.String(baos.toByteArray());
+        } finally {
+            // restore System.err to old value
+            System.setErr(oldErr);
+        }
+    }
+}
+
+var result = runScriptEngine([ "--print-code" ], script);
+
+if (result.indexOf("NOP") != -1) {
+    fail("ASM genenerates NOP*/ATHROW sequences - dead code is still in the script");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/trusted/README	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,4 @@
+This directory contains tests that need AllPermission to run.
+
+Scripts that need to create classloaders, need to reflectively access
+declared members of other classes etc. should go here.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/trusted/getenv.js	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Verifies Map methods do not generate NPE
+ *
+ * @test
+ * @run
+ */
+
+print(java.lang.System.getenv().isEmpty());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/trusted/getenv.js.EXPECTED	Thu Feb 07 17:17:29 2013 +0530
@@ -0,0 +1,1 @@
+false
--- a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Thu Feb 07 17:17:29 2013 +0530
@@ -972,46 +972,6 @@
         }
     }
 
-    private static class MyClassLoader extends ClassLoader {
-        // to check if script engine uses the specified class loader
-        private final boolean[] reached = new boolean[1];
-
-        @Override
-        protected Class findClass(final String name) throws ClassNotFoundException {
-            // flag that it reached here
-            reached[0] = true;
-            return super.findClass(name);
-        }
-
-        public boolean reached() {
-            return reached[0];
-        }
-    };
-
-    @Test
-    public void factoryClassLoaderTest() {
-        final ScriptEngineManager sm = new ScriptEngineManager();
-        for (ScriptEngineFactory fac : sm.getEngineFactories()) {
-            if (fac instanceof NashornScriptEngineFactory) {
-                final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
-                final MyClassLoader loader = new MyClassLoader();
-                // set the classloader as app class loader
-                final ScriptEngine e = nfac.getScriptEngine(loader);
-                try {
-                    e.eval("Packages.foo");
-                    // check that the class loader was attempted
-                    assertTrue(loader.reached(), "did not reach class loader!");
-                } catch (final ScriptException se) {
-                    se.printStackTrace();
-                    fail(se.getMessage());
-                }
-                return;
-            }
-        }
-
-        fail("Cannot find nashorn factory!");
-    }
-
     @Test
     public void factoryOptionsTest() {
         final ScriptEngineManager sm = new ScriptEngineManager();
@@ -1033,38 +993,4 @@
 
         fail("Cannot find nashorn factory!");
     }
-
-    @Test
-    public void factoryClassLoaderAndOptionsTest() {
-        final ScriptEngineManager sm = new ScriptEngineManager();
-        for (ScriptEngineFactory fac : sm.getEngineFactories()) {
-            if (fac instanceof NashornScriptEngineFactory) {
-                final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
-                final String[] options = new String[] { "-strict" };
-                final MyClassLoader loader = new MyClassLoader();
-                // set the classloader as app class loader
-                final ScriptEngine e = nfac.getScriptEngine(options, loader);
-                try {
-                    e.eval("Packages.foo");
-                    // check that the class loader was attempted
-                    assertTrue(loader.reached(), "did not reach class loader!");
-                } catch (final ScriptException se) {
-                    se.printStackTrace();
-                    fail(se.getMessage());
-                }
-
-                try {
-                    // strict mode - delete of a var should throw SyntaxError
-                    e.eval("var d = 2; delete d;");
-                } catch (final ScriptException se) {
-                    // check that the error message contains "SyntaxError"
-                    assertTrue(se.getMessage().contains("SyntaxError"));
-                }
-
-                return;
-            }
-        }
-
-        fail("Cannot find nashorn factory!");
-    }
 }
--- a/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Wed Feb 06 12:51:09 2013 -0400
+++ b/nashorn/test/src/jdk/nashorn/internal/runtime/ContextTest.java	Thu Feb 07 17:17:29 2013 +0530
@@ -27,8 +27,15 @@
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
 
 import java.util.Map;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
+import jdk.nashorn.api.scripting.ScriptEngineTest;
 import jdk.nashorn.internal.runtime.options.Options;
 import org.testng.annotations.Test;
 
@@ -107,4 +114,83 @@
         final ScriptFunction func = cx.compileScript(source, global, cx._strict);
         return func != null ? ScriptRuntime.apply(func, global) : null;
     }
+
+    // Tests for trusted client usage of nashorn script engine factory extension API
+
+    private static class MyClassLoader extends ClassLoader {
+        // to check if script engine uses the specified class loader
+        private final boolean[] reached = new boolean[1];
+
+        @Override
+        protected Class findClass(final String name) throws ClassNotFoundException {
+            // flag that it reached here
+            reached[0] = true;
+            return super.findClass(name);
+        }
+
+        public boolean reached() {
+            return reached[0];
+        }
+    };
+
+    // These are for "private" extension API of NashornScriptEngineFactory that
+    // accepts a ClassLoader and/or command line options.
+
+    @Test
+    public void factoryClassLoaderTest() {
+        final ScriptEngineManager sm = new ScriptEngineManager();
+        for (ScriptEngineFactory fac : sm.getEngineFactories()) {
+            if (fac instanceof NashornScriptEngineFactory) {
+                final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
+                final MyClassLoader loader = new MyClassLoader();
+                // set the classloader as app class loader
+                final ScriptEngine e = nfac.getScriptEngine(loader);
+                try {
+                    e.eval("Packages.foo");
+                    // check that the class loader was attempted
+                    assertTrue(loader.reached(), "did not reach class loader!");
+                } catch (final ScriptException se) {
+                    se.printStackTrace();
+                    fail(se.getMessage());
+                }
+                return;
+            }
+        }
+
+        fail("Cannot find nashorn factory!");
+    }
+
+    @Test
+    public void factoryClassLoaderAndOptionsTest() {
+        final ScriptEngineManager sm = new ScriptEngineManager();
+        for (ScriptEngineFactory fac : sm.getEngineFactories()) {
+            if (fac instanceof NashornScriptEngineFactory) {
+                final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
+                final String[] options = new String[] { "-strict" };
+                final MyClassLoader loader = new MyClassLoader();
+                // set the classloader as app class loader
+                final ScriptEngine e = nfac.getScriptEngine(options, loader);
+                try {
+                    e.eval("Packages.foo");
+                    // check that the class loader was attempted
+                    assertTrue(loader.reached(), "did not reach class loader!");
+                } catch (final ScriptException se) {
+                    se.printStackTrace();
+                    fail(se.getMessage());
+                }
+
+                try {
+                    // strict mode - delete of a var should throw SyntaxError
+                    e.eval("var d = 2; delete d;");
+                } catch (final ScriptException se) {
+                    // check that the error message contains "SyntaxError"
+                    assertTrue(se.getMessage().contains("SyntaxError"));
+                }
+
+                return;
+            }
+        }
+
+        fail("Cannot find nashorn factory!");
+    }
 }