Beispiel #1
0
 public JSObject exec(JSObject arg)
 {
     if (this.GetType() != typeof(RegExp))
         throw new JSException(new TypeError("Try to call RegExp.exec on not RegExp object."));
     string input = (arg ?? "undefined").ToString();
     lIndex = Tools.JSObjectToNumber(lastIndex);
     if ((lIndex.attributes & JSObjectAttributesInternal.SystemObject) != 0)
         lIndex = lIndex.CloneImpl();
     if (lIndex.valueType == JSObjectType.Double)
     {
         lIndex.valueType = JSObjectType.Int;
         lIndex.iValue = (int)lIndex.dValue;
     }
     if (lIndex.iValue < 0)
         lIndex.iValue = 0;
     if (lIndex.iValue >= input.Length && input.Length > 0)
     {
         lIndex.iValue = 0;
         return Null;
     }
     var m = regEx.Match(input, lIndex.iValue);
     if (!m.Success)
     {
         lIndex.iValue = 0;
         return Null;
     }
     var res = new Array(m.Groups.Count);
     for (int i = 0; i < m.Groups.Count; i++)
         res.data[i] = m.Groups[i].Success ? (JSObject)m.Groups[i].Value : null;
     if (_global)
         lIndex.iValue = m.Index + m.Length;
     res.DefineMember("index").Assign(m.Index);
     res.DefineMember("input").Assign(input);
     return res;
 }