Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Jint/AstExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private static ModuleImportAttribute[] GetAttributes(in NodeList<ImportAttribute
{
if (importAttributes.Count == 0)
{
return Array.Empty<ModuleImportAttribute>();
return [];
}

var attributes = new ModuleImportAttribute[importAttributes.Count];
Expand Down
2 changes: 1 addition & 1 deletion Jint/Collections/RefStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void Resize(int value)
}
else
{
_array = Array.Empty<T>();
_array = [];
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions Jint/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ internal ManualPromise RegisterPromise()

Action<JsValue> SettleWith(Function settle) => value =>
{
settle.Call(JsValue.Undefined, new[] { value });
settle.Call(JsValue.Undefined, [value]);
RunAvailableContinuations();
};

Expand Down Expand Up @@ -833,7 +833,7 @@ internal T ExecuteWithConstraints<T>(bool strict, Func<T> callback)
/// <summary>
/// https://tc39.es/ecma262/#sec-invoke
/// </summary>
internal JsValue Invoke(JsValue v, JsValue p, JsValue[] arguments)
internal JsValue Invoke(JsValue v, JsValue p, JsCallArguments arguments)
{
var ownsContext = _activeEvaluationContext is null;
_activeEvaluationContext ??= new EvaluationContext(this);
Expand Down Expand Up @@ -1046,7 +1046,7 @@ private void GlobalDeclarationInstantiation(
/// </summary>
internal JsArguments? FunctionDeclarationInstantiation(
Function function,
JsValue[] argumentsList)
JsCallArguments argumentsList)
{
var calleeContext = ExecutionContext;
var func = function._functionDefinition;
Expand Down Expand Up @@ -1195,14 +1195,14 @@ private void GlobalDeclarationInstantiation(
private JsArguments CreateMappedArgumentsObject(
Function func,
Key[] formals,
JsValue[] argumentsList,
JsCallArguments argumentsList,
DeclarativeEnvironment envRec,
bool hasRestParameter)
{
return _argumentsInstancePool.Rent(func, formals, argumentsList, envRec, hasRestParameter);
}

private JsArguments CreateUnmappedArgumentsObject(JsValue[] argumentsList)
private JsArguments CreateUnmappedArgumentsObject(JsCallArguments argumentsList)
{
return _argumentsInstancePool.Rent(argumentsList);
}
Expand Down Expand Up @@ -1424,7 +1424,7 @@ internal ref readonly ExecutionContext UpdateGenerator(GeneratorInstance generat
/// <param name="callableName">The name of the callable.</param>
/// <param name="arguments">The arguments of the call.</param>
/// <returns>The value returned by the call.</returns>
public JsValue Call(string callableName, params JsValue[] arguments)
public JsValue Call(string callableName, params JsCallArguments arguments)
{
var callable = Evaluate(callableName);
return Call(callable, arguments);
Expand All @@ -1436,7 +1436,7 @@ public JsValue Call(string callableName, params JsValue[] arguments)
/// <param name="callable">The callable.</param>
/// <param name="arguments">The arguments of the call.</param>
/// <returns>The value returned by the call.</returns>
public JsValue Call(JsValue callable, params JsValue[] arguments)
public JsValue Call(JsValue callable, params JsCallArguments arguments)
=> Call(callable, thisObject: JsValue.Undefined, arguments);

/// <summary>
Expand All @@ -1446,7 +1446,7 @@ public JsValue Call(JsValue callable, params JsValue[] arguments)
/// <param name="thisObject">Value bound as this.</param>
/// <param name="arguments">The arguments of the call.</param>
/// <returns>The value returned by the call.</returns>
public JsValue Call(JsValue callable, JsValue thisObject, JsValue[] arguments)
public JsValue Call(JsValue callable, JsValue thisObject, JsCallArguments arguments)
{
JsValue Callback()
{
Expand All @@ -1462,7 +1462,7 @@ JsValue Callback()
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal JsValue Call(ICallable callable, JsValue thisObject, JsValue[] arguments, JintExpression? expression)
internal JsValue Call(ICallable callable, JsValue thisObject, JsCallArguments arguments, JintExpression? expression)
{
if (callable is Function functionInstance)
{
Expand All @@ -1478,7 +1478,7 @@ internal JsValue Call(ICallable callable, JsValue thisObject, JsValue[] argument
/// <param name="constructorName">The name of the constructor to call.</param>
/// <param name="arguments">The arguments of the constructor call.</param>
/// <returns>The value returned by the constructor call.</returns>
public ObjectInstance Construct(string constructorName, params JsValue[] arguments)
public ObjectInstance Construct(string constructorName, params JsCallArguments arguments)
{
var constructor = Evaluate(constructorName);
return Construct(constructor, arguments);
Expand All @@ -1490,7 +1490,7 @@ public ObjectInstance Construct(string constructorName, params JsValue[] argumen
/// <param name="constructor">The name of the constructor to call.</param>
/// <param name="arguments">The arguments of the constructor call.</param>
/// <returns>The value returned by the constructor call.</returns>
public ObjectInstance Construct(JsValue constructor, params JsValue[] arguments)
public ObjectInstance Construct(JsValue constructor, params JsCallArguments arguments)
{
ObjectInstance Callback()
{
Expand All @@ -1507,7 +1507,7 @@ ObjectInstance Callback()

internal ObjectInstance Construct(
JsValue constructor,
JsValue[] arguments,
JsCallArguments arguments,
JsValue newTarget,
JintExpression? expression)
{
Expand All @@ -1525,7 +1525,7 @@ internal JsValue Call(Function function, JsValue thisObject)
internal JsValue Call(
Function function,
JsValue thisObject,
JsValue[] arguments,
JsCallArguments arguments,
JintExpression? expression)
{
// ensure logic is in sync between Call, Construct, engine.Invoke and JintCallExpression!
Expand Down Expand Up @@ -1557,7 +1557,7 @@ internal JsValue Call(

private ObjectInstance Construct(
Function function,
JsValue[] arguments,
JsCallArguments arguments,
JsValue newTarget,
JintExpression? expression)
{
Expand Down Expand Up @@ -1612,7 +1612,7 @@ public void Dispose()
#else
// we can expect that reflection is OK as we've been generating object wrappers already
var clearMethod = _objectWrapperCache.GetType().GetMethod("Clear", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
clearMethod?.Invoke(_objectWrapperCache, Array.Empty<object>());
clearMethod?.Invoke(_objectWrapperCache, []);
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions Jint/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
global using PropertyDictionary = Jint.Collections.HybridDictionary<Jint.Runtime.Descriptors.PropertyDescriptor>;
global using SymbolDictionary = Jint.Collections.DictionarySlim<Jint.Native.JsSymbol, Jint.Runtime.Descriptors.PropertyDescriptor>;

global using JsCallDelegate = System.Func<Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue>;
global using JsCallArguments = Jint.Native.JsValue[];
4 changes: 2 additions & 2 deletions Jint/JsValueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ public static JsValue Call(this JsValue value, JsValue arg1, JsValue arg2, JsVal
}

[Pure]
public static JsValue Call(this JsValue value, params JsValue[] arguments)
public static JsValue Call(this JsValue value, params JsCallArguments arguments)
{
if (value is ObjectInstance objectInstance)
{
Expand All @@ -618,7 +618,7 @@ public static JsValue Call(this JsValue value, params JsValue[] arguments)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static JsValue Call(this JsValue value, JsValue thisObj, JsValue[] arguments)
public static JsValue Call(this JsValue value, JsValue thisObj, JsCallArguments arguments)
{
if (value is ObjectInstance objectInstance)
{
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/AggregateError/AggregateErrorConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ internal AggregateErrorConstructor(

private AggregateErrorPrototype PrototypeObject { get; }

protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
protected internal override JsValue Call(JsValue thisObject, JsCallArguments arguments)
{
return Construct(arguments, this);
}

/// <summary>
/// https://tc39.es/ecma262/#sec-nativeerror
/// </summary>
public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
public override ObjectInstance Construct(JsCallArguments arguments, JsValue newTarget)
{
var errors = arguments.At(0);
var message = arguments.At(1);
Expand Down
50 changes: 22 additions & 28 deletions Jint/Native/Array/ArrayConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override void Initialize()
/// <summary>
/// https://tc39.es/ecma262/#sec-array.from
/// </summary>
private JsValue From(JsValue thisObject, JsValue[] arguments)
private JsValue From(JsValue thisObject, JsCallArguments arguments)
{
var items = arguments.At(0);
var mapFunction = arguments.At(1);
Expand All @@ -69,7 +69,7 @@ private JsValue From(JsValue thisObject, JsValue[] arguments)
ObjectInstance instance;
if (!ReferenceEquals(this, thisObject) && thisObject is IConstructor constructor)
{
instance = constructor.Construct(System.Array.Empty<JsValue>(), thisObject);
instance = constructor.Construct([], thisObject);
}
else
{
Expand Down Expand Up @@ -185,13 +185,13 @@ protected override void IterationEnd()
}
}

private JsValue Of(JsValue thisObject, JsValue[] arguments)
private JsValue Of(JsValue thisObject, JsCallArguments arguments)
{
var len = arguments.Length;
ObjectInstance a;
if (thisObject.IsConstructor)
{
a = ((IConstructor) thisObject).Construct(new JsValue[] { len }, thisObject);
a = ((IConstructor) thisObject).Construct([len], thisObject);
}
else
{
Expand All @@ -203,7 +203,7 @@ private JsValue Of(JsValue thisObject, JsValue[] arguments)
// faster for real arrays
for (uint k = 0; k < arguments.Length; k++)
{
var kValue = arguments[k];
var kValue = arguments[(int)k];
ai.SetIndexValue(k, kValue, updateLength: k == arguments.Length - 1);
}
}
Expand All @@ -212,7 +212,7 @@ private JsValue Of(JsValue thisObject, JsValue[] arguments)
// slower version
for (uint k = 0; k < arguments.Length; k++)
{
var kValue = arguments[k];
var kValue = arguments[(int)k];
var key = JsString.Create(k);
a.CreateDataPropertyOrThrow(key, kValue);
}
Expand All @@ -223,12 +223,12 @@ private JsValue Of(JsValue thisObject, JsValue[] arguments)
return a;
}

private static JsValue Species(JsValue thisObject, JsValue[] arguments)
private static JsValue Species(JsValue thisObject, JsCallArguments arguments)
{
return thisObject;
}

private static JsValue IsArray(JsValue thisObject, JsValue[] arguments)
private static JsValue IsArray(JsValue thisObject, JsCallArguments arguments)
{
var o = arguments.At(0);

Expand All @@ -245,17 +245,17 @@ private static JsValue IsArray(JsValue o)
return oi.IsArray();
}

protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
protected internal override JsValue Call(JsValue thisObject, JsCallArguments arguments)
{
return Construct(arguments, thisObject);
}

public JsArray Construct(JsValue[] arguments)
public JsArray Construct(JsCallArguments arguments)
{
return (JsArray) Construct(arguments, this);
}

public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
public override ObjectInstance Construct(JsCallArguments arguments, JsValue newTarget)
{
if (newTarget.IsUndefined())
{
Expand All @@ -279,20 +279,20 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)

public JsArray Construct(int capacity)
{
return Construct(System.Array.Empty<JsValue>(), (uint) capacity);
return Construct([], (uint) capacity);
}

public JsArray Construct(uint capacity)
{
return Construct(System.Array.Empty<JsValue>(), capacity);
return Construct([], capacity);
}

public JsArray Construct(JsValue[] arguments, uint capacity)
public JsArray Construct(JsCallArguments arguments, uint capacity)
{
return Construct(arguments, capacity, PrototypeObject);
}

private JsArray Construct(JsValue[] arguments, ulong capacity, ObjectInstance prototypeObject)
private JsArray Construct(JsCallArguments arguments, ulong capacity, ObjectInstance prototypeObject)
{
JsArray instance;
if (arguments.Length == 1)
Expand Down Expand Up @@ -367,22 +367,16 @@ private JsArray ConstructArrayFromIEnumerable(IEnumerable enumerable)

public JsArray ConstructFast(JsValue[] contents)
{
var instance = ArrayCreate((ulong) contents.Length);
for (var i = 0; i < contents.Length; i++)
{
instance.SetIndexValue((uint) i, contents[i], updateLength: false);
}
return instance;
var array = new JsValue[contents.Length];
System.Array.Copy(contents, array, contents.Length);
return new JsArray(_engine, array);
}

internal JsArray ConstructFast(List<JsValue> contents)
{
var instance = ArrayCreate((ulong) contents.Count);
for (var i = 0; i < contents.Count; i++)
{
instance.SetIndexValue((uint) i, contents[i], updateLength: false);
}
return instance;
var array = new JsValue[contents.Count];
contents.CopyTo(array);
return new JsArray(_engine, array);
}

/// <summary>
Expand Down Expand Up @@ -430,7 +424,7 @@ internal ObjectInstance ArraySpeciesCreate(ObjectInstance originalArray, ulong l
ExceptionHelper.ThrowTypeError(_realm, $"{c} is not a constructor");
}

return ((IConstructor) c).Construct(new JsValue[] { JsNumber.Create(length) }, c);
return ((IConstructor) c).Construct([JsNumber.Create(length)], c);
}

internal JsArray CreateArrayFromList<T>(List<T> values) where T : JsValue
Expand Down
8 changes: 4 additions & 4 deletions Jint/Native/Array/ArrayInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ArrayInstance : ObjectInstance, IEnumerable<JsValue>

private protected ArrayInstance(Engine engine, InternalTypes type) : base(engine, type: type)
{
_dense = System.Array.Empty<JsValue?>();
_dense = [];
}

private protected ArrayInstance(Engine engine, uint capacity = 0, uint length = 0) : base(engine, type: InternalTypes.Object | InternalTypes.Array)
Expand All @@ -36,7 +36,7 @@ private protected ArrayInstance(Engine engine, uint capacity = 0, uint length =

if (capacity < MaxDenseArrayLength)
{
_dense = capacity > 0 ? new JsValue?[capacity] : System.Array.Empty<JsValue?>();
_dense = capacity > 0 ? new JsValue?[capacity] : [];
}
else
{
Expand Down Expand Up @@ -1151,7 +1151,7 @@ private void WriteValueSlow(double n, JsValue value)
}
}

internal JsArray Map(JsValue[] arguments)
internal JsArray Map(JsCallArguments arguments)
{
var callbackfn = arguments.At(0);
var thisArg = arguments.At(1);
Expand Down Expand Up @@ -1186,7 +1186,7 @@ internal JsArray Map(JsValue[] arguments)

/// <inheritdoc />
internal sealed override bool FindWithCallback(
JsValue[] arguments,
JsCallArguments arguments,
out ulong index,
out JsValue value,
bool visitUnassigned,
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Array/ArrayOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ private sealed class ArrayReadOperations : ArrayOperations
public ArrayReadOperations(JsArray target)
{
_target = target;
_data = target._dense ?? System.Array.Empty<JsValue>();
_data = target._dense ?? [];
_length = target.Length;
}

Expand Down
Loading