// ECMA 262 - 15.10.4 private void ctor(ref mdr.CallFrame callFrame) { DRegExp regexp = null; string pattern; string flags; switch (callFrame.PassedArgsCount) { case 0: regexp = new DRegExp(""); break; case 1: if (callFrame.Arg0.ValueType == mdr.ValueTypes.Object && IsRegExp(callFrame.Arg0.AsDObject())) { regexp = callFrame.Arg0.AsDObject() as DRegExp; if (IsConstrutor) { //We have to create a new copy regexp = new DRegExp(regexp.Value.ToString()); } } else { pattern = Operations.Convert.ToString.Run(ref callFrame.Arg0); regexp = new DRegExp(pattern); } break; case 2: if (callFrame.Arg0.ValueType == mdr.ValueTypes.Object) { if (IsRegExp(callFrame.Arg0.AsDObject())) { RegExpError("TypeError"); } } else { pattern = Operations.Convert.ToString.Run(ref callFrame.Arg0); flags = Operations.Convert.ToString.Run(ref callFrame.Arg1); regexp = new DRegExp(pattern, flags); } break; default: RegExpError("Invalid arguments in RegExp constructor"); break; } if (IsConstrutor) { callFrame.This = (regexp); } else { callFrame.Return.Set(regexp); } }
// ECMA 262 - 15.10.6.2 private static void exec(ref mdr.CallFrame callFrame) { Debug.WriteLine("calling JSRegExp.exec S {0} \n R {1}", callFrame.Arg0, callFrame.This); string S = Operations.Convert.ToString.Run(ref callFrame.Arg0); DRegExp R = callFrame.This as DRegExp; callFrame.Return.Set(R.ExecImplementation(S)); }
// ECMA 262 - 15.10.6.3 private void test(ref mdr.CallFrame callFrame) { Debug.WriteLine("calling JSRegExp.test"); string S = Operations.Convert.ToString.Run(ref callFrame.Arg0); DRegExp R = callFrame.This as DRegExp; LastDRegExp = R; if (R != null && R.MatchImplementation(S) != null) { if (R.MatchedGroups.Count > MaxMatchedGroupIndex) { for (var i = 0; i < (R.MatchedGroups.Count - MaxMatchedGroupIndex); i++) { AddNewMatchedGroup(); } } callFrame.Return.Set(true); } else { callFrame.Return.Set(false); } }