Skip to content

Commit

Permalink
Rename RegExpInstance to JsRegExp (#1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Jul 28, 2023
1 parent a41a0e3 commit 40f1f42
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Jint.Tests/Runtime/JsValueConversionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions Jint/JsValueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static bool IsRegExp(this JsValue value)
return TypeConverter.ToBoolean(matcher);
}

return value is RegExpInstance;
return value is JsRegExp;
}

[Pure]
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions Jint/Native/Iterator/IteratorInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Object/ObjectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions Jint/Native/RegExp/RegExpConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
}
}
2 changes: 1 addition & 1 deletion Jint/Native/RegExp/RegExpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 40f1f42

Please sign in to comment.