Browse Source

Rename RegExpInstance to JsRegExp (#1595)

Marko Lahma 2 years ago
parent
commit
40f1f420a7

+ 1 - 1
Jint.Tests/Runtime/JsValueConversionTests.cs

@@ -119,7 +119,7 @@ namespace Jint.Tests.Runtime
         [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());

+ 3 - 3
Jint/JsValueExtensions.cs

@@ -69,7 +69,7 @@ namespace Jint
                 return TypeConverter.ToBoolean(matcher);
             }
 
-            return value is RegExpInstance;
+            return value is JsRegExp;
         }
 
         [Pure]
@@ -148,14 +148,14 @@ namespace Jint
         }
 
         [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]

+ 4 - 4
Jint/Native/Iterator/IteratorInstance.cs

@@ -132,7 +132,7 @@ namespace Jint.Native.Iterator
 
         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 @@ namespace Jint.Native.Iterator
 
             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 @@ namespace Jint.Native.Iterator
                     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

+ 1 - 1
Jint/Native/Object/ObjectInstance.cs

@@ -1024,7 +1024,7 @@ namespace Jint.Native.Object
                     break;
 
                 case ObjectClass.RegExp:
-                    if (this is RegExpInstance regeExpInstance)
+                    if (this is JsRegExp regeExpInstance)
                     {
                         converted = regeExpInstance.Value;
                     }

+ 2 - 2
Jint/Native/RegExp/RegExpInstance.cs → Jint/Native/RegExp/JsRegExp.cs

@@ -5,7 +5,7 @@ using Jint.Runtime.Descriptors;
 
 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 @@ namespace Jint.Native.RegExp
 
         private PropertyDescriptor _prototypeDescriptor = null!;
 
-        public RegExpInstance(Engine engine)
+        public JsRegExp(Engine engine)
             : base(engine, ObjectClass.RegExp)
         {
             Source = regExpForMatchingAllCharacters;

+ 8 - 8
Jint/Native/RegExp/RegExpConstructor.cs

@@ -72,7 +72,7 @@ namespace Jint.Native.RegExp
 
             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 @@ namespace Jint.Native.RegExp
             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 @@ namespace Jint.Native.RegExp
             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 @@ namespace Jint.Native.RegExp
             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));
         }
     }
 }

+ 1 - 1
Jint/Native/RegExp/RegExpExtensions.cs

@@ -12,7 +12,7 @@ namespace Jint.Native.RegExp
                 return prototype.TryGetDefaultExec(prototype, out exec);
             }
 
-            if (o is RegExpInstance instance)
+            if (o is JsRegExp instance)
             {
                 exec = default;
                 return instance.Properties == null

+ 36 - 36
Jint/Native/RegExp/RegExpPrototype.cs

@@ -42,7 +42,7 @@ namespace Jint.Native.RegExp
         {
             const PropertyFlag lengthFlags = PropertyFlag.Configurable;
 
-            GetSetPropertyDescriptor CreateGetAccessorDescriptor(string name, Func<RegExpInstance, JsValue> valueExtractor, JsValue? protoValue = null)
+            GetSetPropertyDescriptor CreateGetAccessorDescriptor(string name, Func<JsRegExp, JsValue> valueExtractor, JsValue? protoValue = null)
             {
                 return new GetSetPropertyDescriptor(
                     get: new ClrFunctionInstance(Engine, name, (thisObj, arguments) =>
@@ -52,7 +52,7 @@ namespace Jint.Native.RegExp
                             return protoValue ?? Undefined;
                         }
 
-                        var r = thisObj as RegExpInstance;
+                        var r = thisObj as JsRegExp;
                         if (r is null)
                         {
                             ExceptionHelper.ThrowTypeError(_realm);
@@ -105,7 +105,7 @@ namespace Jint.Native.RegExp
                 return DefaultSource;
             }
 
-            var r = thisObj as RegExpInstance;
+            var r = thisObj as JsRegExp;
             if (r is null)
             {
                 ExceptionHelper.ThrowTypeError(_realm);
@@ -113,7 +113,7 @@ namespace Jint.Native.RegExp
 
             if (string.IsNullOrEmpty(r.Source))
             {
-                return RegExpInstance.regExpForMatchingAllCharacters;
+                return JsRegExp.regExpForMatchingAllCharacters;
             }
 
 
@@ -151,14 +151,14 @@ namespace Jint.Native.RegExp
             if (global)
             {
                 fullUnicode = flags.IndexOf('u') != -1;
-                rx.Set(RegExpInstance.PropertyLastIndex, 0, true);
+                rx.Set(JsRegExp.PropertyLastIndex, 0, true);
             }
 
             // check if we can access fast path
             if (!fullUnicode
                 && !mayHaveNamedCaptures
                 && !TypeConverter.ToBoolean(rx.Get(PropertySticky))
-                && rx is RegExpInstance rei && rei.TryGetDefaultRegExpExec(out _))
+                && rx is JsRegExp rei && rei.TryGetDefaultRegExpExec(out _))
             {
                 var count = global ? int.MaxValue : 1;
 
@@ -201,7 +201,7 @@ namespace Jint.Native.RegExp
                     result = rei.Value.Replace(s, TypeConverter.ToString(replaceValue), count);
                 }
 
-                rx.Set(RegExpInstance.PropertyLastIndex, JsNumber.PositiveZero);
+                rx.Set(JsRegExp.PropertyLastIndex, JsNumber.PositiveZero);
                 return result;
             }
 
@@ -224,9 +224,9 @@ namespace Jint.Native.RegExp
                 var matchStr = TypeConverter.ToString(result.Get(0));
                 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);
+                    rx.Set(JsRegExp.PropertyLastIndex, nextIndex);
                 }
             }
 
