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