8132743: Move netscape.javascript package from jdk.plugin to new module
authorddehaven
Thu, 25 Feb 2016 15:42:01 -0800
changeset 36252 f66a8dabc67b
parent 36251 e909478d3e1d
child 36253 652d06266511
8132743: Move netscape.javascript package from jdk.plugin to new module Reviewed-by: kcr, mchung, alanb
jdk/make/src/classes/build/tools/module/boot.modules
jdk/src/jdk.jsobject/share/classes/jdk/internal/netscape/javascript/spi/JSObjectProvider.java
jdk/src/jdk.jsobject/share/classes/netscape/javascript/JSException.java
jdk/src/jdk.jsobject/share/classes/netscape/javascript/JSObject.java
jdk/src/jdk.jsobject/share/classes/netscape/javascript/package-info.java
--- a/jdk/make/src/classes/build/tools/module/boot.modules	Mon Mar 07 19:37:10 2016 +0000
+++ b/jdk/make/src/classes/build/tools/module/boot.modules	Thu Feb 25 15:42:01 2016 -0800
@@ -22,6 +22,7 @@
 jdk.deploy.osx
 jdk.httpserver
 jdk.jfr
+jdk.jsobject
 jdk.net
 jdk.vm.cds
 jdk.vm.ci
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.jsobject/share/classes/jdk/internal/netscape/javascript/spi/JSObjectProvider.java	Thu Feb 25 15:42:01 2016 -0800
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2016, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+package jdk.internal.netscape.javascript.spi;
+
+import java.applet.Applet;
+import netscape.javascript.JSException;
+import netscape.javascript.JSObject;
+
+public interface JSObjectProvider {
+    /**
+     * Return a JSObject for the window containing the given applet.
+     * Implementations of this class should return null if not connected to a
+     * browser, for example, when running in AppletViewer.
+     *
+     * @param applet The applet.
+     * @return JSObject for the window containing the given applet or null if we
+     * are not connected to a browser.
+     * @throws JSException when an error is encountered.
+     */
+    public JSObject getWindow(Applet applet) throws JSException;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.jsobject/share/classes/netscape/javascript/JSException.java	Thu Feb 25 15:42:01 2016 -0800
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2006, 2016, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+package netscape.javascript;
+
+/**
+ * Thrown when an exception is raised in the JavaScript engine. This is merely
+ * a marker class to indicate an exception relating to the JavaScript
+ * interface.
+ */
+public class JSException extends RuntimeException {
+    private static final long serialVersionUID = 2778103758223661489L;
+
+    /**
+     * Constructs a new JavaScript exception with null as it's detail message.
+     */
+    public JSException() {
+        super();
+    }
+
+    /**
+     * Construct a new JavaScript exception with the specified detail message.
+     *
+     * @param s The detail message
+     */
+    public JSException(String s) {
+        super(s);
+    }
+
+    /**
+     * Construct a new JavaScript exception with the specified cause.
+     *
+     * @param t Throwable cause
+     */
+    public JSException(Throwable t) {
+        super(t);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.jsobject/share/classes/netscape/javascript/JSObject.java	Thu Feb 25 15:42:01 2016 -0800
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2006, 2016, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+package netscape.javascript;
+
+import jdk.internal.netscape.javascript.spi.JSObjectProvider;
+import java.applet.Applet;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+/**
+ * <p>
+ * Allows Java code to manipulate JavaScript objects.
+ * </p>
+ *
+ * <p>
+ * When a JavaScript object is passed or returned to Java code, it
+ * is wrapped in an instance of {@code JSObject}. When a
+ * {@code JSObject} instance is passed to the JavaScript engine,
+ * it is unwrapped back to its original JavaScript object. The
+ * {@code JSObject} class provides a way to invoke JavaScript
+ * methods and examine JavaScript properties.
+ * </p>
+ *
+ * <p> Any data returned from the JavaScript engine to Java is
+ * converted to Java data types. Certain data passed to the JavaScript
+ * engine is converted to JavaScript data types.
+ * </p>
+ *
+ */
+public abstract class JSObject {
+    /**
+     * Constructs a new JSObject. Users should neither call this method nor
+     * subclass JSObject.
+     */
+    protected JSObject()  {
+    }
+
+    /**
+     * Calls a JavaScript method. Equivalent to
+     * "this.methodName(args[0], args[1], ...)" in JavaScript.
+     *
+     * @param methodName The name of the JavaScript method to be invoked.
+     * @param args the Java objects passed as arguments to the method.
+     * @return Result of the method.
+     * @throws JSException when an error is reported from the browser or
+     * JavaScript engine.
+     */
+    public abstract Object call(String methodName, Object... args) throws JSException;
+
+    /**
+     * Evaluates a JavaScript expression. The expression is a string of
+     * JavaScript source code which will be evaluated in the context given by
+     * "this".
+     *
+     * @param s The JavaScript expression.
+     * @return Result of the JavaScript evaluation.
+     * @throws JSException when an error is reported from the browser or
+     * JavaScript engine.
+     */
+    public abstract Object eval(String s) throws JSException;
+
+    /**
+     * Retrieves a named member of a JavaScript object. Equivalent to
+     * "this.name" in JavaScript.
+     *
+     * @param name The name of the JavaScript property to be accessed.
+     * @return The value of the propery.
+     * @throws JSException when an error is reported from the browser or
+     * JavaScript engine.
+     */
+    public abstract Object getMember(String name) throws JSException;
+
+    /**
+     * Sets a named member of a JavaScript object. Equivalent to
+     * "this.name = value" in JavaScript.
+     *
+     * @param name The name of the JavaScript property to be accessed.
+     * @param value The value of the propery.
+     * @throws JSException when an error is reported from the browser or
+     * JavaScript engine.
+     */
+    public abstract void setMember(String name, Object value) throws JSException;
+
+    /**
+     * Removes a named member of a JavaScript object. Equivalent
+     * to "delete this.name" in JavaScript.
+     *
+     * @param name The name of the JavaScript property to be removed.
+     * @throws JSException when an error is reported from the browser or
+     * JavaScript engine.
+     */
+    public abstract void removeMember(String name) throws JSException;
+
+    /**
+     * Retrieves an indexed member of a JavaScript object. Equivalent to
+     * "this[index]" in JavaScript.
+     *
+     * @param index The index of the array to be accessed.
+     * @return The value of the indexed member.
+     * @throws JSException when an error is reported from the browser or
+     * JavaScript engine.
+     */
+    public abstract Object getSlot(int index) throws JSException;
+
+    /**
+     * Sets an indexed member of a JavaScript object. Equivalent to
+     * "this[index] = value" in JavaScript.
+     *
+     * @param index The index of the array to be accessed.
+     * @param value The value to set
+     * @throws JSException when an error is reported from the browser or
+     * JavaScript engine.
+     */
+    public abstract void setSlot(int index, Object value) throws JSException;
+
+    /**
+     * Returns a JSObject for the window containing the given applet. This
+     * method only works when the Java code is running in a browser as an
+     * applet. The object returned may be used to access the HTML DOM directly.
+     *
+     * @param applet The applet.
+     * @return JSObject representing the window containing the given applet or
+     * {@code null} if we are not connected to a browser.
+     * @throws JSException when an error is reported from the browser or
+     * JavaScript engine or if applet is {@code null}
+     */
+    public static JSObject getWindow(Applet applet) throws JSException {
+        return ProviderLoader.callGetWindow(applet);
+    }
+
+    private static class ProviderLoader {
+        private static final JSObjectProvider provider;
+
+        static {
+            provider = AccessController.doPrivileged(
+                new PrivilegedAction<>() {
+                    @Override
+                    public JSObjectProvider run() {
+                        Iterator<JSObjectProvider> providers =
+                            ServiceLoader.loadInstalled(JSObjectProvider.class).iterator();
+                        if (providers.hasNext()) {
+                            return providers.next();
+                        }
+                        return null;
+                    }
+                }
+            );
+        }
+
+        private static JSObject callGetWindow(Applet applet) {
+            if (provider != null) {
+                return provider.getWindow(applet);
+            }
+            return null;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.jsobject/share/classes/netscape/javascript/package-info.java	Thu Feb 25 15:42:01 2016 -0800
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008, 2016, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+/**
+ * <p>
+ * Provides Java code the ability to access the JavaScript engine and the
+ * HTML DOM in the web browser.
+ * </p>
+ *
+ * <p>
+ * The classes in this package were initially specified by Netscape, and are the
+ * de facto standard mechanism for calling JavaScript from the Java runtime.
+ * </p>
+ */
+
+package netscape.javascript;