Skip to content

Commit

Permalink
Make JsArguments public
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Jan 11, 2024
1 parent 1de2334 commit e7e081b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Jint.Tests.PublicInterface/PublicInterfaceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Concurrent;
using Jint.Native;
using Jint.Native.Argument;
using Jint.Native.Function;

namespace Jint.Tests.PublicInterface;
Expand Down Expand Up @@ -38,6 +39,15 @@ public void BindFunctionInstancesArePublic()
");
}

[Fact]
public void JsArgumentsIsPublic()
{
// debuggers might want to access the information
var obj = new Engine().Execute("function f() { return arguments; }").Evaluate("f('a', 'b', 'c');");
var arguments = Assert.IsType<JsArguments>(obj);
Assert.Equal((uint) 3, arguments.Length);
}

private sealed class SetTimeoutEmulator : IDisposable
{
private readonly Engine _engine;
Expand Down
15 changes: 9 additions & 6 deletions Jint/Native/Argument/JsArguments.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading;
using Jint.Native.Function;
using Jint.Native.Object;
using Jint.Native.Symbol;
using Jint.Runtime;
Expand All @@ -13,7 +12,7 @@ namespace Jint.Native.Argument
/// <summary>
/// https://tc39.es/ecma262/#sec-arguments-exotic-objects
/// </summary>
internal sealed class JsArguments : ObjectInstance
public sealed class JsArguments : ObjectInstance
{
// cache property container for array iteration for less allocations
private static readonly ThreadLocal<HashSet<string>> _mappedNamed = new(() => new HashSet<string>(StringComparer.Ordinal));
Expand Down Expand Up @@ -102,10 +101,14 @@ protected override void Initialize()
DefinePropertyOrThrow(GlobalSymbolRegistry.Iterator, new PropertyDescriptor(iteratorFunction, PropertyFlag.Writable | PropertyFlag.Configurable));
}

public ObjectInstance? ParameterMap { get; set; }
internal ObjectInstance? ParameterMap { get; set; }

internal override bool IsArrayLike => true;

internal override bool IsIntegerIndexedArray => true;

public uint Length => (uint) _args.Length;

public override PropertyDescriptor GetOwnProperty(JsValue property)
{
EnsureInitialized();
Expand Down Expand Up @@ -154,7 +157,7 @@ public override bool Set(JsValue property, JsValue value, JsValue receiver)

if (desc.IsAccessorDescriptor())
{
if (!(desc.Set is ICallable setter))
if (desc.Set is not ICallable setter)
{
return false;
}
Expand All @@ -179,7 +182,7 @@ public override bool DefineOwnProperty(JsValue property, PropertyDescriptor desc

EnsureInitialized();

if (!(_func is null) && !ReferenceEquals(ParameterMap, null))
if (!ReferenceEquals(ParameterMap, null))
{
var map = ParameterMap;
var isMapped = map.GetOwnProperty(property);
Expand Down Expand Up @@ -220,7 +223,7 @@ public override bool Delete(JsValue property)
{
EnsureInitialized();

if (!(_func is null) && !ReferenceEquals(ParameterMap, null))
if (!ReferenceEquals(ParameterMap, null))
{
var map = ParameterMap;
var isMapped = map.GetOwnProperty(property);
Expand Down

0 comments on commit e7e081b

Please sign in to comment.