Initial load
diff --git a/test/javax/script/CommonSetup.sh b/test/javax/script/CommonSetup.sh
new file mode 100644
index 0000000..e76da82
--- /dev/null
+++ b/test/javax/script/CommonSetup.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+#
+# Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+
+#
+#
+# Common setup for the script API unit tests. Setups up the following variables:
+#
+# PS - path sep.
+# FS - file sep.
+# JAVA - java cmd.
+# JAVAC - javac cmd.
+# JAR - jar cmd.
+
+OS=`uname -s`
+case "$OS" in
+  SunOS )
+    PS=":"
+    FS="/"
+    ;;
+  Linux )
+    PS=":"
+    FS="/"
+    ;;
+  Windows* )
+    PS=";"
+    OS="Windows"
+    FS="\\"
+    ;;
+  * )
+    echo "Unrecognized system!"
+    exit 1;
+    ;;
+esac
+
+if [ "${TESTJAVA}" = "" ]
+then
+  echo "TESTJAVA not set.  Test cannot execute.  Failed."
+  exit 1
+fi
+
+if [ "${TESTSRC}" = "" ]
+then
+  echo "TESTSRC not set.  Test cannot execute.  Failed."
+  exit 1
+fi
+ 
+if [ "${TESTCLASSES}" = "" ]
+then
+  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
+  exit 1
+fi
+
+JAVA="${TESTJAVA}/bin/java"
+JAVAC="${TESTJAVA}/bin/javac"
+JAR="${TESTJAVA}/bin/jar"
+
diff --git a/test/javax/script/DummyScriptEngine.java b/test/javax/script/DummyScriptEngine.java
new file mode 100644
index 0000000..a1d83dc
--- /dev/null
+++ b/test/javax/script/DummyScriptEngine.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ *
+ *
+ * This is a dummy script engine implementation
+ */
+import javax.script.*;
+import java.io.*;
+
+public class DummyScriptEngine extends AbstractScriptEngine {
+    public Object eval(String str, ScriptContext ctx) {
+        return eval(new StringReader(str), ctx);
+    }
+
+    public Object eval(Reader reader, ScriptContext ctx) {
+        System.out.println("eval done!");
+        return null;
+    }
+
+    public ScriptEngineFactory getFactory() {
+        return new DummyScriptEngineFactory();
+    }
+
+    public Bindings createBindings() {
+        return new SimpleBindings();
+    }
+}
diff --git a/test/javax/script/DummyScriptEngineFactory.java b/test/javax/script/DummyScriptEngineFactory.java
new file mode 100644
index 0000000..ae150e8
--- /dev/null
+++ b/test/javax/script/DummyScriptEngineFactory.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ *
+ *
+ * This is script engine factory for dummy engine.
+ */
+
+import javax.script.*;
+import java.util.*;
+
+public class DummyScriptEngineFactory implements ScriptEngineFactory {
+    public String getEngineName() {
+        return "dummy";
+    }
+
+    public String getEngineVersion() {
+        return "-1.0";
+    }
+
+    public List<String> getExtensions() {
+        return extensions;
+    }
+
+    public String getLanguageName() {
+        return "dummy";
+    }
+
+    public String getLanguageVersion() {
+        return "-1.0";
+    }
+
+    public String getMethodCallSyntax(String obj, String m, String... args) {
+        StringBuffer buf = new StringBuffer();
+        buf.append("call " + m + " ");
+        buf.append(" on " + obj + " with ");
+        for (int i = 0; i < args.length; i++) {
+            buf.append(args[i] + ", ");
+        }
+        buf.append(";");
+        return buf.toString();
+    }
+
+    public List<String> getMimeTypes() {
+        return mimeTypes;
+    }
+
+    public List<String> getNames() {
+        return names;
+    }
+
+    public String getOutputStatement(String str) {
+        return "output " + str;
+    }
+
+    public String getParameter(String key) {
+        if (key.equals(ScriptEngine.ENGINE)) {
+            return getEngineName();
+        } else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
+            return getEngineVersion();
+        } else if (key.equals(ScriptEngine.NAME)) {
+            return getEngineName();
+        } else if (key.equals(ScriptEngine.LANGUAGE)) {
+            return getLanguageName();
+        } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
+            return getLanguageVersion();
+        } else {
+            return null;
+        }
+    }
+
+    public String getProgram(String... statements) {
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < statements.length; i++) {
+            buf.append(statements[i]);
+        }
+        return buf.toString();
+    }
+
+    public ScriptEngine getScriptEngine() {
+        return new DummyScriptEngine();
+    }
+
+    private static List<String> names;
+    private static List<String> extensions;
+    private static List<String> mimeTypes;
+    static {
+        names = new ArrayList<String>(1);
+        names.add("dummy");
+        names = Collections.unmodifiableList(names);
+        extensions = names;
+        mimeTypes = new ArrayList<String>(0);
+        mimeTypes = Collections.unmodifiableList(mimeTypes);
+    }
+}
diff --git a/test/javax/script/E4XErrorTest.java b/test/javax/script/E4XErrorTest.java
new file mode 100644
index 0000000..5936fd4
--- /dev/null
+++ b/test/javax/script/E4XErrorTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6346734
+ * @summary We do *not* support E4X (ECMAScript for XML) in our
+ * implementation. We want to throw error on XML literals
+ * as early as possible rather than at "runtime" - i.e., when
+ * engine looks for "XML" constructor.
+ */
+
+import javax.script.*;
+import java.util.Locale;
+
+public class E4XErrorTest {
+
+        public static void main(String[] args) throws Exception {
+            ScriptEngineManager manager = new ScriptEngineManager();
+            ScriptEngine jsengine = manager.getEngineByName("js");
+            if (jsengine == null) {
+                throw new RuntimeException("no js engine found");
+            }
+
+            // The test below depends on the error message content
+            // that is loaded from resource bundles.  So, we force
+            // English Locale to compare correct value..
+            Locale.setDefault(Locale.US);
+
+            try {
+                jsengine.eval("var v = <html></html>;");
+            } catch (ScriptException se) {
+                String msg = se.getMessage();
+                if (msg.indexOf("syntax error") == -1) {
+                    throw new RuntimeException("syntax error expected, got " +
+                                       msg);
+                }
+                return;
+            }
+            // should not reach here.. exception should have been thrown.
+            throw new RuntimeException("Huh! E4X is supported??");
+        }
+}
diff --git a/test/javax/script/JavaScriptScopeTest.java b/test/javax/script/JavaScriptScopeTest.java
new file mode 100644
index 0000000..1bce7b6
--- /dev/null
+++ b/test/javax/script/JavaScriptScopeTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6346733
+ * @summary Verify that independent Bindings instances don't
+ * get affected by default scope assignments. Also, verify
+ * that script globals can be created and accessed from Java
+ * as well as JavaScript.
+ */
+
+import javax.script.*;
+
+public class JavaScriptScopeTest {
+
+        public static void main(String[] args) throws Exception {
+            ScriptEngineManager manager = new ScriptEngineManager();
+            ScriptEngine jsengine = manager.getEngineByName("js");
+            if (jsengine == null) {
+                throw new RuntimeException("no js engine found");
+            }
+            jsengine.eval("var v = 'hello';");
+            // Create a new scope
+            Bindings b = jsengine.createBindings();
+            // b is newly created scope. We don't expect 'v' there.
+            // we expect b to be empty...
+            if (b.keySet().size() != 0) {
+                throw new RuntimeException("no variables expected in new scope");
+            }
+
+            // verify that we can create new variable from Java
+            jsengine.put("fromJava", "hello world");
+            // below should execute without problems..
+            jsengine.eval(" if (fromJava != 'hello world') throw 'unexpected'");
+
+            // verify that script globals are exposed to Java
+            // we have created 'v' and 'fromJava' already.
+            if (! jsengine.get("v").equals("hello")) {
+                throw new RuntimeException("unexpected value of 'v'");
+            }
+
+            if (! jsengine.get("fromJava").equals("hello world")) {
+                throw new RuntimeException("unexpected value of 'fromJava'");
+            }
+        }
+}
diff --git a/test/javax/script/META-INF/services/javax.script.ScriptEngineFactory b/test/javax/script/META-INF/services/javax.script.ScriptEngineFactory
new file mode 100644
index 0000000..bc6a5b8
--- /dev/null
+++ b/test/javax/script/META-INF/services/javax.script.ScriptEngineFactory
@@ -0,0 +1,5 @@
+#
+
+# dummy script engine
+
+DummyScriptEngineFactory
diff --git a/test/javax/script/MyContext.java b/test/javax/script/MyContext.java
new file mode 100644
index 0000000..642cf84
--- /dev/null
+++ b/test/javax/script/MyContext.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * This is pluggable context used by test for 6398614
+ */
+
+import javax.script.*;
+import java.util.*;
+import java.io.*;
+
+public class MyContext  implements ScriptContext {
+
+    public static final int APP_SCOPE = 125;
+
+    protected Writer writer;
+
+    protected Writer errorWriter;
+
+    protected Reader reader;
+
+
+    protected Bindings appScope;
+    protected Bindings engineScope;
+    protected Bindings globalScope;
+
+
+    public MyContext() {
+        appScope = new SimpleBindings();
+        engineScope = new SimpleBindings();
+        globalScope = null;
+        reader = new InputStreamReader(System.in);
+        writer = new PrintWriter(System.out , true);
+        errorWriter = new PrintWriter(System.err, true);
+    }
+
+    public void setBindings(Bindings bindings, int scope) {
+
+        switch (scope) {
+            case APP_SCOPE:
+                if (bindings == null) {
+                    throw new NullPointerException("App scope cannot be null.");
+                }
+                appScope = bindings;
+                break;
+
+            case ENGINE_SCOPE:
+                if (bindings == null) {
+                    throw new NullPointerException("Engine scope cannot be null.");
+                }
+                engineScope = bindings;
+                break;
+            case GLOBAL_SCOPE:
+                globalScope = bindings;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid scope value.");
+        }
+    }
+
+    public Object getAttribute(String name) {
+        if (engineScope.containsKey(name)) {
+            return getAttribute(name, ENGINE_SCOPE);
+        } else if (appScope.containsKey(name)) {
+            return getAttribute(name, APP_SCOPE);
+        } else if (globalScope != null && globalScope.containsKey(name)) {
+            return getAttribute(name, GLOBAL_SCOPE);
+        }
+
+        return null;
+    }
+
+    public Object getAttribute(String name, int scope) {
+
+        switch (scope) {
+            case APP_SCOPE:
+                return appScope.get(name);
+
+            case ENGINE_SCOPE:
+                return engineScope.get(name);
+
+            case GLOBAL_SCOPE:
+                if (globalScope != null) {
+                    return globalScope.get(name);
+                }
+                return null;
+
+            default:
+                throw new IllegalArgumentException("Illegal scope value.");
+        }
+    }
+
+    public Object removeAttribute(String name, int scope) {
+
+        switch (scope) {
+            case APP_SCOPE:
+                if (getBindings(APP_SCOPE) != null) {
+                    return getBindings(APP_SCOPE).remove(name);
+                }
+                return null;
+
+
+            case ENGINE_SCOPE:
+                if (getBindings(ENGINE_SCOPE) != null) {
+                    return getBindings(ENGINE_SCOPE).remove(name);
+                }
+                return null;
+
+            case GLOBAL_SCOPE:
+                if (getBindings(GLOBAL_SCOPE) != null) {
+                    return getBindings(GLOBAL_SCOPE).remove(name);
+                }
+                return null;
+
+            default:
+                throw new IllegalArgumentException("Illegal scope value.");
+        }
+    }
+
+    public void setAttribute(String name, Object value, int scope) {
+
+        switch (scope) {
+            case APP_SCOPE:
+                appScope.put(name, value);
+                return;
+
+            case ENGINE_SCOPE:
+                engineScope.put(name, value);
+                return;
+
+            case GLOBAL_SCOPE:
+                if (globalScope != null) {
+                    globalScope.put(name, value);
+                }
+                return;
+
+            default:
+                throw new IllegalArgumentException("Illegal scope value.");
+        }
+    }
+
+    public Writer getWriter() {
+        return writer;
+    }
+
+    public Reader getReader() {
+        return reader;
+    }
+
+    public void setReader(Reader reader) {
+        this.reader = reader;
+    }
+
+    public void setWriter(Writer writer) {
+        this.writer = writer;
+    }
+
+    public Writer getErrorWriter() {
+        return errorWriter;
+    }
+
+    public void setErrorWriter(Writer writer) {
+        this.errorWriter = writer;
+    }
+
+    public int getAttributesScope(String name) {
+        if (engineScope.containsKey(name)) {
+            return ENGINE_SCOPE;
+        } else if (appScope.containsKey(name)) {
+            return APP_SCOPE;
+        } else if (globalScope != null && globalScope.containsKey(name)) {
+            return GLOBAL_SCOPE;
+        } else {
+            return -1;
+        }
+    }
+
+    public Bindings getBindings(int scope) {
+        if (scope == ENGINE_SCOPE) {
+            return engineScope;
+        } else if (scope == APP_SCOPE) {
+            return appScope;
+        } else if (scope == GLOBAL_SCOPE) {
+            return globalScope;
+        } else {
+            throw new IllegalArgumentException("Illegal scope value.");
+        }
+    }
+
+    public List<Integer> getScopes() {
+        return scopes;
+    }
+
+    private static List<Integer> scopes;
+    static {
+        scopes = new ArrayList<Integer>(3);
+        scopes.add(ENGINE_SCOPE);
+        scopes.add(APP_SCOPE);
+        scopes.add(GLOBAL_SCOPE);
+        scopes = Collections.unmodifiableList(scopes);
+    }
+}
diff --git a/test/javax/script/NullUndefinedVarTest.java b/test/javax/script/NullUndefinedVarTest.java
new file mode 100644
index 0000000..b07d5af
--- /dev/null
+++ b/test/javax/script/NullUndefinedVarTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6346732
+ * @summary should be able to assign null and undefined
+ * value to JavaScript global variables.
+ */
+
+import javax.script.*;
+
+public class NullUndefinedVarTest {
+
+        public static void main(String[] args) throws Exception {
+            ScriptEngineManager manager = new ScriptEngineManager();
+            ScriptEngine jsengine = manager.getEngineByName("js");
+            if (jsengine == null) {
+                throw new RuntimeException("no js engine found");
+            }
+            jsengine.eval("var n = null; " +
+                          "if (n !== null) throw 'expecting null';" +
+                          "var u = undefined; " +
+                          "if (u !== undefined) throw 'undefined expected';");
+        }
+}
diff --git a/test/javax/script/PluggableContextTest.java b/test/javax/script/PluggableContextTest.java
new file mode 100644
index 0000000..1e6f4fa
--- /dev/null
+++ b/test/javax/script/PluggableContextTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6398614
+ * @summary Create a user defined ScriptContext and check
+ * that script can access variables from non-standard scopes
+ */
+
+import javax.script.*;
+
+public class PluggableContextTest {
+    public static void main(String[] args) throws Exception {
+        ScriptEngineManager m = new ScriptEngineManager();
+        ScriptContext ctx = new MyContext();
+        ctx.setAttribute("x", "hello", MyContext.APP_SCOPE);
+        ScriptEngine e = m.getEngineByName("js");
+        // the following reference to 'x' throws exception
+        // if APP_SCOPE is not searched.
+        e.eval("x", ctx);
+    }
+}
diff --git a/test/javax/script/ProviderTest.java b/test/javax/script/ProviderTest.java
new file mode 100644
index 0000000..79d6f16
--- /dev/null
+++ b/test/javax/script/ProviderTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ *
+ *
+ * Unit test for testing script engine discovery.
+ */
+import javax.script.*;
+
+public class ProviderTest {
+    public static void main(String args[]) throws Exception {
+        ScriptEngineManager manager = new ScriptEngineManager();
+        ScriptEngine se = manager.getEngineByName("dummy");
+        if (se == null) {
+            throw new RuntimeException("can't locate dummy engine");
+        }
+        se = manager.getEngineByName("js");
+        if (se == null) {
+            throw new RuntimeException("can't locate JavaScript engine");
+        }
+    }
+}
diff --git a/test/javax/script/ProviderTest.sh b/test/javax/script/ProviderTest.sh
new file mode 100644
index 0000000..211d9ed
--- /dev/null
+++ b/test/javax/script/ProviderTest.sh
@@ -0,0 +1,50 @@
+#
+# Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# @test
+# @bug 6249843
+# @summary ScriptEngine provider unit test
+#
+# @build ProviderTest DummyScriptEngineFactory
+# @run shell ProviderTest.sh
+
+if [ "${TESTSRC}" = "" ]
+then
+  echo "TESTSRC not set.  Test cannot execute.  Failed."
+  exit 1
+fi
+
+. ${TESTSRC}/CommonSetup.sh
+
+echo "Creating JAR file ..."
+
+$JAR -cf ${TESTCLASSES}/dummy.jar \
+    -C ${TESTCLASSES} DummyScriptEngine.class \
+    -C ${TESTCLASSES} DummyScriptEngineFactory.class \
+    -C "${TESTSRC}" META-INF/services/javax.script.ScriptEngineFactory
+
+echo "Running test ..."
+
+$JAVA -classpath \
+  ${TESTCLASSES}${PS}${TESTCLASSES}/dummy.jar \
+  ProviderTest
diff --git a/test/javax/script/RhinoExceptionTest.java b/test/javax/script/RhinoExceptionTest.java
new file mode 100644
index 0000000..439b947
--- /dev/null
+++ b/test/javax/script/RhinoExceptionTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6474943
+ * @summary Test that Rhion exception messages are
+ * available from ScriptException.
+ */
+
+import java.io.*;
+import javax.script.*;
+
+public class RhinoExceptionTest {
+    private static final String ERROR_MSG = "error from JavaScript";
+
+    public static void main(String[] args) throws Exception {
+        ScriptEngineManager m = new ScriptEngineManager();
+        ScriptEngine engine = m.getEngineByName("js");
+        engine.put("msg", ERROR_MSG);
+        try {
+            engine.eval("throw new Error(msg);");
+        } catch (ScriptException exp) {
+            if (exp.getMessage().indexOf(ERROR_MSG) == -1) {
+                throw exp;
+            }
+        }
+        try {
+            engine.eval("throw (msg);");
+        } catch (ScriptException exp) {
+            if (exp.getMessage().indexOf(ERROR_MSG) == -1) {
+                throw exp;
+            }
+        }
+        try {
+            CompiledScript scr = ((Compilable)engine).compile("throw new Error(msg);");
+            scr.eval();
+        } catch (ScriptException exp) {
+            if (exp.getMessage().indexOf(ERROR_MSG) == -1) {
+                throw exp;
+            }
+        }
+        try {
+            CompiledScript scr = ((Compilable)engine).compile("throw msg;");
+            scr.eval();
+        } catch (ScriptException exp) {
+            if (exp.getMessage().indexOf(ERROR_MSG) == -1) {
+                throw exp;
+            }
+        }
+    }
+}
diff --git a/test/javax/script/Test1.java b/test/javax/script/Test1.java
new file mode 100644
index 0000000..fdfdef9
--- /dev/null
+++ b/test/javax/script/Test1.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6249843
+ * @summary Create JavaScript engine and execute a simple script.
+ * Tests script engine discovery mechanism.
+ */
+
+import javax.script.*;
+import java.io.*;
+
+public class Test1  {
+        public static void main(String[] args) throws Exception {
+            System.out.println("\nTest1\n");
+            ScriptEngineManager manager = new ScriptEngineManager();
+            ScriptEngine jsengine = manager.getEngineByName("js");
+            if (jsengine == null) {
+                throw new RuntimeException("no js engine found");
+            }
+            jsengine.eval(new FileReader(
+                     new File(System.getProperty("test.src", "."), "Test1.js")));
+        }
+}
diff --git a/test/javax/script/Test1.js b/test/javax/script/Test1.js
new file mode 100644
index 0000000..4e46efb
--- /dev/null
+++ b/test/javax/script/Test1.js
@@ -0,0 +1 @@
+print("Test1 passes");
diff --git a/test/javax/script/Test2.java b/test/javax/script/Test2.java
new file mode 100644
index 0000000..0a70eb1
--- /dev/null
+++ b/test/javax/script/Test2.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6249843
+ * @summary Test exposing a Java object to script
+ */
+
+import javax.script.*;
+import java.io.*;
+
+public class Test2 {
+        public static class Testobj {
+                private String val;
+                public Testobj(String s) {
+                        val = s;
+                }
+                public void setVal(String v) {
+                        val = v;
+                }
+                public String getVal() {
+                        return val;
+                }
+                public String toString() {
+                        return "Testobj containing " + val;
+                }
+        }
+
+        public static void main(String[] args) throws Exception {
+            System.out.println("\nTest2\n");
+            ScriptEngineManager m = new ScriptEngineManager();
+            ScriptEngine eng = m.getEngineByName("js");
+            eng.put("Testobj", new Testobj("Hello World"));
+            eng.eval(new FileReader(
+                    new File(System.getProperty("test.src", "."), "Test2.js")));
+        }
+}
diff --git a/test/javax/script/Test2.js b/test/javax/script/Test2.js
new file mode 100644
index 0000000..673a4e6
--- /dev/null
+++ b/test/javax/script/Test2.js
@@ -0,0 +1,9 @@
+if (Testobj.getVal() != 'Hello World') {
+    throw "unexpected value";
+}
+
+Testobj = "a string";
+if (Testobj.getVal != undefined ||
+    Testobj != 'a string') {
+    throw "can' change Testobj?";
+}
diff --git a/test/javax/script/Test3.java b/test/javax/script/Test3.java
new file mode 100644
index 0000000..84b610a
--- /dev/null
+++ b/test/javax/script/Test3.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6249843
+ * @summary Test engine and global scopes
+ */
+
+import javax.script.*;
+import java.io.*;
+import java.util.*;
+
+public class Test3 {
+        public static void main(String[] args) throws Exception {
+            System.out.println("\nTest3\n");
+            final Reader reader = new FileReader(
+                new File(System.getProperty("test.src", "."), "Test3.js"));
+            ScriptEngineManager m = new ScriptEngineManager();
+            final ScriptEngine engine = m.getEngineByName("js");
+            Bindings en = new SimpleBindings();
+            engine.setBindings(en, ScriptContext.ENGINE_SCOPE);
+            en.put("key", "engine value");
+            Bindings gn = new SimpleBindings();
+            engine.setBindings(gn, ScriptContext.GLOBAL_SCOPE);
+            gn.put("key", "global value");
+            engine.eval(reader);
+        }
+}
diff --git a/test/javax/script/Test3.js b/test/javax/script/Test3.js
new file mode 100644
index 0000000..4cdb828
--- /dev/null
+++ b/test/javax/script/Test3.js
@@ -0,0 +1,22 @@
+if (key == undefined || key != 'engine value') {
+    throw "unexpected engine scope value";
+}
+
+// pre-defined context variable refers to current ScriptContext
+if (context.getAttribute('key', context.GLOBAL_SCOPE) != 'global value') {
+    throw "unexpected global scope value";
+}
+
+// change the engine scope value
+key = 'new engine value';
+
+if (context.getAttribute('key', context.GLOBAL_SCOPE) != 'global value') {
+    throw "global scope should not change here";
+}
+
+// delete engine scope value
+delete key;
+
+if (key == undefined && key != 'xglobal value') {
+    throw 'global scope should be visible after engine scope removal';
+}
diff --git a/test/javax/script/Test4.java b/test/javax/script/Test4.java
new file mode 100644
index 0000000..bae2550
--- /dev/null
+++ b/test/javax/script/Test4.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6249843
+ * @summary Test script functions implementing Java interface
+ */
+
+import javax.script.*;
+import java.io.*;
+
+public class Test4 {
+        public static void main(String[] args) throws Exception {
+            System.out.println("\nTest4\n");
+            ScriptEngineManager m = new ScriptEngineManager();
+            ScriptEngine e  = m.getEngineByName("js");
+            e.eval(new FileReader(
+                new File(System.getProperty("test.src", "."), "Test4.js")));
+            Invocable inv = (Invocable)e;
+            Runnable run1 = (Runnable)inv.getInterface(Runnable.class);
+            run1.run();
+            // use methods of a specific script object
+            Object intfObj = e.get("intfObj");
+            Runnable run2 = (Runnable)inv.getInterface(intfObj, Runnable.class);
+            run2.run();
+        }
+}
diff --git a/test/javax/script/Test4.js b/test/javax/script/Test4.js
new file mode 100644
index 0000000..6c3c1f4
--- /dev/null
+++ b/test/javax/script/Test4.js
@@ -0,0 +1,7 @@
+function run() {
+    print("global run method");
+}
+
+var intfObj = {
+    run: function() { print("object run method"); }
+};
diff --git a/test/javax/script/Test5.java b/test/javax/script/Test5.java
new file mode 100644
index 0000000..cf32cff
--- /dev/null
+++ b/test/javax/script/Test5.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6249843
+ * @summary Tests engine, global scopes and scope hiding.
+ */
+
+import java.io.*;
+import javax.script.*;
+
+public class Test5 {
+        public static void main(String[] args) throws Exception {
+                System.out.println("\nTest5\n");
+                ScriptEngineManager m = new ScriptEngineManager();
+                ScriptEngine engine = m.getEngineByName("js");
+                Bindings g = new SimpleBindings();
+                Bindings e = new SimpleBindings();
+                g.put("key", "value in global");
+                e.put("key", "value in engine");
+                ScriptContext ctxt = new SimpleScriptContext();
+                ctxt.setBindings(e, ScriptContext.ENGINE_SCOPE);
+                System.out.println("engine scope only");
+                e.put("count", new Integer(1));
+
+                Reader reader = new FileReader(
+                    new File(System.getProperty("test.src", "."), "Test5.js"));
+                engine.eval(reader,ctxt);
+                System.out.println("both scopes");
+                ctxt.setBindings(g, ScriptContext.GLOBAL_SCOPE);
+                e.put("count", new Integer(2));
+                engine.eval(reader,ctxt);
+                System.out.println("only global");
+                e.put("count", new Integer(3));
+                ctxt.setAttribute("key", null, ScriptContext.ENGINE_SCOPE);
+                engine.eval(reader,ctxt);
+        }
+}
diff --git a/test/javax/script/Test5.js b/test/javax/script/Test5.js
new file mode 100644
index 0000000..c607cbc
--- /dev/null
+++ b/test/javax/script/Test5.js
@@ -0,0 +1,42 @@
+var key;
+var count;
+
+print(count);
+
+switch (count) {
+        // engine only
+	case 1:
+            if (key != 'value in engine') {
+                throw "unexpected engine scope value";
+            }
+            if (context.getAttribute("key", context.GLOBAL_SCOPE ) != null) {
+                throw "unexpected global scope value";
+            }
+            break;
+
+        // both scopes
+        case 2:
+            if (key != 'value in engine') {
+                throw "unexpected engine scope value";
+            }
+            if (context.getAttribute("key", context.GLOBAL_SCOPE ) != 
+                "value in global") {
+                throw "unexpected global scope value";
+            }
+            break;
+
+        // global only
+        case 3:
+            if (key != 'value in global') {
+                throw "unexpected global scope value";
+            }
+            if (context.getAttribute("key", context.GLOBAL_SCOPE ) != 
+                "value in global") {
+                throw "unexpected global scope value";
+            }
+            break;
+
+        default:
+            throw "unexpected count";
+            break;
+}
diff --git a/test/javax/script/Test6.java b/test/javax/script/Test6.java
new file mode 100644
index 0000000..15bbda1
--- /dev/null
+++ b/test/javax/script/Test6.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6249843
+ * @summary Test basic script compilation. Value eval'ed from
+ * compiled and interpreted scripts should be same.
+ */
+
+import java.io.*;
+import javax.script.*;
+
+public class Test6 {
+        public static void main(String[] args) throws Exception {
+            System.out.println("\nTest6\n");
+            ScriptEngineManager m = new ScriptEngineManager();
+            ScriptEngine engine = m.getEngineByName("js");
+            Reader reader = new FileReader(
+                new File(System.getProperty("test.src", "."), "Test6.js"));
+            engine.eval(reader);
+            Object res = engine.get("res");
+            CompiledScript scr = ((Compilable)engine).compile(reader);
+            scr.eval();
+            Object res1 = engine.get("res");
+            if (! res.equals(res1)) {
+                throw new RuntimeException("values not equal");
+            }
+        }
+}
diff --git a/test/javax/script/Test6.js b/test/javax/script/Test6.js
new file mode 100644
index 0000000..2a4fd4a
--- /dev/null
+++ b/test/javax/script/Test6.js
@@ -0,0 +1 @@
+var res = 45 + 34;
diff --git a/test/javax/script/Test7.java b/test/javax/script/Test7.java
new file mode 100644
index 0000000..9cdd8ac
--- /dev/null
+++ b/test/javax/script/Test7.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6249843
+ * @summary Tests importPackage and java access in script
+ */
+
+import java.io.*;
+import javax.script.*;
+
+public class Test7 {
+        public static void main(String[] args) throws Exception {
+            System.out.println("\nTest7\n");
+            File file =
+                new File(System.getProperty("test.src", "."), "Test7.js");
+            Reader r = new FileReader(file);
+            ScriptEngineManager m = new ScriptEngineManager();
+            ScriptEngine eng = m.getEngineByName("js");
+            eng.put("filename", file.getAbsolutePath());
+            eng.eval(r);
+            String str = (String)eng.get("firstLine");
+            // do not change first line in Test7.js -- we check it here!
+            if (!str.equals("//this is the first line of Test7.js")) {
+                throw new RuntimeException("unexpected first line");
+            }
+        }
+}
diff --git a/test/javax/script/Test7.js b/test/javax/script/Test7.js
new file mode 100644
index 0000000..b1ec2a8
--- /dev/null
+++ b/test/javax/script/Test7.js
@@ -0,0 +1,9 @@
+//this is the first line of Test7.js
+var filename;
+importPackage(java.io);
+importPackage(java);
+var f = new File(filename);
+var r = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
+
+var firstLine = r.readLine() + '';
+print(firstLine);
diff --git a/test/javax/script/Test8.java b/test/javax/script/Test8.java
new file mode 100644
index 0000000..80f0a6a
--- /dev/null
+++ b/test/javax/script/Test8.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6249843
+ * @summary Test invoking script function or method from Java
+ */
+
+import javax.script.*;
+import java.io.*;
+
+public class Test8 {
+        public static void main(String[] args) throws Exception {
+            System.out.println("\nTest8\n");
+            ScriptEngineManager m = new ScriptEngineManager();
+            ScriptEngine e  = m.getEngineByName("js");
+            e.eval(new FileReader(
+                new File(System.getProperty("test.src", "."), "Test8.js")));
+            Invocable inv = (Invocable)e;
+            inv.invokeFunction("main", "Mustang");
+            // use method of a specific script object
+            Object scriptObj = e.get("scriptObj");
+            inv.invokeMethod(scriptObj, "main", "Mustang");
+        }
+}
diff --git a/test/javax/script/Test8.js b/test/javax/script/Test8.js
new file mode 100644
index 0000000..70d4e77
--- /dev/null
+++ b/test/javax/script/Test8.js
@@ -0,0 +1,7 @@
+function main(name) {
+    print(name);
+}
+
+var scriptObj = {
+    main: function(name) { print(name); }
+};
diff --git a/test/javax/script/VersionTest.java b/test/javax/script/VersionTest.java
new file mode 100644
index 0000000..b4fc2fc
--- /dev/null
+++ b/test/javax/script/VersionTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6346729
+ * @summary Create JavaScript engine and check language and engine version
+ */
+
+import javax.script.*;
+import java.io.*;
+
+public class VersionTest  {
+
+        private static final String JS_LANG_VERSION = "1.6";
+        private static final String JS_ENGINE_VERSION = "1.6 release 2";
+
+        public static void main(String[] args) throws Exception {
+            ScriptEngineManager manager = new ScriptEngineManager();
+            ScriptEngine jsengine = manager.getEngineByName("js");
+            if (jsengine == null) {
+                throw new RuntimeException("no js engine found");
+            }
+            String langVersion = jsengine.getFactory().getLanguageVersion();
+            if (! langVersion.equals(JS_LANG_VERSION)) {
+                throw new RuntimeException("Expected JavaScript version is " +
+                            JS_LANG_VERSION);
+            }
+            String engineVersion = jsengine.getFactory().getEngineVersion();
+            if (! engineVersion.equals(JS_ENGINE_VERSION)) {
+                throw new RuntimeException("Expected Rhino version is " +
+                            JS_ENGINE_VERSION);
+            }
+        }
+}