public static EcmaValue RegExp([NewTarget] RuntimeObject newTarget, [This] EcmaValue thisValue, EcmaValue pattern, EcmaValue flags) { bool patternIsRegExp = pattern.IsRegExp; if (newTarget == null && patternIsRegExp && flags == default) { EcmaValue constructor = pattern[WellKnownProperty.Constructor]; if (constructor.Type == EcmaValueType.Object && constructor.ToObject().IsWellknownObject(WellKnownObject.RegExpConstructor)) { return(pattern); } } string strPattern; string strFlags; if (pattern.Type == EcmaValueType.Object && pattern.ToObject() is EcmaRegExp other) { strPattern = other.Source; strFlags = flags == default ? (string)RegExpPrototype.Flags(other) : flags.ToStringOrThrow(); } else if (patternIsRegExp) { strPattern = pattern[WellKnownProperty.Source].ToStringOrThrow(); strFlags = flags == default ? pattern[WellKnownProperty.Flags].ToStringOrThrow() : flags.ToStringOrThrow(); } else { strPattern = pattern == default ? "" : pattern.ToStringOrThrow(); strFlags = flags == default ? "" : flags.ToStringOrThrow(); } EcmaRegExp re = EcmaRegExp.Parse(strPattern, strFlags); if (newTarget == null) { return(re.Clone()); } thisValue.GetUnderlyingObject <EcmaRegExp>().Init(re); return(thisValue); }
public static EcmaValue ToString([This] EcmaValue thisValue) { EcmaRegExp re = thisValue.GetUnderlyingObject <EcmaRegExp>(); return(String.Concat("/", re.Source, "/", re.Flags)); }
public static EcmaValue Exec([This] EcmaValue thisValue, EcmaValue input) { EcmaRegExp re = thisValue.GetUnderlyingObject <EcmaRegExp>(); return(re.Test(input.ToStringOrThrow()) ? re.LastResult.ToValue() : EcmaValue.Null); }
protected virtual void WriteRegExp(EcmaRegExp re) { WriteToken(InspectorTokenType.RegExp, re.ToString()); }