diff --git a/Jint.Tests/Runtime/JsValueConversionTests.cs b/Jint.Tests/Runtime/JsValueConversionTests.cs index b28cd97a14..5e61c1df8e 100644 --- a/Jint.Tests/Runtime/JsValueConversionTests.cs +++ b/Jint.Tests/Runtime/JsValueConversionTests.cs @@ -119,7 +119,7 @@ public void ShouldBeAnObject() [Fact] public void ShouldBeARegExp() { - var value = new RegExpInstance(_engine); + var value = new JsRegExp(_engine); Assert.Equal(false, value.IsBoolean()); Assert.Equal(false, value.IsArray()); Assert.Equal(false, value.IsDate()); diff --git a/Jint/JsValueExtensions.cs b/Jint/JsValueExtensions.cs index 0d8dc0074e..b26975b940 100644 --- a/Jint/JsValueExtensions.cs +++ b/Jint/JsValueExtensions.cs @@ -69,7 +69,7 @@ public static bool IsRegExp(this JsValue value) return TypeConverter.ToBoolean(matcher); } - return value is RegExpInstance; + return value is JsRegExp; } [Pure] @@ -148,14 +148,14 @@ public static JsDate AsDate(this JsValue value) } [Pure] - public static RegExpInstance AsRegExp(this JsValue value) + public static JsRegExp AsRegExp(this JsValue value) { if (!value.IsRegExp()) { ExceptionHelper.ThrowArgumentException("The value is not a regex"); } - return (RegExpInstance) value; + return (JsRegExp) value; } [Pure] diff --git a/Jint/Native/Iterator/IteratorInstance.cs b/Jint/Native/Iterator/IteratorInstance.cs index 12605c1869..fd8c86ef4e 100644 --- a/Jint/Native/Iterator/IteratorInstance.cs +++ b/Jint/Native/Iterator/IteratorInstance.cs @@ -132,7 +132,7 @@ public override bool TryIteratorStep(out ObjectInstance nextItem) internal sealed class RegExpStringIterator : IteratorInstance { - private readonly RegExpInstance _iteratingRegExp; + private readonly JsRegExp _iteratingRegExp; private readonly string _s; private readonly bool _global; private readonly bool _unicode; @@ -141,7 +141,7 @@ internal sealed class RegExpStringIterator : IteratorInstance public RegExpStringIterator(Engine engine, ObjectInstance iteratingRegExp, string iteratedString, bool global, bool unicode) : base(engine) { - var r = iteratingRegExp as RegExpInstance; + var r = iteratingRegExp as JsRegExp; if (r is null) { ExceptionHelper.ThrowTypeError(engine.Realm); @@ -174,9 +174,9 @@ public override bool TryIteratorStep(out ObjectInstance nextItem) var macthStr = TypeConverter.ToString(match.Get(JsString.NumberZeroString)); if (macthStr == "") { - var thisIndex = TypeConverter.ToLength(_iteratingRegExp.Get(RegExpInstance.PropertyLastIndex)); + var thisIndex = TypeConverter.ToLength(_iteratingRegExp.Get(JsRegExp.PropertyLastIndex)); var nextIndex = thisIndex + 1; - _iteratingRegExp.Set(RegExpInstance.PropertyLastIndex, nextIndex, true); + _iteratingRegExp.Set(JsRegExp.PropertyLastIndex, nextIndex, true); } } else diff --git a/Jint/Native/Object/ObjectInstance.cs b/Jint/Native/Object/ObjectInstance.cs index 84d25dec63..4bdb5fba63 100644 --- a/Jint/Native/Object/ObjectInstance.cs +++ b/Jint/Native/Object/ObjectInstance.cs @@ -1024,7 +1024,7 @@ private object ToObject(ObjectTraverseStack stack) break; case ObjectClass.RegExp: - if (this is RegExpInstance regeExpInstance) + if (this is JsRegExp regeExpInstance) { converted = regeExpInstance.Value; } diff --git a/Jint/Native/RegExp/RegExpInstance.cs b/Jint/Native/RegExp/JsRegExp.cs similarity index 97% rename from Jint/Native/RegExp/RegExpInstance.cs rename to Jint/Native/RegExp/JsRegExp.cs index adcf4d1d97..bacd74c5cb 100644 --- a/Jint/Native/RegExp/RegExpInstance.cs +++ b/Jint/Native/RegExp/JsRegExp.cs @@ -5,7 +5,7 @@ namespace Jint.Native.RegExp { - public sealed class RegExpInstance : ObjectInstance + public sealed class JsRegExp : ObjectInstance { internal const string regExpForMatchingAllCharacters = "(?:)"; internal static readonly JsString PropertyLastIndex = new("lastIndex"); @@ -14,7 +14,7 @@ public sealed class RegExpInstance : ObjectInstance private PropertyDescriptor _prototypeDescriptor = null!; - public RegExpInstance(Engine engine) + public JsRegExp(Engine engine) : base(engine, ObjectClass.RegExp) { Source = regExpForMatchingAllCharacters; diff --git a/Jint/Native/RegExp/RegExpConstructor.cs b/Jint/Native/RegExp/RegExpConstructor.cs index 63bc12021a..8142cf9427 100644 --- a/Jint/Native/RegExp/RegExpConstructor.cs +++ b/Jint/Native/RegExp/RegExpConstructor.cs @@ -72,7 +72,7 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget) JsValue p; JsValue f; - if (pattern is RegExpInstance regExpInstance) + if (pattern is JsRegExp regExpInstance) { p = regExpInstance.Source; f = flags.IsUndefined() ? regExpInstance.Flags : flags; @@ -92,7 +92,7 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget) return RegExpInitialize(r, p, f); } - private ObjectInstance RegExpInitialize(RegExpInstance r, JsValue pattern, JsValue flags) + private ObjectInstance RegExpInitialize(JsRegExp r, JsValue pattern, JsValue flags) { var p = pattern.IsUndefined() ? "" : TypeConverter.ToString(pattern); if (string.IsNullOrEmpty(p)) @@ -129,18 +129,18 @@ private ObjectInstance RegExpInitialize(RegExpInstance r, JsValue pattern, JsVal return r; } - private RegExpInstance RegExpAlloc(JsValue newTarget) + private JsRegExp RegExpAlloc(JsValue newTarget) { var r = OrdinaryCreateFromConstructor( newTarget, static intrinsics => intrinsics.RegExp.PrototypeObject, - static (Engine engine, Realm _, object? _) => new RegExpInstance(engine)); + static (Engine engine, Realm _, object? _) => new JsRegExp(engine)); return r; } - public RegExpInstance Construct(Regex regExp, string source, string flags) + public JsRegExp Construct(Regex regExp, string source, string flags) { - var r = new RegExpInstance(Engine); + var r = new JsRegExp(Engine); r._prototype = PrototypeObject; r.Flags = flags; @@ -161,9 +161,9 @@ public RegExpInstance Construct(Regex regExp, string source, string flags) return r; } - private static void RegExpInitialize(RegExpInstance r) + private static void RegExpInitialize(JsRegExp r) { - r.SetOwnProperty(RegExpInstance.PropertyLastIndex, new PropertyDescriptor(0, PropertyFlag.OnlyWritable)); + r.SetOwnProperty(JsRegExp.PropertyLastIndex, new PropertyDescriptor(0, PropertyFlag.OnlyWritable)); } } } diff --git a/Jint/Native/RegExp/RegExpExtensions.cs b/Jint/Native/RegExp/RegExpExtensions.cs index 0d29054732..927f8be297 100644 --- a/Jint/Native/RegExp/RegExpExtensions.cs +++ b/Jint/Native/RegExp/RegExpExtensions.cs @@ -12,7 +12,7 @@ internal static bool TryGetDefaultRegExpExec(this ObjectInstance? o, [NotNullWhe return prototype.TryGetDefaultExec(prototype, out exec); } - if (o is RegExpInstance instance) + if (o is JsRegExp instance) { exec = default; return instance.Properties == null diff --git a/Jint/Native/RegExp/RegExpPrototype.cs b/Jint/Native/RegExp/RegExpPrototype.cs index c079937a82..8e2e8a09c5 100644 --- a/Jint/Native/RegExp/RegExpPrototype.cs +++ b/Jint/Native/RegExp/RegExpPrototype.cs @@ -42,7 +42,7 @@ protected override void Initialize() { const PropertyFlag lengthFlags = PropertyFlag.Configurable; - GetSetPropertyDescriptor CreateGetAccessorDescriptor(string name, Func valueExtractor, JsValue? protoValue = null) + GetSetPropertyDescriptor CreateGetAccessorDescriptor(string name, Func valueExtractor, JsValue? protoValue = null) { return new GetSetPropertyDescriptor( get: new ClrFunctionInstance(Engine, name, (thisObj, arguments) => @@ -52,7 +52,7 @@ GetSetPropertyDescriptor CreateGetAccessorDescriptor(string name, Func= s.Length && s.Length > 0) { return JsBoolean.False; @@ -639,10 +639,10 @@ private JsValue Test(JsValue thisObj, JsValue[] arguments) var m = R.Value.Match(s, lastIndex); if (!m.Success || (R.Sticky && m.Index != lastIndex)) { - R.Set(RegExpInstance.PropertyLastIndex, 0, throwOnError: true); + R.Set(JsRegExp.PropertyLastIndex, 0, throwOnError: true); return JsBoolean.False; } - R.Set(RegExpInstance.PropertyLastIndex, m.Index + m.Length, throwOnError: true); + R.Set(JsRegExp.PropertyLastIndex, m.Index + m.Length, throwOnError: true); return JsBoolean.True; } @@ -658,17 +658,17 @@ private JsValue Search(JsValue thisObj, JsValue[] arguments) var rx = AssertThisIsObjectInstance(thisObj, "RegExp.prototype.search"); var s = TypeConverter.ToString(arguments.At(0)); - var previousLastIndex = rx.Get(RegExpInstance.PropertyLastIndex); + var previousLastIndex = rx.Get(JsRegExp.PropertyLastIndex); if (!SameValue(previousLastIndex, 0)) { - rx.Set(RegExpInstance.PropertyLastIndex, 0, true); + rx.Set(JsRegExp.PropertyLastIndex, 0, true); } var result = RegExpExec(rx, s); - var currentLastIndex = rx.Get(RegExpInstance.PropertyLastIndex); + var currentLastIndex = rx.Get(JsRegExp.PropertyLastIndex); if (!SameValue(currentLastIndex, previousLastIndex)) { - rx.Set(RegExpInstance.PropertyLastIndex, previousLastIndex, true); + rx.Set(JsRegExp.PropertyLastIndex, previousLastIndex, true); } if (result.IsNull()) @@ -695,10 +695,10 @@ private JsValue Match(JsValue thisObj, JsValue[] arguments) } var fullUnicode = flags.IndexOf('u') != -1; - rx.Set(RegExpInstance.PropertyLastIndex, JsNumber.PositiveZero, true); + rx.Set(JsRegExp.PropertyLastIndex, JsNumber.PositiveZero, true); if (!fullUnicode - && rx is RegExpInstance rei + && rx is JsRegExp rei && rei.TryGetDefaultRegExpExec(out _)) { // fast path @@ -762,9 +762,9 @@ private JsValue MatchSlow(ObjectInstance rx, string s, bool fullUnicode) a.SetIndexValue(n, matchStr, updateLength: false); if (matchStr == "") { - var thisIndex = TypeConverter.ToLength(rx.Get(RegExpInstance.PropertyLastIndex)); + var thisIndex = TypeConverter.ToLength(rx.Get(JsRegExp.PropertyLastIndex)); var nextIndex = AdvanceStringIndex(s, thisIndex, fullUnicode); - rx.Set(RegExpInstance.PropertyLastIndex, nextIndex, true); + rx.Set(JsRegExp.PropertyLastIndex, nextIndex, true); } n++; @@ -788,8 +788,8 @@ private JsValue MatchAll(JsValue thisObj, JsValue[] arguments) flags }); - var lastIndex = TypeConverter.ToLength(r.Get(RegExpInstance.PropertyLastIndex)); - matcher.Set(RegExpInstance.PropertyLastIndex, lastIndex, true); + var lastIndex = TypeConverter.ToLength(r.Get(JsRegExp.PropertyLastIndex)); + matcher.Set(JsRegExp.PropertyLastIndex, lastIndex, true); var global = flags.IndexOf('g') != -1; var fullUnicode = flags.IndexOf('u') != -1; @@ -833,7 +833,7 @@ internal static JsValue RegExpExec(ObjectInstance r, string s) return result; } - var ri = r as RegExpInstance; + var ri = r as JsRegExp; if (ri is null) { ExceptionHelper.ThrowTypeError(r.Engine.Realm); @@ -857,10 +857,10 @@ internal bool TryGetDefaultExec(ObjectInstance o, [NotNullWhen((true))] out Func /// /// https://tc39.es/ecma262/#sec-regexpbuiltinexec /// - private static JsValue RegExpBuiltinExec(RegExpInstance R, string s) + private static JsValue RegExpBuiltinExec(JsRegExp R, string s) { var length = (ulong) s.Length; - var lastIndex = TypeConverter.ToLength(R.Get(RegExpInstance.PropertyLastIndex)); + var lastIndex = TypeConverter.ToLength(R.Get(JsRegExp.PropertyLastIndex)); var global = R.Global; var sticky = R.Sticky; @@ -869,7 +869,7 @@ private static JsValue RegExpBuiltinExec(RegExpInstance R, string s) lastIndex = 0; } - if (R.Source == RegExpInstance.regExpForMatchingAllCharacters) // Reg Exp is really "" + if (R.Source == JsRegExp.regExpForMatchingAllCharacters) // Reg Exp is really "" { if (lastIndex > (ulong) s.Length) { @@ -906,7 +906,7 @@ private static JsValue RegExpBuiltinExec(RegExpInstance R, string s) { if (lastIndex > length) { - R.Set(RegExpInstance.PropertyLastIndex, JsNumber.PositiveZero, true); + R.Set(JsRegExp.PropertyLastIndex, JsNumber.PositiveZero, true); return Null; } @@ -914,7 +914,7 @@ private static JsValue RegExpBuiltinExec(RegExpInstance R, string s) var success = match.Success && (!sticky || match.Index == (int) lastIndex); if (!success) { - R.Set(RegExpInstance.PropertyLastIndex, JsNumber.PositiveZero, true); + R.Set(JsRegExp.PropertyLastIndex, JsNumber.PositiveZero, true); return Null; } @@ -929,7 +929,7 @@ private static JsValue RegExpBuiltinExec(RegExpInstance R, string s) if (global || sticky) { - R.Set(RegExpInstance.PropertyLastIndex, e, true); + R.Set(JsRegExp.PropertyLastIndex, e, true); } return CreateReturnValueArray(R.Engine, matcher, match, s, fullUnicode, hasIndices); @@ -1085,7 +1085,7 @@ private static JsValue GetMatchIndexPair(Engine engine, string s, JsNumber[] mat private JsValue Exec(JsValue thisObj, JsValue[] arguments) { - var r = thisObj as RegExpInstance; + var r = thisObj as JsRegExp; if (r is null) { ExceptionHelper.ThrowTypeError(_engine.Realm); diff --git a/Jint/Native/String/StringPrototype.cs b/Jint/Native/String/StringPrototype.cs index cf41656e1f..82f584f2ec 100644 --- a/Jint/Native/String/StringPrototype.cs +++ b/Jint/Native/String/StringPrototype.cs @@ -350,7 +350,7 @@ private JsValue Split(JsValue thisObj, JsValue[] arguments) var limit = arguments.At(1); // fast path for empty regexp - if (separator is RegExpInstance R && R.Source == RegExpInstance.regExpForMatchingAllCharacters) + if (separator is JsRegExp R && R.Source == JsRegExp.regExpForMatchingAllCharacters) { separator = JsString.Empty; } @@ -518,7 +518,7 @@ private JsValue Search(JsValue thisObj, JsValue[] arguments) } } - var rx = (RegExpInstance) _realm.Intrinsics.RegExp.Construct(new[] {regex}); + var rx = (JsRegExp) _realm.Intrinsics.RegExp.Construct(new[] {regex}); var s = TypeConverter.ToJsString(thisObj); return _engine.Invoke(rx, GlobalSymbolRegistry.Search, new JsValue[] { s }); } @@ -686,7 +686,7 @@ private JsValue Match(JsValue thisObj, JsValue[] arguments) } } - var rx = (RegExpInstance) _realm.Intrinsics.RegExp.Construct(new[] {regex}); + var rx = (JsRegExp) _realm.Intrinsics.RegExp.Construct(new[] {regex}); var s = TypeConverter.ToJsString(thisObj); return _engine.Invoke(rx, GlobalSymbolRegistry.Match, new JsValue[] { s }); @@ -716,7 +716,7 @@ private JsValue MatchAll(JsValue thisObj, JsValue[] arguments) } var s = TypeConverter.ToJsString(thisObj); - var rx = (RegExpInstance) _realm.Intrinsics.RegExp.Construct(new[] { regex, "g" }); + var rx = (JsRegExp) _realm.Intrinsics.RegExp.Construct(new[] { regex, "g" }); return _engine.Invoke(rx, GlobalSymbolRegistry.MatchAll, new JsValue[] { s }); }