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.Objects; 31 import java.util.Set; 32 33 /** 34 * This is the base class for nashorn ScriptObjectMirror class. 35 * 36 * This class can also be subclassed by an arbitrary Java class. Nashorn will 37 * treat objects of such classes just like nashorn script objects. Usual nashorn 38 * operations like obj[i], obj.foo, obj.func(), delete obj.foo will be delegated 39 * to appropriate method call of this class. 40 * 41 * @deprecated Nashorn JavaScript script engine and APIs, and the jjs tool 42 * are deprecated with the intent to remove them in a future release. 43 * 44 * @since 1.8u40 45 */ 46 @Deprecated(since="11", forRemoval=true) 47 public abstract class AbstractJSObject implements JSObject { 48 /** 49 * The default constructor. 50 */ 51 public AbstractJSObject() {} 52 53 /** 54 * @implSpec This implementation always throws UnsupportedOperationException 55 */ 56 @Override 57 public Object call(final Object thiz, final Object... args) { 58 throw new UnsupportedOperationException("call"); 59 } 60 61 /** 62 * @implSpec This implementation always throws UnsupportedOperationException 63 */ 64 @Override 65 public Object newObject(final Object... args) { 66 throw new UnsupportedOperationException("newObject"); 67 } 68 69 /** 70 * @implSpec This imlementation always throws UnsupportedOperationException 71 */ 72 @Override 73 public Object eval(final String s) { 74 throw new UnsupportedOperationException("eval"); 75 } 76 77 /** 78 * @implSpec This implementation always returns null 79 */ 80 @Override 81 public Object getMember(final String name) { 82 Objects.requireNonNull(name); 83 return null; 84 } 85 86 /** 87 * @implSpec This implementation always returns null 88 */ 89 @Override 90 public Object getSlot(final int index) { 91 return null; 92 } 93 94 /** 95 * @implSpec This implementation always returns false 96 */ 97 @Override 98 public boolean hasMember(final String name) { 99 Objects.requireNonNull(name); 100 return false; 101 } 102 103 /** 104 * @implSpec This implementation always returns false 105 */ 106 @Override 107 public boolean hasSlot(final int slot) { 108 return false; 109 } 110 111 /** 112 * @implSpec This implementation is a no-op 113 */ 114 @Override 115 public void removeMember(final String name) { 116 Objects.requireNonNull(name); 117 //empty 118 } 119 120 /** 121 * @implSpec This implementation is a no-op 122 */ 123 @Override 124 public void setMember(final String name, final Object value) { 125 Objects.requireNonNull(name); 126 //empty 127 } 128 129 /** 130 * @implSpec This implementation is a no-op 131 */ 132 @Override 133 public void setSlot(final int index, final Object value) { 134 //empty 135 } 136 137 // property and value iteration 138 139 /** 140 * @implSpec This implementation returns empty set 141 */ 142 @Override 143 public Set<String> keySet() { 144 return Collections.emptySet(); 145 } 146 147 /** 148 * @implSpec This implementation returns empty set 149 */ 150 @Override 151 public Collection<Object> values() { 152 return Collections.emptySet(); 153 } 154 155 // JavaScript instanceof check 156 157 /** 158 * @implSpec This implementation always returns false 159 */ 160 @Override 161 public boolean isInstance(final Object instance) { 162 return false; 163 } 164 165 @Override 166 public boolean isInstanceOf(final Object clazz) { 167 if (clazz instanceof JSObject) { 168 return ((JSObject)clazz).isInstance(this); 169 } 170 171 return false; 172 } 173 174 @Override 175 public String getClassName() { 176 return getClass().getName(); 177 } 178 179 /** 180 * @implSpec This implementation always returns false 181 */ 182 @Override 183 public boolean isFunction() { 184 return false; 185 } 186 187 /** 188 * @implSpec This implementation always returns false 189 */ 190 @Override 191 public boolean isStrictFunction() { 192 return false; 193 } 194 195 /** 196 * @implSpec This implementation always returns false 197 */ 198 @Override 199 public boolean isArray() { 200 return false; 201 } 202 203 /** 204 * Returns this object's numeric value. 205 * 206 * @return this object's numeric value. 207 * @deprecated use {@link #getDefaultValue(Class)} with {@link Number} hint instead. 208 */ 209 @Override @Deprecated 210 public double toNumber() { 211 return Double.NaN; 212 } 213 214 /** 215 * When passed an {@link AbstractJSObject}, invokes its {@link #getDefaultValue(Class)} method. When passed any 216 * other {@link JSObject}, it will obtain its {@code [[DefaultValue]]} method as per ECMAScript 5.1 section 217 * 8.6.2. 218 * 219 * @param jsobj the {@link JSObject} whose {@code [[DefaultValue]]} is obtained. 220 * @param hint the type hint. Should be either {@code null}, {@code Number.class} or {@code String.class}. 221 * @return this object's default value. 222 * @throws UnsupportedOperationException if the conversion can't be performed. The engine will convert this 223 * exception into a JavaScript {@code TypeError}. 224 * @deprecated use {@link JSObject#getDefaultValue(Class)} instead. 225 */ 226 @Deprecated 227 public static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) { 228 return jsobj.getDefaultValue(hint); 229 } 230 }