rev 1131 : 8068431: @since and @jdk.Exported are missing in jdk.nashorn.api.scripting classes and package-info.java files Reviewed-by: attila, lagergren
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 public abstract class AbstractJSObject implements JSObject { 41 /** 42 * Call this object as a JavaScript function. This is equivalent to 43 * 'func.apply(thiz, args)' in JavaScript. 44 * 45 * @param thiz 'this' object to be passed to the function 46 * @param args arguments to method 47 * @return result of call 48 */ 49 @Override 50 public Object call(final Object thiz, final Object... args) { 51 throw new UnsupportedOperationException("call"); 52 } 53 54 /** 55 * Call this 'constructor' JavaScript function to create a new object. 56 * This is equivalent to 'new func(arg1, arg2...)' in JavaScript. 57 * 58 * @param args arguments to method 59 * @return result of constructor call 60 */ 61 @Override 62 public Object newObject(final Object... args) { 63 throw new UnsupportedOperationException("newObject"); 64 } 65 66 /** 67 * Evaluate a JavaScript expression. 68 * 69 * @param s JavaScript expression to evaluate 70 * @return evaluation result 71 */ 72 @Override 73 public Object eval(final String s) { 74 throw new UnsupportedOperationException("eval"); 75 } 76 77 /** 78 * Retrieves a named member of this JavaScript object. 79 * 80 * @param name of member 81 * @return member 82 */ 83 @Override 84 public Object getMember(final String name) { 85 return null; 86 } 87 88 /** 89 * Retrieves an indexed member of this JavaScript object. 90 * 91 * @param index index slot to retrieve 92 * @return member 93 */ 94 @Override 95 public Object getSlot(final int index) { 96 return null; 97 } 98 99 /** 100 * Does this object have a named member? 101 * 102 * @param name name of member 103 * @return true if this object has a member of the given name 104 */ 105 @Override 106 public boolean hasMember(final String name) { 107 return false; 108 } 109 110 /** 111 * Does this object have a indexed property? 112 * 113 * @param slot index to check 114 * @return true if this object has a slot 115 */ 116 @Override 117 public boolean hasSlot(final int slot) { 118 return false; 119 } 120 121 /** 122 * Remove a named member from this JavaScript object 123 * 124 * @param name name of the member 125 */ 126 @Override 127 public void removeMember(final String name) { 128 //empty 129 } 130 131 /** 132 * Set a named member in this JavaScript object 133 * 134 * @param name name of the member 135 * @param value value of the member 136 */ 137 @Override 138 public void setMember(final String name, final Object value) { 139 //empty 140 } 141 142 /** 143 * Set an indexed member in this JavaScript object 144 * 145 * @param index index of the member slot 146 * @param value value of the member 147 */ 148 @Override 149 public void setSlot(final int index, final Object value) { 150 //empty 151 } 152 153 // property and value iteration 154 155 /** 156 * Returns the set of all property names of this object. 157 * 158 * @return set of property names 159 */ 160 @Override 161 @SuppressWarnings("unchecked") 162 public Set<String> keySet() { 163 return Collections.EMPTY_SET; 164 } 165 166 /** 167 * Returns the set of all property values of this object. 168 * 169 * @return set of property values. 170 */ 171 @Override 172 @SuppressWarnings("unchecked") 173 public Collection<Object> values() { 174 return Collections.EMPTY_SET; 175 } 176 177 // JavaScript instanceof check 178 179 /** 180 * Checking whether the given object is an instance of 'this' object. 181 * 182 * @param instance instace to check 183 * @return true if the given 'instance' is an instance of this 'function' object 184 */ 185 @Override 186 public boolean isInstance(final Object instance) { 187 return false; 188 } 189 190 /** 191 * Checking whether this object is an instance of the given 'clazz' object. 192 * 193 * @param clazz clazz to check 194 * @return true if this object is an instance of the given 'clazz' 195 */ 196 @Override 197 public boolean isInstanceOf(final Object clazz) { 198 if (clazz instanceof JSObject) { 199 return ((JSObject)clazz).isInstance(this); 200 } 201 202 return false; 203 } 204 205 /** 206 * ECMA [[Class]] property 207 * 208 * @return ECMA [[Class]] property value of this object 209 */ 210 @Override 211 public String getClassName() { 212 return getClass().getName(); 213 } 214 215 /** 216 * Is this a function object? 217 * 218 * @return if this mirror wraps a ECMAScript function instance 219 */ 220 @Override 221 public boolean isFunction() { 222 return false; 223 } 224 225 /** 226 * Is this a 'use strict' function object? 227 * 228 * @return true if this mirror represents a ECMAScript 'use strict' function 229 */ 230 @Override 231 public boolean isStrictFunction() { 232 return false; 233 } 234 235 /** 236 * Is this an array object? 237 * 238 * @return if this mirror wraps a ECMAScript array object 239 */ 240 @Override 241 public boolean isArray() { 242 return false; 243 } 244 245 /** 246 * Returns this object's numeric value. 247 * 248 * @return this object's numeric value. 249 */ 250 @Override 251 public double toNumber() { 252 return Double.NaN; 253 } 254 } --- EOF ---