AbstractJSObject.java revision 1209:36fbf759ab8d
131567Ssef/*
231899Ssef * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
331899Ssef * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
431899Ssef *
531899Ssef * This code is free software; you can redistribute it and/or modify it
631899Ssef * under the terms of the GNU General Public License version 2 only, as
731899Ssef * published by the Free Software Foundation.  Oracle designates this
831899Ssef * particular file as subject to the "Classpath" exception as provided
931899Ssef * by Oracle in the LICENSE file that accompanied this code.
1031899Ssef *
1131899Ssef * This code is distributed in the hope that it will be useful, but WITHOUT
1231899Ssef * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1331899Ssef * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1431899Ssef * version 2 for more details (a copy is included in the LICENSE file that
1531899Ssef * accompanied this code).
1631899Ssef *
1731899Ssef * You should have received a copy of the GNU General Public License version
1831899Ssef * 2 along with this work; if not, write to the Free Software Foundation,
1931899Ssef * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2031899Ssef *
2131899Ssef * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2231899Ssef * or visit www.oracle.com if you need additional information or have any
2331899Ssef * questions.
2431899Ssef */
2531899Ssef
2631899Ssefpackage jdk.nashorn.api.scripting;
2731899Ssef
2831899Ssefimport java.util.Collection;
2931899Ssefimport java.util.Collections;
3031899Ssefimport java.util.Set;
3131899Ssef
3232275Scharnier/**
3332275Scharnier * This is the base class for nashorn ScriptObjectMirror class.
3450477Speter *
3532275Scharnier * This class can also be subclassed by an arbitrary Java class. Nashorn will
3632275Scharnier * treat objects of such classes just like nashorn script objects. Usual nashorn
3731899Ssef * operations like obj[i], obj.foo, obj.func(), delete obj.foo will be glued
3831567Ssef * to appropriate method call of this class.
3931567Ssef *
4031567Ssef * @since 1.8u40
4131567Ssef */
42127328Salfred@jdk.Exported
4385292Sdespublic abstract class AbstractJSObject implements JSObject {
44168569Sdelphij    /**
4585292Sdes     * Call this object as a JavaScript function. This is equivalent to
46104581Smike     * 'func.apply(thiz, args)' in JavaScript.
4785292Sdes     *
4885292Sdes     * @param thiz 'this' object to be passed to the function
4985292Sdes     * @param args arguments to method
50158630Spav     * @return result of call
51158630Spav     */
52158630Spav    @Override
53158630Spav    public Object call(final Object thiz, final Object... args) {
54158630Spav        throw new UnsupportedOperationException("call");
55158630Spav    }
56158630Spav
5785292Sdes    /**
5886138Sgreen     * Call this 'constructor' JavaScript function to create a new object.
5932275Scharnier     * This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
60127328Salfred     *
61127332Sdwmalone     * @param args arguments to method
6285292Sdes     * @return result of constructor call
63127332Sdwmalone     */
6431567Ssef    @Override
6531567Ssef    public Object newObject(final Object... args) {
6631567Ssef        throw new UnsupportedOperationException("newObject");
67101423Smdodd    }
6831567Ssef
69158630Spav    /**
7085292Sdes     * Evaluate a JavaScript expression.
71101282Smdodd     *
7287703Smarkm     * @param s JavaScript expression to evaluate
7331567Ssef     * @return evaluation result
7431567Ssef     */
75171646Smarcel    @Override
76171646Smarcel    public Object eval(final String s) {
77171646Smarcel        throw new UnsupportedOperationException("eval");
78171646Smarcel    }
79171646Smarcel
80171646Smarcel    /**
81171646Smarcel     * Retrieves a named member of this JavaScript object.
82171646Smarcel     *
83171646Smarcel     * @param name of member
84171646Smarcel     * @return member
85171646Smarcel     */
86171646Smarcel    @Override
87171646Smarcel    public Object getMember(final String name) {
88171646Smarcel        return null;
8931567Ssef    }
90158630Spav
9131567Ssef    /**
9231567Ssef     * Retrieves an indexed member of this JavaScript object.
93192025Sdds     *
94192025Sdds     * @param index index slot to retrieve
95200751Sjh     * @return member
96200751Sjh     */
97200751Sjh    @Override
98200751Sjh    public Object getSlot(final int index) {
99200751Sjh        return null;
100200751Sjh    }
101200751Sjh
102200751Sjh    /**
103200751Sjh     * Does this object have a named member?
104200751Sjh     *
105200751Sjh     * @param name name of member
106200751Sjh     * @return true if this object has a member of the given name
107192025Sdds     */
108192025Sdds    @Override
109192025Sdds    public boolean hasMember(final String name) {
110192025Sdds        return false;
111192025Sdds    }
112192025Sdds
113192025Sdds    /**
114192025Sdds     * Does this object have a indexed property?
115192025Sdds     *
116192025Sdds     * @param slot index to check
117192025Sdds     * @return true if this object has a slot
118192025Sdds     */
119192025Sdds    @Override
120192025Sdds    public boolean hasSlot(final int slot) {
121192025Sdds        return false;
122192025Sdds    }
123192025Sdds
124192025Sdds    /**
125192025Sdds     * Remove a named member from this JavaScript object
126192025Sdds     *
127192025Sdds     * @param name name of the member
128192025Sdds     */
129192025Sdds    @Override
130192025Sdds    public void removeMember(final String name) {
131192025Sdds        //empty
132192025Sdds    }
133192025Sdds
134192025Sdds    /**
135192025Sdds     * Set a named member in this JavaScript object
136192025Sdds     *
137192025Sdds     * @param name  name of the member
138192025Sdds     * @param value value of the member
139192025Sdds     */
140192025Sdds    @Override
141192025Sdds    public void setMember(final String name, final Object value) {
142192025Sdds        //empty
143192025Sdds    }
144192025Sdds
145192025Sdds    /**
146192025Sdds     * Set an indexed member in this JavaScript object
147192025Sdds     *
148192025Sdds     * @param index index of the member slot
149192025Sdds     * @param value value of the member
150192025Sdds     */
151192025Sdds    @Override
152192025Sdds    public void setSlot(final int index, final Object value) {
153192025Sdds        //empty
154192025Sdds    }
155192025Sdds
156192025Sdds    // property and value iteration
157192025Sdds
158192025Sdds    /**
159192025Sdds     * Returns the set of all property names of this object.
160192025Sdds     *
161192025Sdds     * @return set of property names
162192025Sdds     */
163192025Sdds    @Override
164192025Sdds    @SuppressWarnings("unchecked")
165192025Sdds    public Set<String> keySet() {
166192025Sdds        return Collections.EMPTY_SET;
167192025Sdds    }
168192025Sdds
169192025Sdds    /**
170192025Sdds     * Returns the set of all property values of this object.
171192025Sdds     *
172192025Sdds     * @return set of property values.
173192025Sdds     */
174192025Sdds    @Override
175192025Sdds    @SuppressWarnings("unchecked")
176192025Sdds    public Collection<Object> values() {
177192025Sdds        return Collections.EMPTY_SET;
178192025Sdds    }
179192025Sdds
180192025Sdds    // JavaScript instanceof check
181192025Sdds
182192025Sdds    /**
183192025Sdds     * Checking whether the given object is an instance of 'this' object.
184192025Sdds     *
185192025Sdds     * @param instance instace to check
186192025Sdds     * @return true if the given 'instance' is an instance of this 'function' object
187192025Sdds     */
188192025Sdds    @Override
189192025Sdds    public boolean isInstance(final Object instance) {
190192025Sdds        return false;
191192025Sdds    }
192192025Sdds
193192025Sdds    /**
194192025Sdds     * Checking whether this object is an instance of the given 'clazz' object.
195192025Sdds     *
196192025Sdds     * @param clazz clazz to check
197192025Sdds     * @return true if this object is an instance of the given 'clazz'
198192025Sdds     */
199192025Sdds    @Override
200192025Sdds    public boolean isInstanceOf(final Object clazz) {
201192025Sdds        if (clazz instanceof JSObject) {
202192025Sdds            return ((JSObject)clazz).isInstance(this);
203192025Sdds        }
204192025Sdds
205192025Sdds        return false;
206192025Sdds    }
207192025Sdds
208192025Sdds    /**
209192025Sdds     * ECMA [[Class]] property
210192025Sdds     *
211192025Sdds     * @return ECMA [[Class]] property value of this object
212192025Sdds     */
213192025Sdds    @Override
214192025Sdds    public String getClassName() {
215192025Sdds        return getClass().getName();
216192025Sdds    }
217192025Sdds
218192025Sdds    /**
219192025Sdds     * Is this a function object?
220192025Sdds     *
221192025Sdds     * @return if this mirror wraps a ECMAScript function instance
222192025Sdds     */
223192025Sdds    @Override
224192025Sdds    public boolean isFunction() {
225192025Sdds        return false;
226192025Sdds    }
227192025Sdds
228192025Sdds    /**
229192025Sdds     * Is this a 'use strict' function object?
230192025Sdds     *
231192025Sdds     * @return true if this mirror represents a ECMAScript 'use strict' function
232192025Sdds     */
233192025Sdds    @Override
234192025Sdds    public boolean isStrictFunction() {
235192025Sdds        return false;
236192025Sdds    }
237192025Sdds
238192025Sdds    /**
239192025Sdds     * Is this an array object?
240192025Sdds     *
241192025Sdds     * @return if this mirror wraps a ECMAScript array object
242192025Sdds     */
243192025Sdds    @Override
244192025Sdds    public boolean isArray() {
245200780Sjh        return false;
246200780Sjh    }
247192025Sdds
248192025Sdds    /**
249192025Sdds     * Returns this object's numeric value.
250192025Sdds     *
251192025Sdds     * @return this object's numeric value.
252192025Sdds     */
253192025Sdds    @SuppressWarnings("deprecation")
254192025Sdds    @Override
255192025Sdds    public double toNumber() {
256192025Sdds        return Double.NaN;
257192025Sdds    }
258192025Sdds}
259192025Sdds