nashorn/src/jdk/nashorn/api/scripting/JSObject.java
author lagergren
Thu, 10 Oct 2013 16:16:20 +0200
changeset 20933 89748612fd1d
parent 19889 63af9358d0dc
child 21450 419e5d51f319
permissions -rw-r--r--
8026250: Logging nullpointer bugfix and javadoc warnings Reviewed-by: hannesw, jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
17751
15a93d511eb7 8009141: Avoid netscape.javascript.JSObject in nashorn code
sundar
parents: 16151
diff changeset
    26
package jdk.nashorn.api.scripting;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    28
import java.util.Collection;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    29
import java.util.Collections;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    30
import java.util.Set;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    31
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    32
/**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    33
 * This is the base class for nashorn ScriptObjectMirror class.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    34
 *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    35
 * This class can also be subclassed by an arbitrary Java class. Nashorn will
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    36
 * treat objects of such classes just like nashorn script objects. Usual nashorn
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    37
 * operations like obj[i], obj.foo, obj.func(), delete obj.foo will be glued
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    38
 * to appropriate method call of this class.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
public abstract class JSObject {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    41
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    42
     * Call this object as a JavaScript function. This is equivalent to
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    43
     * 'func.apply(thiz, args)' in JavaScript.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    44
     *
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    45
     * @param thiz 'this' object to be passed to the function
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
     * @param args arguments to method
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
     * @return result of call
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
    49
    public Object call(final Object thiz, final Object... args) {
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    50
        throw new UnsupportedOperationException("call");
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    51
    }
18614
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    52
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    53
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    54
     * Call this 'constructor' JavaScript function to create a new object.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    55
     * This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
18614
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    56
     *
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    57
     * @param args arguments to method
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    58
     * @return result of constructor call
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    59
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
    60
    public Object newObject(final Object... args) {
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    61
        throw new UnsupportedOperationException("newObject");
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    62
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    65
     * Evaluate a JavaScript expression.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    66
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
     * @param s JavaScript expression to evaluate
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
     * @return evaluation result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
    70
    public Object eval(final String s) {
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    71
        throw new UnsupportedOperationException("eval");
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    72
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    73
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    75
     * Call a JavaScript function member of this object.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    76
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    77
     * @param name name of the member function to call
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    78
     * @param args arguments to be passed to the member function
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    79
     * @return result of call
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    80
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
    81
    public Object callMember(final String name, final Object... args) {
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    82
        throw new UnsupportedOperationException("call");
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    83
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    84
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    85
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    86
     * Retrieves a named member of this JavaScript object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
     * @param name of member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    89
     * @return member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
    91
    public Object getMember(final String name) {
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    92
        return null;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    93
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    94
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    95
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    96
     * Retrieves an indexed member of this JavaScript object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
     *
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    98
     * @param index index slot to retrieve
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    99
     * @return member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   101
    public Object getSlot(final int index) {
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   102
        return null;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   103
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   104
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   105
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   106
     * Does this object have a named member?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   107
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   108
     * @param name name of member
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   109
     * @return true if this object has a member of the given name
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   110
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   111
    public boolean hasMember(final String name) {
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   112
        return false;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   113
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   114
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   115
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   116
     * Does this object have a indexed property?
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   117
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   118
     * @param slot index to check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   119
     * @return true if this object has a slot
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   120
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   121
    public boolean hasSlot(final int slot) {
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   122
        return false;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   123
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   124
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   125
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   126
     * Remove a named member from this JavaScript object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   127
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   128
     * @param name name of the member
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   129
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   130
    public void removeMember(final String name) {
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   131
        //empty
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   132
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   133
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   134
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   135
     * Set a named member in this JavaScript object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   136
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   137
     * @param name  name of the member
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   138
     * @param value value of the member
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   139
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   140
    public void setMember(final String name, final Object value) {
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   141
        //empty
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   142
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   143
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   144
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   145
     * Set an indexed member in this JavaScript object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   146
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   147
     * @param index index of the member slot
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   148
     * @param value value of the member
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   149
     */
20933
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   150
    public void setSlot(final int index, final Object value) {
89748612fd1d 8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents: 19889
diff changeset
   151
        //empty
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   152
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   153
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   154
    // property and value iteration
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   155
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   156
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   157
     * Returns the set of all property names of this object.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   158
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   159
     * @return set of property names
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   160
     */
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   161
    @SuppressWarnings("unchecked")
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   162
    public Set<String> keySet() {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   163
        return Collections.EMPTY_SET;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   164
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   165
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   166
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   167
     * Returns the set of all property values of this object.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   168
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   169
     * @return set of property values.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   170
     */
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   171
    @SuppressWarnings("unchecked")
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   172
    public Collection<Object> values() {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   173
        return Collections.EMPTY_SET;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   174
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   175
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   176
    // JavaScript instanceof check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   177
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   178
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   179
     * Checking whether the given object is an instance of 'this' object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   180
     *
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   181
     * @param instance instace to check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   182
     * @return true if the given 'instance' is an instance of this 'function' object
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   183
     */
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   184
    public boolean isInstance(final Object instance) {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   185
        return false;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   186
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   187
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   188
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   189
     * Checking whether this object is an instance of the given 'clazz' object.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   190
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   191
     * @param clazz clazz to check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   192
     * @return true if this object is an instance of the given 'clazz'
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   193
     */
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   194
    public boolean isInstanceOf(final Object clazz) {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   195
        if (clazz instanceof JSObject) {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   196
            return ((JSObject)clazz).isInstance(this);
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   197
        }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   198
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   199
        return false;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   200
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   201
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   202
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   203
     * ECMA [[Class]] property
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   204
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   205
     * @return ECMA [[Class]] property value of this object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   206
     */
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   207
    public String getClassName() {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   208
        return getClass().getName();
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   209
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   210
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   211
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   212
     * Is this a function object?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   213
     *
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   214
     * @return if this mirror wraps a ECMAScript function instance
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   215
     */
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   216
    public boolean isFunction() {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   217
        return false;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   218
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   219
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   220
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   221
     * Is this a 'use strict' function object?
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   222
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   223
     * @return true if this mirror represents a ECMAScript 'use strict' function
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   224
     */
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   225
    public boolean isStrictFunction() {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   226
        return false;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   227
    }
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   228
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   229
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   230
     * Is this an array object?
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   231
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   232
     * @return if this mirror wraps a ECMAScript array object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   233
     */
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   234
    public boolean isArray() {
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   235
        return false;
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   236
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   237
}