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

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.objects;
  27 
  28 import static jdk.nashorn.internal.runtime.ECMAErrors.rangeError;
  29 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
  30 import static jdk.nashorn.internal.runtime.PropertyDescriptor.VALUE;
  31 import static jdk.nashorn.internal.runtime.PropertyDescriptor.WRITABLE;
  32 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.arrayLikeIterator;
  33 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.reverseArrayLikeIterator;
  34 
  35 import java.lang.invoke.MethodHandle;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.Collections;
  39 import java.util.Comparator;
  40 import java.util.Iterator;
  41 import java.util.List;

  42 import jdk.nashorn.internal.objects.annotations.Attribute;
  43 import jdk.nashorn.internal.objects.annotations.Constructor;
  44 import jdk.nashorn.internal.objects.annotations.Function;
  45 import jdk.nashorn.internal.objects.annotations.Getter;
  46 import jdk.nashorn.internal.objects.annotations.ScriptClass;
  47 import jdk.nashorn.internal.objects.annotations.Setter;
  48 import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
  49 import jdk.nashorn.internal.objects.annotations.Where;
  50 import jdk.nashorn.internal.runtime.JSType;
  51 import jdk.nashorn.internal.runtime.PropertyDescriptor;
  52 import jdk.nashorn.internal.runtime.ScriptFunction;
  53 import jdk.nashorn.internal.runtime.ScriptObject;
  54 import jdk.nashorn.internal.runtime.ScriptRuntime;
  55 import jdk.nashorn.internal.runtime.Undefined;
  56 import jdk.nashorn.internal.runtime.arrays.ArrayData;
  57 import jdk.nashorn.internal.runtime.arrays.ArrayIndex;
  58 import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator;
  59 import jdk.nashorn.internal.runtime.arrays.IteratorAction;
  60 import jdk.nashorn.internal.runtime.linker.Bootstrap;
  61 import jdk.nashorn.internal.runtime.linker.InvokeByName;


 274     /**
 275      * Return the array contents upcasted as an ObjectArray, regardless of
 276      * representation
 277      *
 278      * @return an object array
 279      */
 280     public Object[] asObjectArray() {
 281         return getArray().asObjectArray();
 282     }
 283 
 284     /**
 285      * ECMA 15.4.3.2 Array.isArray ( arg )
 286      *
 287      * @param self self reference
 288      * @param arg  argument - object to check
 289      * @return true if argument is an array
 290      */
 291     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 292     public static Object isArray(final Object self, final Object arg) {
 293         return isArray(arg) || (arg == Global.instance().getArrayPrototype())
 294                 || (arg instanceof NativeRegExpExecResult);

 295     }
 296 
 297     /**
 298      * Length getter
 299      * @param self self reference
 300      * @return the length of the object
 301      */
 302     @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
 303     public static Object length(final Object self) {
 304         if (isArray(self)) {
 305             return ((ScriptObject) self).getArray().length() & JSType.MAX_UINT;
 306         }
 307 
 308         return 0;
 309     }
 310 
 311     /**
 312      * Length setter
 313      * @param self   self reference
 314      * @param length new length property




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.objects;
  27 
  28 import static jdk.nashorn.internal.runtime.ECMAErrors.rangeError;
  29 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
  30 import static jdk.nashorn.internal.runtime.PropertyDescriptor.VALUE;
  31 import static jdk.nashorn.internal.runtime.PropertyDescriptor.WRITABLE;
  32 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.arrayLikeIterator;
  33 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.reverseArrayLikeIterator;
  34 
  35 import java.lang.invoke.MethodHandle;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.Collections;
  39 import java.util.Comparator;
  40 import java.util.Iterator;
  41 import java.util.List;
  42 import jdk.nashorn.api.scripting.ScriptObjectMirror;
  43 import jdk.nashorn.internal.objects.annotations.Attribute;
  44 import jdk.nashorn.internal.objects.annotations.Constructor;
  45 import jdk.nashorn.internal.objects.annotations.Function;
  46 import jdk.nashorn.internal.objects.annotations.Getter;
  47 import jdk.nashorn.internal.objects.annotations.ScriptClass;
  48 import jdk.nashorn.internal.objects.annotations.Setter;
  49 import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
  50 import jdk.nashorn.internal.objects.annotations.Where;
  51 import jdk.nashorn.internal.runtime.JSType;
  52 import jdk.nashorn.internal.runtime.PropertyDescriptor;
  53 import jdk.nashorn.internal.runtime.ScriptFunction;
  54 import jdk.nashorn.internal.runtime.ScriptObject;
  55 import jdk.nashorn.internal.runtime.ScriptRuntime;
  56 import jdk.nashorn.internal.runtime.Undefined;
  57 import jdk.nashorn.internal.runtime.arrays.ArrayData;
  58 import jdk.nashorn.internal.runtime.arrays.ArrayIndex;
  59 import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator;
  60 import jdk.nashorn.internal.runtime.arrays.IteratorAction;
  61 import jdk.nashorn.internal.runtime.linker.Bootstrap;
  62 import jdk.nashorn.internal.runtime.linker.InvokeByName;


 275     /**
 276      * Return the array contents upcasted as an ObjectArray, regardless of
 277      * representation
 278      *
 279      * @return an object array
 280      */
 281     public Object[] asObjectArray() {
 282         return getArray().asObjectArray();
 283     }
 284 
 285     /**
 286      * ECMA 15.4.3.2 Array.isArray ( arg )
 287      *
 288      * @param self self reference
 289      * @param arg  argument - object to check
 290      * @return true if argument is an array
 291      */
 292     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 293     public static Object isArray(final Object self, final Object arg) {
 294         return isArray(arg) || (arg == Global.instance().getArrayPrototype())
 295                 || (arg instanceof NativeRegExpExecResult)
 296                 || (arg instanceof ScriptObjectMirror && ((ScriptObjectMirror)arg).isArray());
 297     }
 298 
 299     /**
 300      * Length getter
 301      * @param self self reference
 302      * @return the length of the object
 303      */
 304     @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
 305     public static Object length(final Object self) {
 306         if (isArray(self)) {
 307             return ((ScriptObject) self).getArray().length() & JSType.MAX_UINT;
 308         }
 309 
 310         return 0;
 311     }
 312 
 313     /**
 314      * Length setter
 315      * @param self   self reference
 316      * @param length new length property