From e7e081b88808b9cb4e8411282036bcc606cf072a Mon Sep 17 00:00:00 2001 From: Marko Lahma Date: Thu, 11 Jan 2024 20:20:38 +0200 Subject: [PATCH] Make JsArguments public --- .../PublicInterfaceTests.cs | 10 ++++++++++ Jint/Native/Argument/JsArguments.cs | 15 +++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Jint.Tests.PublicInterface/PublicInterfaceTests.cs b/Jint.Tests.PublicInterface/PublicInterfaceTests.cs index 3dca962912..3eb80c01b6 100644 --- a/Jint.Tests.PublicInterface/PublicInterfaceTests.cs +++ b/Jint.Tests.PublicInterface/PublicInterfaceTests.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using Jint.Native; +using Jint.Native.Argument; using Jint.Native.Function; namespace Jint.Tests.PublicInterface; @@ -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(obj); + Assert.Equal((uint) 3, arguments.Length); + } + private sealed class SetTimeoutEmulator : IDisposable { private readonly Engine _engine; diff --git a/Jint/Native/Argument/JsArguments.cs b/Jint/Native/Argument/JsArguments.cs index dae028ae3d..a310eadca5 100644 --- a/Jint/Native/Argument/JsArguments.cs +++ b/Jint/Native/Argument/JsArguments.cs @@ -1,5 +1,4 @@ using System.Threading; -using Jint.Native.Function; using Jint.Native.Object; using Jint.Native.Symbol; using Jint.Runtime; @@ -13,7 +12,7 @@ namespace Jint.Native.Argument /// /// https://tc39.es/ecma262/#sec-arguments-exotic-objects /// - internal sealed class JsArguments : ObjectInstance + public sealed class JsArguments : ObjectInstance { // cache property container for array iteration for less allocations private static readonly ThreadLocal> _mappedNamed = new(() => new HashSet(StringComparer.Ordinal)); @@ -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(); @@ -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; } @@ -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); @@ -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);