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

Print this page




  34 import jdk.nashorn.internal.runtime.regexp.RegExpResult;
  35 import jdk.nashorn.internal.runtime.ScriptObject;
  36 import jdk.nashorn.internal.runtime.arrays.ArrayData;
  37 
  38 /**
  39  * Objects of this class are used to represent return values from
  40  * RegExp.prototype.exec method.
  41  */
  42 @ScriptClass("RegExpExecResult")
  43 public final class NativeRegExpExecResult extends ScriptObject {
  44     /** index property */
  45     @Property
  46     public Object index;
  47 
  48     /** input property */
  49     @Property
  50     public Object input;
  51 
  52     NativeRegExpExecResult(final RegExpResult result) {
  53         setProto(Global.instance().getArrayPrototype());

  54         this.setArray(ArrayData.allocate(result.getGroups().clone()));
  55         this.index = result.getIndex();
  56         this.input = result.getInput();
  57     }
  58 
  59     /**
  60      * Length getter
  61      * @param self self reference
  62      * @return length property value
  63      */
  64     @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
  65     public static Object length(final Object self) {
  66         if (self instanceof ScriptObject) {
  67             return ((ScriptObject)self).getArray().length() & JSType.MAX_UINT;
  68         }
  69 
  70         return 0;
  71     }
  72 
  73     /**


  34 import jdk.nashorn.internal.runtime.regexp.RegExpResult;
  35 import jdk.nashorn.internal.runtime.ScriptObject;
  36 import jdk.nashorn.internal.runtime.arrays.ArrayData;
  37 
  38 /**
  39  * Objects of this class are used to represent return values from
  40  * RegExp.prototype.exec method.
  41  */
  42 @ScriptClass("RegExpExecResult")
  43 public final class NativeRegExpExecResult extends ScriptObject {
  44     /** index property */
  45     @Property
  46     public Object index;
  47 
  48     /** input property */
  49     @Property
  50     public Object input;
  51 
  52     NativeRegExpExecResult(final RegExpResult result) {
  53         setProto(Global.instance().getArrayPrototype());
  54         setIsArray();
  55         this.setArray(ArrayData.allocate(result.getGroups().clone()));
  56         this.index = result.getIndex();
  57         this.input = result.getInput();
  58     }
  59 
  60     /**
  61      * Length getter
  62      * @param self self reference
  63      * @return length property value
  64      */
  65     @Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
  66     public static Object length(final Object self) {
  67         if (self instanceof ScriptObject) {
  68             return ((ScriptObject)self).getArray().length() & JSType.MAX_UINT;
  69         }
  70 
  71         return 0;
  72     }
  73 
  74     /**