src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeRegExp.java

Print this page




  61 @ScriptClass("RegExp")
  62 public final class NativeRegExp extends ScriptObject {
  63     /** ECMA 15.10.7.5 lastIndex property */
  64     @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
  65     public Object lastIndex;
  66 
  67     /** Compiled regexp */
  68     private RegExp regexp;
  69 
  70     // Reference to global object needed to support static RegExp properties
  71     private final Global globalObject;
  72 
  73     // initialized by nasgen
  74     private static PropertyMap $nasgenmap$;
  75 
  76     private NativeRegExp(final Global global) {
  77         super(global.getRegExpPrototype(), $nasgenmap$);
  78         this.globalObject = global;
  79     }
  80 
  81     NativeRegExp(final String input, final String flagString, final Global global) {
  82         this(global);
  83         try {
  84             this.regexp = RegExpFactory.create(input, flagString);
  85         } catch (final ParserException e) {
  86             // translate it as SyntaxError object and throw it
  87             e.throwAsEcmaException();
  88             throw new AssertionError(); //guard against null warnings below
  89         }
  90 
  91         this.setLastIndex(0);
  92     }
  93 




  94     NativeRegExp(final String input, final String flagString) {
  95         this(input, flagString, Global.instance());
  96     }
  97 
  98     NativeRegExp(final String string, final Global global) {
  99         this(string, "", global);
 100     }
 101 
 102     NativeRegExp(final String string) {
 103         this(string, Global.instance());
 104     }
 105 
 106     NativeRegExp(final NativeRegExp regExp) {
 107         this(Global.instance());
 108         this.lastIndex  = regExp.getLastIndexObject();
 109         this.regexp      = regExp.getRegExp();
 110     }
 111 
 112     @Override
 113     public String getClassName() {


 911     /**
 912      * Fast lastIndex getter
 913      * @return last index property as boxed integer
 914      */
 915     public Object getLastIndexObject() {
 916         return lastIndex;
 917     }
 918 
 919     /**
 920      * Fast lastIndex setter
 921      * @param lastIndex lastIndex
 922      */
 923     public void setLastIndex(final int lastIndex) {
 924         this.lastIndex = JSType.toObject(lastIndex);
 925     }
 926 
 927     private static NativeRegExp checkRegExp(final Object self) {
 928         if (self instanceof NativeRegExp) {
 929             return (NativeRegExp)self;
 930         } else if (self != null && self == Global.instance().getRegExpPrototype()) {
 931             return Global.instance().DEFAULT_REGEXP;
 932         } else {
 933             throw typeError("not.a.regexp", ScriptRuntime.safeToString(self));
 934         }
 935     }
 936 
 937     boolean getGlobal() {
 938         return regexp.isGlobal();
 939     }
 940 
 941     private RegExp getRegExp() {
 942         return regexp;
 943     }
 944 
 945     private void setRegExp(final RegExp regexp) {
 946         this.regexp = regexp;
 947     }
 948 
 949 }


  61 @ScriptClass("RegExp")
  62 public final class NativeRegExp extends ScriptObject {
  63     /** ECMA 15.10.7.5 lastIndex property */
  64     @Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
  65     public Object lastIndex;
  66 
  67     /** Compiled regexp */
  68     private RegExp regexp;
  69 
  70     // Reference to global object needed to support static RegExp properties
  71     private final Global globalObject;
  72 
  73     // initialized by nasgen
  74     private static PropertyMap $nasgenmap$;
  75 
  76     private NativeRegExp(final Global global) {
  77         super(global.getRegExpPrototype(), $nasgenmap$);
  78         this.globalObject = global;
  79     }
  80 
  81     NativeRegExp(final String input, final String flagString, final Global global, final ScriptObject proto) {
  82         super(proto, $nasgenmap$);
  83         try {
  84             this.regexp = RegExpFactory.create(input, flagString);
  85         } catch (final ParserException e) {
  86             // translate it as SyntaxError object and throw it
  87             e.throwAsEcmaException();
  88             throw new AssertionError(); //guard against null warnings below
  89         }
  90         this.globalObject = global;
  91         this.setLastIndex(0);
  92     }
  93 
  94     NativeRegExp(final String input, final String flagString, final Global global) {
  95         this(input, flagString, global, global.getRegExpPrototype());
  96     }
  97 
  98     NativeRegExp(final String input, final String flagString) {
  99         this(input, flagString, Global.instance());
 100     }
 101 
 102     NativeRegExp(final String string, final Global global) {
 103         this(string, "", global);
 104     }
 105 
 106     NativeRegExp(final String string) {
 107         this(string, Global.instance());
 108     }
 109 
 110     NativeRegExp(final NativeRegExp regExp) {
 111         this(Global.instance());
 112         this.lastIndex  = regExp.getLastIndexObject();
 113         this.regexp      = regExp.getRegExp();
 114     }
 115 
 116     @Override
 117     public String getClassName() {


 915     /**
 916      * Fast lastIndex getter
 917      * @return last index property as boxed integer
 918      */
 919     public Object getLastIndexObject() {
 920         return lastIndex;
 921     }
 922 
 923     /**
 924      * Fast lastIndex setter
 925      * @param lastIndex lastIndex
 926      */
 927     public void setLastIndex(final int lastIndex) {
 928         this.lastIndex = JSType.toObject(lastIndex);
 929     }
 930 
 931     private static NativeRegExp checkRegExp(final Object self) {
 932         if (self instanceof NativeRegExp) {
 933             return (NativeRegExp)self;
 934         } else if (self != null && self == Global.instance().getRegExpPrototype()) {
 935             return Global.instance().getDefaultRegExp();
 936         } else {
 937             throw typeError("not.a.regexp", ScriptRuntime.safeToString(self));
 938         }
 939     }
 940 
 941     boolean getGlobal() {
 942         return regexp.isGlobal();
 943     }
 944 
 945     private RegExp getRegExp() {
 946         return regexp;
 947     }
 948 
 949     private void setRegExp(final RegExp regexp) {
 950         this.regexp = regexp;
 951     }
 952 
 953 }