Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions ClearScript/V8/FastProxy/V8FastArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Numerics;
using Microsoft.ClearScript.Util;
using Microsoft.ClearScript.V8.SplitProxy;

namespace Microsoft.ClearScript.V8.FastProxy
Expand All @@ -15,23 +14,13 @@ public readonly ref struct V8FastArgs
{
private readonly ReadOnlySpan<V8Value.FastArg> args;
private readonly V8FastArgKind argKind;
private readonly object[] objects;
private readonly V8ScriptEngine engine;

internal V8FastArgs(V8ScriptEngine engine, in ReadOnlySpan<V8Value.FastArg> args, V8FastArgKind argKind)
{
this.args = args;
this.argKind = argKind;
objects = null;

for (var index = 0; index < args.Length; index++)
{
var tempObject = V8FastArgImpl.InitializeObject(engine, args[index]);
if (tempObject is not Nonexistent)
{
EnsureObjects(ref objects, args.Length);
objects[index] = tempObject;
}
}
this.engine = engine;
}

/// <summary>
Expand Down Expand Up @@ -432,18 +421,6 @@ internal V8FastArgs(V8ScriptEngine engine, in ReadOnlySpan<V8Value.FastArg> args
/// </remarks>
public T Get<T>(int index, string name = null) => V8FastArgImpl.Get<T>(args[index], GetObject(index), argKind, name);

private static void EnsureObjects(ref object[] objects, int count)
{
if (objects is null)
{
objects = new object[count];
for (var index = 0; index < count; index++)
{
objects[index] = Nonexistent.Value;
}
}
}

private object GetObject(int index) => (objects is not null) ? objects[index] : Nonexistent.Value;
private object GetObject(int index) => V8FastArgImpl.InitializeObject(engine, args[index]);
}
}