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

Print this page
rev 755 : 8035948: Redesign property listeners for shared classes
Reviewed-by: sundar, lagergren


  51  * Arguments object used for non-strict mode functions. For strict mode, we use
  52  * a different implementation (@see NativeStrictArguments). In non-strict mode,
  53  * named argument access and index argument access (arguments[i]) are linked.
  54  * Modifications reflect on each other access -- till arguments indexed element
  55  * is deleted. After delete, there is no link between named access and indexed
  56  * access for that deleted index alone.
  57  */
  58 public final class NativeArguments extends ScriptObject {
  59 
  60     private static final MethodHandle G$LENGTH = findOwnMH("G$length", Object.class, Object.class);
  61     private static final MethodHandle S$LENGTH = findOwnMH("S$length", void.class, Object.class, Object.class);
  62     private static final MethodHandle G$CALLEE = findOwnMH("G$callee", Object.class, Object.class);
  63     private static final MethodHandle S$CALLEE = findOwnMH("S$callee", void.class, Object.class, Object.class);
  64 
  65     private static final PropertyMap map$;
  66 
  67     static {
  68         final ArrayList<Property> properties = new ArrayList<>(2);
  69         properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH));
  70         properties.add(AccessorProperty.create("callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE));
  71         map$ = PropertyMap.newMap(properties).setIsShared();
  72     }
  73 
  74     static PropertyMap getInitialMap() {
  75         return map$;
  76     }
  77 
  78     private Object length;
  79     private Object callee;
  80     private final int numMapped;
  81     private final int numParams;
  82 
  83     // These are lazily initialized when delete is invoked on a mapped arg or an unmapped argument is set.
  84     private ArrayData unmappedArgs;
  85     private BitSet deleted;
  86 
  87     NativeArguments(final Object[] arguments, final Object callee, final int numParams, final ScriptObject proto, final PropertyMap map) {
  88         super(proto, map);
  89         setIsArguments();
  90         setArray(ArrayData.allocate(arguments));
  91         this.length = arguments.length;


 250      */
 251     private boolean isMapped(final int index) {
 252         // in mapped named args and not marked as "deleted"
 253         return index >= 0 && index < numMapped && !isDeleted(index);
 254     }
 255 
 256     /**
 257      * Factory to create correct Arguments object based on strict mode.
 258      *
 259      * @param arguments the actual arguments array passed
 260      * @param callee the callee function that uses arguments object
 261      * @param numParams the number of declared (named) function parameters
 262      * @return Arguments Object
 263      */
 264     public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) {
 265         // Strict functions won't always have a callee for arguments, and will pass null instead.
 266         final boolean isStrict = callee == null || callee.isStrict();
 267         final Global global = Global.instance();
 268         final ScriptObject proto = global.getObjectPrototype();
 269         if (isStrict) {
 270             return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap());
 271         }
 272         return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap());
 273     }
 274 
 275     /**
 276      * Length getter
 277      * @param self self reference
 278      * @return length property value
 279      */
 280     public static Object G$length(final Object self) {
 281         if (self instanceof NativeArguments) {
 282             return ((NativeArguments)self).getArgumentsLength();
 283         }
 284 
 285         return 0;
 286     }
 287 
 288     /**
 289      * Length setter
 290      * @param self self reference
 291      * @param value value for length property
 292      */




  51  * Arguments object used for non-strict mode functions. For strict mode, we use
  52  * a different implementation (@see NativeStrictArguments). In non-strict mode,
  53  * named argument access and index argument access (arguments[i]) are linked.
  54  * Modifications reflect on each other access -- till arguments indexed element
  55  * is deleted. After delete, there is no link between named access and indexed
  56  * access for that deleted index alone.
  57  */
  58 public final class NativeArguments extends ScriptObject {
  59 
  60     private static final MethodHandle G$LENGTH = findOwnMH("G$length", Object.class, Object.class);
  61     private static final MethodHandle S$LENGTH = findOwnMH("S$length", void.class, Object.class, Object.class);
  62     private static final MethodHandle G$CALLEE = findOwnMH("G$callee", Object.class, Object.class);
  63     private static final MethodHandle S$CALLEE = findOwnMH("S$callee", void.class, Object.class, Object.class);
  64 
  65     private static final PropertyMap map$;
  66 
  67     static {
  68         final ArrayList<Property> properties = new ArrayList<>(2);
  69         properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH));
  70         properties.add(AccessorProperty.create("callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE));
  71         map$ = PropertyMap.newMap(properties);
  72     }
  73 
  74     static PropertyMap getInitialMap() {
  75         return map$;
  76     }
  77 
  78     private Object length;
  79     private Object callee;
  80     private final int numMapped;
  81     private final int numParams;
  82 
  83     // These are lazily initialized when delete is invoked on a mapped arg or an unmapped argument is set.
  84     private ArrayData unmappedArgs;
  85     private BitSet deleted;
  86 
  87     NativeArguments(final Object[] arguments, final Object callee, final int numParams, final ScriptObject proto, final PropertyMap map) {
  88         super(proto, map);
  89         setIsArguments();
  90         setArray(ArrayData.allocate(arguments));
  91         this.length = arguments.length;


 250      */
 251     private boolean isMapped(final int index) {
 252         // in mapped named args and not marked as "deleted"
 253         return index >= 0 && index < numMapped && !isDeleted(index);
 254     }
 255 
 256     /**
 257      * Factory to create correct Arguments object based on strict mode.
 258      *
 259      * @param arguments the actual arguments array passed
 260      * @param callee the callee function that uses arguments object
 261      * @param numParams the number of declared (named) function parameters
 262      * @return Arguments Object
 263      */
 264     public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) {
 265         // Strict functions won't always have a callee for arguments, and will pass null instead.
 266         final boolean isStrict = callee == null || callee.isStrict();
 267         final Global global = Global.instance();
 268         final ScriptObject proto = global.getObjectPrototype();
 269         if (isStrict) {
 270             return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap());
 271         }
 272         return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap());
 273     }
 274 
 275     /**
 276      * Length getter
 277      * @param self self reference
 278      * @return length property value
 279      */
 280     public static Object G$length(final Object self) {
 281         if (self instanceof NativeArguments) {
 282             return ((NativeArguments)self).getArgumentsLength();
 283         }
 284 
 285         return 0;
 286     }
 287 
 288     /**
 289      * Length setter
 290      * @param self self reference
 291      * @param value value for length property
 292      */