nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/JSObject.java
author sundar
Thu, 25 Feb 2016 13:56:23 +0530
changeset 36141 696d662bcdb7
parent 34903 0a5536ef0eec
permissions -rw-r--r--
8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications Reviewed-by: hannesw, mhaupt
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.Set;
29133
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
    30
import jdk.nashorn.internal.runtime.JSType;
19889
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
/**
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    33
 * This interface can be implemented by an arbitrary Java class. Nashorn will
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    34
 * treat objects of such classes just like nashorn script objects. Usual nashorn
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
    35
 * operations like obj[i], obj.foo, obj.func(), delete obj.foo will be delegated
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    36
 * to appropriate method call of this interface.
28317
0aeeae75e696 8068431: @since and @jdk.Exported are missing in jdk.nashorn.api.scripting classes and package-info.java files
sundar
parents: 25865
diff changeset
    37
 *
0aeeae75e696 8068431: @since and @jdk.Exported are missing in jdk.nashorn.api.scripting classes and package-info.java files
sundar
parents: 25865
diff changeset
    38
 * @since 1.8u40
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
 */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    40
public interface JSObject {
16147
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
     *
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
    45
     * @param thiz 'this' object to be passed to the function. This may be null.
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
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    49
    public Object call(final Object thiz, final Object... args);
18614
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    50
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    51
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    52
     * 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
    53
     * This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
18614
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    54
     *
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    55
     * @param args arguments to method
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    56
     * @return result of constructor call
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    57
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    58
    public Object newObject(final Object... args);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    60
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    61
     * Evaluate a JavaScript expression.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
     * @param s JavaScript expression to evaluate
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
     * @return evaluation result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    65
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    66
    public Object eval(final String s);
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    67
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    68
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    69
     * Retrieves a named member of this JavaScript object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
     * @param name of member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
     * @return member
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
    73
     * @throws NullPointerException if name is null
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    75
    public Object getMember(final String name);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    77
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    78
     * Retrieves an indexed member of this JavaScript object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    79
     *
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    80
     * @param index index slot to retrieve
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
     * @return member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    82
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    83
    public Object getSlot(final int index);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    86
     * Does this object have a named member?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
     * @param name name of member
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    89
     * @return true if this object has a member of the given name
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    91
    public boolean hasMember(final String name);
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    92
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    93
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    94
     * Does this object have a indexed property?
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    95
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    96
     * @param slot index to check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    97
     * @return true if this object has a slot
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    98
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    99
    public boolean hasSlot(final int slot);
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   100
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   101
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   102
     * Remove a named member from this JavaScript object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   103
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   104
     * @param name name of the member
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
   105
     * @throws NullPointerException if name is null
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   106
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   107
    public void removeMember(final String name);
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   108
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   109
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   110
     * Set a named member in this JavaScript object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   111
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   112
     * @param name  name of the member
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   113
     * @param value value of the member
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
   114
     * @throws NullPointerException if name is null
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   115
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   116
    public void setMember(final String name, final Object value);
19889
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
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   119
     * Set an indexed member in this JavaScript object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   120
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   121
     * @param index index of the member slot
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   122
     * @param value value of the member
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   123
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   124
    public void setSlot(final int index, final Object value);
19889
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
    // property and value iteration
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
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   129
     * 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
   130
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   131
     * @return set of property names
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   132
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   133
    public Set<String> keySet();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   134
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   135
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   136
     * 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
   137
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   138
     * @return set of property values.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   139
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   140
    public Collection<Object> values();
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   141
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   142
    // JavaScript instanceof check
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
     * Checking whether the given object is an instance of 'this' object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   146
     *
31738
5ad3dfcf3507 8130888: Typos in nashorn sources
sundar
parents: 29133
diff changeset
   147
     * @param instance instance to check
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   148
     * @return true if the given 'instance' is an instance of this 'function' object
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   149
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   150
    public boolean isInstance(final Object instance);
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   151
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
     * 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
   154
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   155
     * @param clazz clazz to check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   156
     * @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
   157
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   158
    public boolean isInstanceOf(final Object clazz);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   159
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   160
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   161
     * ECMA [[Class]] property
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   162
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   163
     * @return ECMA [[Class]] property value of this object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   164
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   165
    public String getClassName();
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   166
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   167
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   168
     * Is this a function object?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   169
     *
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   170
     * @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
   171
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   172
    public boolean isFunction();
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   173
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
     * Is this a 'use strict' function object?
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   176
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   177
     * @return true if this mirror represents a ECMAScript 'use strict' function
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   178
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   179
    public boolean isStrictFunction();
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   180
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   181
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   182
     * Is this an array object?
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   183
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   184
     * @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
   185
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   186
    public boolean isArray();
21450
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   187
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   188
    /**
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   189
     * Returns this object's numeric value.
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   190
     *
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   191
     * @return this object's numeric value.
29133
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   192
     * @deprecated use {@link #getDefaultValue(Class)} with {@link Number} hint instead.
21450
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   193
     */
29133
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   194
    @Deprecated
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   195
    default double toNumber() {
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   196
        return JSType.toNumber(JSType.toPrimitive(this, Number.class));
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   197
    }
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   198
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   199
    /**
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   200
     * Implements this object's {@code [[DefaultValue]]} method as per ECMAScript 5.1 section 8.6.2.
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   201
     *
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   202
     * @param hint the type hint. Should be either {@code null}, {@code Number.class} or {@code String.class}.
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   203
     * @return this object's default value.
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   204
     * @throws UnsupportedOperationException if the conversion can't be performed. The engine will convert this
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   205
     * exception into a JavaScript {@code TypeError}.
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   206
     */
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   207
    default Object getDefaultValue(final Class<?> hint) throws UnsupportedOperationException {
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   208
        return DefaultValueImpl.getDefaultValue(this, hint);
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   209
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   210
}