src/jdk.jsobject/share/classes/netscape/javascript/JSObject.java
author stefank
Mon, 28 Oct 2019 11:24:11 +0100
changeset 58812 4adca7312d8f
parent 57521 d0c2e34bae88
permissions -rw-r--r--
8232649: ZGC: Add callbacks to ZMemoryManager Reviewed-by: pliden, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36252
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     1
/*
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     2
 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     4
 *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    10
 *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    15
 * accompanied this code).
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    16
 *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    20
 *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    23
 * questions.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    24
 */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    25
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    26
package netscape.javascript;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    27
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    28
import java.security.AccessController;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    29
import java.security.PrivilegedAction;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    30
import java.util.Iterator;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    31
import java.util.ServiceLoader;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    32
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    33
/**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    34
 * <p>
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    35
 * Allows Java code to manipulate JavaScript objects.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    36
 * </p>
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    37
 *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    38
 * <p>
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    39
 * When a JavaScript object is passed or returned to Java code, it
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    40
 * is wrapped in an instance of {@code JSObject}. When a
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    41
 * {@code JSObject} instance is passed to the JavaScript engine,
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    42
 * it is unwrapped back to its original JavaScript object. The
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    43
 * {@code JSObject} class provides a way to invoke JavaScript
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    44
 * methods and examine JavaScript properties.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    45
 * </p>
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    46
 *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    47
 * <p> Any data returned from the JavaScript engine to Java is
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    48
 * converted to Java data types. Certain data passed to the JavaScript
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    49
 * engine is converted to JavaScript data types.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    50
 * </p>
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    51
 *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    52
 */
38470
6dd62dab450d 8157622: Add @Deprecated annotations to the Applet API classes
dtitov
parents: 36252
diff changeset
    53
@SuppressWarnings("deprecation")
36252
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    54
public abstract class JSObject {
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    55
    /**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    56
     * Constructs a new JSObject. Users should neither call this method nor
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    57
     * subclass JSObject.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    58
     */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    59
    protected JSObject()  {
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    60
    }
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    61
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    62
    /**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    63
     * Calls a JavaScript method. Equivalent to
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    64
     * "this.methodName(args[0], args[1], ...)" in JavaScript.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    65
     *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    66
     * @param methodName The name of the JavaScript method to be invoked.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    67
     * @param args the Java objects passed as arguments to the method.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    68
     * @return Result of the method.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    69
     * @throws JSException when an error is reported from the browser or
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    70
     * JavaScript engine.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    71
     */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    72
    public abstract Object call(String methodName, Object... args) throws JSException;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    73
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    74
    /**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    75
     * Evaluates a JavaScript expression. The expression is a string of
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    76
     * JavaScript source code which will be evaluated in the context given by
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    77
     * "this".
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    78
     *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    79
     * @param s The JavaScript expression.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    80
     * @return Result of the JavaScript evaluation.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    81
     * @throws JSException when an error is reported from the browser or
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    82
     * JavaScript engine.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    83
     */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    84
    public abstract Object eval(String s) throws JSException;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    85
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    86
    /**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    87
     * Retrieves a named member of a JavaScript object. Equivalent to
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    88
     * "this.name" in JavaScript.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    89
     *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    90
     * @param name The name of the JavaScript property to be accessed.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    91
     * @return The value of the propery.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    92
     * @throws JSException when an error is reported from the browser or
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    93
     * JavaScript engine.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    94
     */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    95
    public abstract Object getMember(String name) throws JSException;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    96
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    97
    /**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    98
     * Sets a named member of a JavaScript object. Equivalent to
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
    99
     * "this.name = value" in JavaScript.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   100
     *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   101
     * @param name The name of the JavaScript property to be accessed.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   102
     * @param value The value of the propery.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   103
     * @throws JSException when an error is reported from the browser or
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   104
     * JavaScript engine.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   105
     */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   106
    public abstract void setMember(String name, Object value) throws JSException;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   107
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   108
    /**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   109
     * Removes a named member of a JavaScript object. Equivalent
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   110
     * to "delete this.name" in JavaScript.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   111
     *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   112
     * @param name The name of the JavaScript property to be removed.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   113
     * @throws JSException when an error is reported from the browser or
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   114
     * JavaScript engine.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   115
     */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   116
    public abstract void removeMember(String name) throws JSException;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   117
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   118
    /**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   119
     * Retrieves an indexed member of a JavaScript object. Equivalent to
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   120
     * "this[index]" in JavaScript.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   121
     *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   122
     * @param index The index of the array to be accessed.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   123
     * @return The value of the indexed member.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   124
     * @throws JSException when an error is reported from the browser or
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   125
     * JavaScript engine.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   126
     */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   127
    public abstract Object getSlot(int index) throws JSException;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   128
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   129
    /**
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   130
     * Sets an indexed member of a JavaScript object. Equivalent to
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   131
     * "this[index] = value" in JavaScript.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   132
     *
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   133
     * @param index The index of the array to be accessed.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   134
     * @param value The value to set
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   135
     * @throws JSException when an error is reported from the browser or
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   136
     * JavaScript engine.
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   137
     */
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   138
    public abstract void setSlot(int index, Object value) throws JSException;
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   139
f66a8dabc67b 8132743: Move netscape.javascript package from jdk.plugin to new module
ddehaven
parents:
diff changeset
   140
}