src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/JSObject.java
author sundar
Thu, 28 Jun 2018 18:04:19 +0530
changeset 50878 fb7800b66c92
parent 47216 71c04702a3d5
permissions -rw-r--r--
8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs Reviewed-by: jlaskey, hannesw
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
 *
50878
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    38
 * @deprecated Nashorn JavaScript script engine and APIs, and the jjs tool
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    39
 * are deprecated with the intent to remove them in a future release.
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    40
 *
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
    41
 * @since 1.8u40
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
 */
50878
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    43
@Deprecated(since="11", forRemoval=true)
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    44
public interface JSObject {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    45
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    46
     * 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
    47
     * 'func.apply(thiz, args)' in JavaScript.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
     *
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
    49
     * @param thiz 'this' object to be passed to the function. This may be null.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
     * @param args arguments to method
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
     * @return result of call
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    53
    public Object call(final Object thiz, final Object... args);
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
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    56
     * 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
    57
     * This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
18614
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    58
     *
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    59
     * @param args arguments to method
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    60
     * @return result of constructor call
addca7a10167 8015959: Can't call foreign constructor
sundar
parents: 17751
diff changeset
    61
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    62
    public Object newObject(final Object... args);
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
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
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
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    72
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    73
     * Retrieves a named member of this JavaScript object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
     * @param name of member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
     * @return member
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
    77
     * @throws NullPointerException if name is null
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    78
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    79
    public Object getMember(final String name);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    80
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    82
     * Retrieves an indexed member of this JavaScript object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
     *
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    84
     * @param index index slot to retrieve
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
     * @return member
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    87
    public Object getSlot(final int index);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    89
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    90
     * Does this object have a named member?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
     * @param name name of member
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    93
     * @return true if this object has a member of the given name
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    94
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
    95
    public boolean hasMember(final String name);
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    96
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    97
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    98
     * Does this object have a indexed property?
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
    99
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   100
     * @param slot index to check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   101
     * @return true if this object has a slot
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   102
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   103
    public boolean hasSlot(final int slot);
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   104
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   105
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   106
     * Remove a named member from this JavaScript object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   107
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   108
     * @param name name of the member
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
   109
     * @throws NullPointerException if name is null
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   110
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   111
    public void removeMember(final String name);
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   112
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
     * Set a named member in this JavaScript object
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
     * @param name  name of the member
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   117
     * @param value value of the member
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 34903
diff changeset
   118
     * @throws NullPointerException if name is null
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   119
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   120
    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
   121
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   122
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   123
     * Set an indexed member in this JavaScript object
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
     * @param index index of the member slot
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   126
     * @param value value of the member
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   127
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   128
    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
   129
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   130
    // property and value iteration
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   131
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
     * 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
   134
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   135
     * @return set of property names
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   136
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   137
    public Set<String> keySet();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   138
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   139
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   140
     * 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
   141
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   142
     * @return set of property values.
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   143
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   144
    public Collection<Object> values();
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   145
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   146
    // JavaScript instanceof check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   147
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   148
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   149
     * Checking whether the given object is an instance of 'this' object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   150
     *
31738
5ad3dfcf3507 8130888: Typos in nashorn sources
sundar
parents: 29133
diff changeset
   151
     * @param instance instance to check
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   152
     * @return true if the given 'instance' is an instance of this 'function' object
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   153
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   154
    public boolean isInstance(final Object instance);
19889
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
     * 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
   158
     *
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   159
     * @param clazz clazz to check
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   160
     * @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
   161
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   162
    public boolean isInstanceOf(final Object clazz);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   163
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   164
    /**
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   165
     * ECMA [[Class]] property
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
     * @return ECMA [[Class]] property value of this object
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   168
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   169
    public String getClassName();
19889
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
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   172
     * Is this a function object?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   173
     *
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   174
     * @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
   175
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   176
    public boolean isFunction();
19889
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
     * Is this a 'use strict' function object?
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
     * @return true if this mirror represents a ECMAScript 'use strict' function
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   182
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   183
    public boolean isStrictFunction();
19889
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   184
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   185
    /**
63af9358d0dc 8024615: Refactor ScriptObjectMirror and JSObject to support external JSObject implementations
sundar
parents: 18614
diff changeset
   186
     * Is this an array object?
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
     * @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
   189
     */
21453
b48953eede53 8027128: jdk.nashorn.api.scripting.JSObject should be an interface
sundar
parents: 21450
diff changeset
   190
    public boolean isArray();
21450
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   191
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   192
    /**
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   193
     * Returns this object's numeric value.
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   194
     *
419e5d51f319 8027037: Make ScriptObjectMirror conversions work for any JSObject
attila
parents: 20933
diff changeset
   195
     * @return this object's numeric value.
29133
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   196
     * @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
   197
     */
29133
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   198
    @Deprecated
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   199
    default double toNumber() {
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   200
        return JSType.toNumber(JSType.toPrimitive(this, Number.class));
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
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   203
    /**
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   204
     * 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
   205
     *
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   206
     * @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
   207
     * @return this object's default value.
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   208
     * @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
   209
     * exception into a JavaScript {@code TypeError}.
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   210
     */
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   211
    default Object getDefaultValue(final Class<?> hint) throws UnsupportedOperationException {
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   212
        return DefaultValueImpl.getDefaultValue(this, hint);
1cd7d8af99ba 8072426: Can't compare Java objects to strings or numbers
attila
parents: 28317
diff changeset
   213
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   214
}