src/jdk/nashorn/internal/objects/NativeObject.java

Print this page

        

*** 26,40 **** --- 26,42 ---- package jdk.nashorn.internal.objects; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; + import jdk.nashorn.api.scripting.ScriptObjectMirror; import jdk.nashorn.internal.objects.annotations.Attribute; import jdk.nashorn.internal.objects.annotations.Constructor; import jdk.nashorn.internal.objects.annotations.Function; import jdk.nashorn.internal.objects.annotations.ScriptClass; import jdk.nashorn.internal.objects.annotations.Where; + import jdk.nashorn.internal.runtime.ECMAException; import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.ScriptFunction; import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptRuntime; import jdk.nashorn.internal.runtime.linker.InvokeByName;
*** 52,73 **** private static final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); private NativeObject() { } /** * ECMA 15.2.3.2 Object.getPrototypeOf ( O ) * * @param self self reference * @param obj object to get prototype from * @return the prototype of an object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object getPrototypeOf(final Object self, final Object obj) { ! Global.checkObject(obj); ! return ((ScriptObject)obj).getProto(); } /** * ECMA 15.2.3.3 Object.getOwnPropertyDescriptor ( O, P ) * --- 54,83 ---- private static final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); private NativeObject() { } + private static ECMAException notAnObject(final Object obj) { + return typeError("not.an.object", ScriptRuntime.safeToString(obj)); + } + /** * ECMA 15.2.3.2 Object.getPrototypeOf ( O ) * * @param self self reference * @param obj object to get prototype from * @return the prototype of an object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object getPrototypeOf(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { return ((ScriptObject)obj).getProto(); + } else if (obj instanceof ScriptObjectMirror) { + return ((ScriptObjectMirror)obj).getProto(); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.3 Object.getOwnPropertyDescriptor ( O, P ) *
*** 76,91 **** * @param prop property descriptor * @return property descriptor */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object getOwnPropertyDescriptor(final Object self, final Object obj, final Object prop) { ! Global.checkObject(obj); ! final String key = JSType.toString(prop); final ScriptObject sobj = (ScriptObject)obj; return sobj.getOwnPropertyDescriptor(key); } /** * ECMA 15.2.3.4 Object.getOwnPropertyNames ( O ) * --- 86,108 ---- * @param prop property descriptor * @return property descriptor */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object getOwnPropertyDescriptor(final Object self, final Object obj, final Object prop) { ! if (obj instanceof ScriptObject) { final String key = JSType.toString(prop); final ScriptObject sobj = (ScriptObject)obj; return sobj.getOwnPropertyDescriptor(key); + } else if (obj instanceof ScriptObjectMirror) { + final String key = JSType.toString(prop); + final ScriptObjectMirror sobjMirror = (ScriptObjectMirror)obj; + + return sobjMirror.getOwnPropertyDescriptor(key); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.4 Object.getOwnPropertyNames ( O ) *
*** 93,105 **** * @param obj object to query for property names * @return array of property names */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object getOwnPropertyNames(final Object self, final Object obj) { ! Global.checkObject(obj); ! return new NativeArray(((ScriptObject)obj).getOwnKeys(true)); } /** * ECMA 15.2.3.5 Object.create ( O [, Properties] ) * --- 110,126 ---- * @param obj object to query for property names * @return array of property names */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object getOwnPropertyNames(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { return new NativeArray(((ScriptObject)obj).getOwnKeys(true)); + } else if (obj instanceof ScriptObjectMirror) { + return new NativeArray(((ScriptObjectMirror)obj).getOwnKeys(true)); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.5 Object.create ( O [, Properties] ) *
*** 173,184 **** * @param obj object to seal * @return sealed object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object seal(final Object self, final Object obj) { ! Global.checkObject(obj); return ((ScriptObject)obj).seal(); } /** * ECMA 15.2.3.9 Object.freeze ( O ) --- 194,210 ---- * @param obj object to seal * @return sealed object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object seal(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { return ((ScriptObject)obj).seal(); + } else if (obj instanceof ScriptObjectMirror) { + return ((ScriptObjectMirror)obj).seal(); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.9 Object.freeze ( O )
*** 187,198 **** * @param obj object to freeze * @return frozen object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object freeze(final Object self, final Object obj) { ! Global.checkObject(obj); return ((ScriptObject)obj).freeze(); } /** * ECMA 15.2.3.10 Object.preventExtensions ( O ) * --- 213,229 ---- * @param obj object to freeze * @return frozen object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object freeze(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { return ((ScriptObject)obj).freeze(); + } else if (obj instanceof ScriptObjectMirror) { + return ((ScriptObjectMirror)obj).freeze(); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.10 Object.preventExtensions ( O ) *
*** 200,211 **** * @param obj object, for which to set the internal extensible property to false * @return object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object preventExtensions(final Object self, final Object obj) { ! Global.checkObject(obj); return ((ScriptObject)obj).preventExtensions(); } /** * ECMA 15.2.3.11 Object.isSealed ( O ) * --- 231,247 ---- * @param obj object, for which to set the internal extensible property to false * @return object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object preventExtensions(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { return ((ScriptObject)obj).preventExtensions(); + } else if (obj instanceof ScriptObjectMirror) { + return ((ScriptObjectMirror)obj).preventExtensions(); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.11 Object.isSealed ( O ) *
*** 213,224 **** * @param obj check whether an object is sealed * @return true if sealed, false otherwise */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object isSealed(final Object self, final Object obj) { ! Global.checkObject(obj); return ((ScriptObject)obj).isSealed(); } /** * ECMA 15.2.3.12 Object.isFrozen ( O ) * --- 249,265 ---- * @param obj check whether an object is sealed * @return true if sealed, false otherwise */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object isSealed(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { return ((ScriptObject)obj).isSealed(); + } else if (obj instanceof ScriptObjectMirror) { + return ((ScriptObjectMirror)obj).isSealed(); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.12 Object.isFrozen ( O ) *
*** 226,237 **** * @param obj check whether an object * @return true if object is frozen, false otherwise */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object isFrozen(final Object self, final Object obj) { ! Global.checkObject(obj); return ((ScriptObject)obj).isFrozen(); } /** * ECMA 15.2.3.13 Object.isExtensible ( O ) * --- 267,283 ---- * @param obj check whether an object * @return true if object is frozen, false otherwise */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object isFrozen(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { return ((ScriptObject)obj).isFrozen(); + } else if (obj instanceof ScriptObjectMirror) { + return ((ScriptObjectMirror)obj).isFrozen(); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.13 Object.isExtensible ( O ) *
*** 239,250 **** * @param obj check whether an object is extensible * @return true if object is extensible, false otherwise */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object isExtensible(final Object self, final Object obj) { ! Global.checkObject(obj); return ((ScriptObject)obj).isExtensible(); } /** * ECMA 15.2.3.14 Object.keys ( O ) * --- 285,301 ---- * @param obj check whether an object is extensible * @return true if object is extensible, false otherwise */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object isExtensible(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { return ((ScriptObject)obj).isExtensible(); + } else if (obj instanceof ScriptObjectMirror) { + return ((ScriptObjectMirror)obj).isExtensible(); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.3.14 Object.keys ( O ) *
*** 252,264 **** * @param obj object from which to extract keys * @return array of keys in object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object keys(final Object self, final Object obj) { ! Global.checkObject(obj); final ScriptObject sobj = (ScriptObject)obj; return new NativeArray(sobj.getOwnKeys(false)); } /** * ECMA 15.2.2.1 , 15.2.1.1 new Object([value]) and Object([value]) * --- 303,321 ---- * @param obj object from which to extract keys * @return array of keys in object */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object keys(final Object self, final Object obj) { ! if (obj instanceof ScriptObject) { final ScriptObject sobj = (ScriptObject)obj; return new NativeArray(sobj.getOwnKeys(false)); + } else if (obj instanceof ScriptObjectMirror) { + final ScriptObjectMirror sobjMirror = (ScriptObjectMirror)obj; + return new NativeArray(sobjMirror.getOwnKeys(false)); + } else { + throw notAnObject(obj); + } } /** * ECMA 15.2.2.1 , 15.2.1.1 new Object([value]) and Object([value]) *