@@ -463,11 +463,11 @@ namespace Jint.Native.RegExp
                 return a;
             }
 
-            if (!unicodeMatching && rx is RegExpInstance R && R.TryGetDefaultRegExpExec(out _))
+            if (!unicodeMatching && rx is JsRegExp R && R.TryGetDefaultRegExpExec(out _))
             {
                 // we can take faster path
 
-                if (R.Source == RegExpInstance.regExpForMatchingAllCharacters)
+                if (R.Source == JsRegExp.regExpForMatchingAllCharacters)
                 {
                     // if empty string, just a string split
                     return StringPrototype.SplitWithStringSeparator(_realm, "", s, (uint) s.Length);
@@ -538,7 +538,7 @@ namespace Jint.Native.RegExp
             ulong currentIndex = 0;
             while (currentIndex < (ulong) s.Length)
             {
-                splitter.Set(RegExpInstance.PropertyLastIndex, currentIndex, true);
+                splitter.Set(JsRegExp.PropertyLastIndex, currentIndex, true);
                 var z = RegExpExec(splitter, s);
                 if (z.IsNull())
                 {
@@ -546,7 +546,7 @@ namespace Jint.Native.RegExp
                     continue;
                 }
 
-                var endIndex = TypeConverter.ToLength(splitter.Get(RegExpInstance.PropertyLastIndex));
+                var endIndex = TypeConverter.ToLength(splitter.Get(JsRegExp.PropertyLastIndex));
                 endIndex = System.Math.Min(endIndex, (ulong) s.Length);
                 if (endIndex == previousStringIndex)
                 {
@@ -622,15 +622,15 @@ namespace Jint.Native.RegExp
             var s = TypeConverter.ToString(arguments.At(0));
 
             // check couple fast paths
-            if (r is RegExpInstance R && !R.FullUnicode)
+            if (r is JsRegExp R && !R.FullUnicode)
             {
                 if (!R.Sticky && !R.Global)
                 {
-                    R.Set(RegExpInstance.PropertyLastIndex, 0, throwOnError: true);
+                    R.Set(JsRegExp.PropertyLastIndex, 0, throwOnError: true);
                     return R.Value.IsMatch(s);
                 }
 
-                var lastIndex = (int) TypeConverter.ToLength(R.Get(RegExpInstance.PropertyLastIndex));
+                var lastIndex = (int) TypeConverter.ToLength(R.Get(JsRegExp.PropertyLastIndex));
                 if (lastIndex >= s.Length && s.Length > 0)
                 {
                     return JsBoolean.False;
@@ -639,10 +639,10 @@ namespace Jint.Native.RegExp
                 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 @@ namespace Jint.Native.RegExp
             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 @@ namespace Jint.Native.RegExp
             }
 
             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 @@ namespace Jint.Native.RegExp
                 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 @@ namespace Jint.Native.RegExp
                 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 @@ namespace Jint.Native.RegExp
                 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 @@ namespace Jint.Native.RegExp
         /// <summary>
         /// https://tc39.es/ecma262/#sec-regexpbuiltinexec
         /// </summary>
-        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 @@ namespace Jint.Native.RegExp
                 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 @@ namespace Jint.Native.RegExp
             {
                 if (lastIndex > length)
                 {
-                    R.Set(RegExpInstance.PropertyLastIndex, JsNumber.PositiveZero, true);
+                    R.Set(JsRegExp.PropertyLastIndex, JsNumber.PositiveZero, true);
                     return Null;
                 }
 
@@ -914,7 +914,7 @@ namespace Jint.Native.RegExp
                 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 @@ namespace Jint.Native.RegExp
 
             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 @@ namespace Jint.Native.RegExp
 
         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);

+ 4 - 4
Jint/Native/String/StringPrototype.cs

@@ -350,7 +350,7 @@ namespace Jint.Native.String
             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 @@ namespace Jint.Native.String
                 }
             }
 
-            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 @@ namespace Jint.Native.String
                 }
             }
 
-            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 @@ namespace Jint.Native.String
             }
 
             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 });
         }