Skip to content

Commit

Permalink
Add net60 target (#1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Mar 27, 2023
1 parent 1985f7e commit 75a7b12
Show file tree
Hide file tree
Showing 32 changed files with 106 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Jint/EsprimaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal static string LiteralKeyToString(Literal literal)
return TypeConverter.ToString(d);
}

return literal.Value as string ?? Convert.ToString(literal.Value, provider: null);
return literal.Value as string ?? Convert.ToString(literal.Value, provider: null) ?? "";
}

internal static void GetBoundNames(this VariableDeclaration variableDeclaration, List<string> target)
Expand Down
4 changes: 2 additions & 2 deletions Jint/Extensions/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static object AsNumberOfType(this double d, TypeCode type)
}

public static bool TryConvertViaTypeCoercion(
Type memberType,
Type? memberType,
ValueCoercionType valueCoercionType,
JsValue value,
[NotNullWhen(true)] out object? converted)
Expand Down Expand Up @@ -155,7 +155,7 @@ public static bool TryConvertViaTypeCoercion(
return true;
}

if (memberType.IsClrNumericCoercible() && (valueCoercionType & ValueCoercionType.Number) != 0)
if (memberType is not null && memberType.IsClrNumericCoercible() && (valueCoercionType & ValueCoercionType.Number) != 0)
{
// we know how to print out correct string presentation for primitives
// that are non-null and non-undefined
Expand Down
2 changes: 1 addition & 1 deletion Jint/Jint.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NeutralLanguage>en-US</NeutralLanguage>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>Jint.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion Jint/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public bool Equals(Key other)
return HashCode == other.HashCode && Name == other.Name;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is Key other && Equals(other);
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Argument/ArgumentsInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected override void Initialize()
ObjectInstance? map = null;
if (args.Length > 0)
{
var mappedNamed = _mappedNamed.Value;
var mappedNamed = _mappedNamed.Value!;
mappedNamed.Clear();

map = Engine.Realm.Intrinsics.Object.Construct(Arguments.Empty);
Expand Down
11 changes: 9 additions & 2 deletions Jint/Native/Array/ArrayInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,14 @@ private void ConvertToSparse()

internal void EnsureCapacity(uint capacity, bool force = false)
{
if (!force && (capacity > MaxDenseArrayLength || _dense is null || capacity <= (uint) _dense.Length))
var dense = _dense;

if (dense is null)
{
return;
}

if (!force && (capacity > MaxDenseArrayLength || capacity <= (uint) dense.Length))
{
return;
}
Expand All @@ -956,7 +963,7 @@ internal void EnsureCapacity(uint capacity, bool force = false)

// need to grow
var newArray = new object[capacity];
System.Array.Copy(_dense, newArray, _dense!.Length);
System.Array.Copy(dense, newArray, dense.Length);
_dense = newArray;
_isObjectArray = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Array/ArrayPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ private ArrayComparer(Engine? engine, ICallable? compare)
_compare = compare;
}

public int Compare(JsValue x, JsValue y)
public int Compare(JsValue? x, JsValue? y)
{
var xIsNull = ReferenceEquals(x, null);
var yIsNull = ReferenceEquals(y, null);
Expand Down
7 changes: 4 additions & 3 deletions Jint/Native/ArrayBuffer/ArrayBufferInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ internal ArrayBufferInstance CloneArrayBuffer(
{
var targetBuffer = constructor.AllocateArrayBuffer(_engine.Realm.Intrinsics.ArrayBuffer, srcLength);
AssertNotDetached();
var srcBlock = _arrayBufferData;
var targetBlock = targetBuffer.ArrayBufferData;

var srcBlock = _arrayBufferData!;
var targetBlock = targetBuffer.ArrayBufferData!;

// TODO SharedArrayBuffer would use this
//CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, srcLength).
Expand Down Expand Up @@ -202,7 +203,7 @@ internal void SetValueInBuffer(
ArrayBufferOrder order,
bool? isLittleEndian = null)
{
var block = _arrayBufferData;
var block = _arrayBufferData!;
if (!IsSharedArrayBuffer)
{
// If isLittleEndian is not present, set isLittleEndian to the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/ArrayBuffer/ArrayBufferPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private JsValue Slice(JsValue thisObj, JsValue[] arguments)

var fromBuf = o.ArrayBufferData;
var toBuf = bufferInstance.ArrayBufferData;
System.Array.Copy(fromBuf, first, toBuf, 0, newLen);
System.Array.Copy(fromBuf!, first, toBuf!, 0, newLen);
return bufferInstance;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Error/ErrorInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ internal void InstallErrorCause(JsValue options)

public override string ToString()
{
return Engine.Realm.Intrinsics.Error.PrototypeObject.ToString(this, Arguments.Empty).ToObject().ToString();
return Engine.Realm.Intrinsics.Error.PrototypeObject.ToString(this, Arguments.Empty).ToObject().ToString() ?? "";
}
}
2 changes: 1 addition & 1 deletion Jint/Native/JsBigInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override bool IsLooselyEqual(JsValue value)
return false;
}

public override bool Equals(object other)
public override bool Equals(object? other)
{
return Equals(other as JsBigInt);
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/JsString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public override bool IsLooselyEqual(JsValue value)
return base.IsLooselyEqual(value);
}

public sealed override bool Equals(object obj)
public sealed override bool Equals(object? obj)
{
return Equals(obj as JsString);
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/JsValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public virtual bool IsLooselyEqual(JsValue value)
/// <summary>
/// Strict equality.
/// </summary>
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as JsValue);
}
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/SameValueZeroComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal sealed class SameValueZeroComparer : IEqualityComparer<JsValue>
{
public static readonly SameValueZeroComparer Instance = new();

bool IEqualityComparer<JsValue>.Equals(JsValue x, JsValue y)
bool IEqualityComparer<JsValue>.Equals(JsValue? x, JsValue? y)
{
return Equals(x, y);
}
Expand All @@ -17,7 +17,7 @@ public int GetHashCode(JsValue obj)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool Equals(JsValue x, JsValue y)
internal static bool Equals(JsValue? x, JsValue? y)
{
return x == y || x is JsNumber xNum && y is JsNumber yNum && double.IsNaN(xNum._value) && double.IsNaN(yNum._value);
}
Expand Down
6 changes: 3 additions & 3 deletions Jint/Native/String/StringExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ private StringExecutionContext()
{
}

public List<string> SplitSegmentList => _splitSegmentList = _splitSegmentList ?? new List<string>();
public List<string> SplitSegmentList => _splitSegmentList ??= new List<string>();

public string[] SplitArray1 => _splitArray1 = _splitArray1 ?? new string[1];
public string[] SplitArray1 => _splitArray1 ??= new string[1];

public static StringExecutionContext Current => _executionContext.Value;
public static StringExecutionContext Current => _executionContext.Value!;
}
}
22 changes: 21 additions & 1 deletion Jint/Native/TypedArray/IntrinsicTypedArrayPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,8 +1435,28 @@ private TypedArrayComparer(ArrayBufferInstance buffer, ICallable? compare)
_compare = compare;
}

public int Compare(JsValue x, JsValue y)
public int Compare(JsValue? x, JsValue? y)
{
if (x is null && y is null)
{
return 0;
}

if (x is not null && y is null)
{
return 1;
}

if (x is null)
{
return -1;
}

if (y is null)
{
return 1;
}

if (_compare is not null)
{
_comparableArray[0] = x;
Expand Down
32 changes: 16 additions & 16 deletions Jint/Native/TypedArray/TypedArrayValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,86 +66,86 @@ public TypeCode GetTypeCode()
return default;
}

public bool ToBoolean(IFormatProvider provider)
public bool ToBoolean(IFormatProvider? provider)
{
ExceptionHelper.ThrowNotImplementedException();
return default;
}

public char ToChar(IFormatProvider provider)
public char ToChar(IFormatProvider? provider)
{
ExceptionHelper.ThrowNotImplementedException();
return default;
}

public sbyte ToSByte(IFormatProvider provider)
public sbyte ToSByte(IFormatProvider? provider)
{
return (sbyte) DoubleValue;
}

public byte ToByte(IFormatProvider provider)
public byte ToByte(IFormatProvider? provider)
{
return (byte) DoubleValue;
}

public short ToInt16(IFormatProvider provider)
public short ToInt16(IFormatProvider? provider)
{
return (short) DoubleValue;
}

public ushort ToUInt16(IFormatProvider provider)
public ushort ToUInt16(IFormatProvider? provider)
{
return (ushort) DoubleValue;
}

public int ToInt32(IFormatProvider provider)
public int ToInt32(IFormatProvider? provider)
{
return (int) DoubleValue;
}

public uint ToUInt32(IFormatProvider provider)
public uint ToUInt32(IFormatProvider? provider)
{
return (uint) DoubleValue;
}

public long ToInt64(IFormatProvider provider)
public long ToInt64(IFormatProvider? provider)
{
return (long) BigInteger;
}

public ulong ToUInt64(IFormatProvider provider)
public ulong ToUInt64(IFormatProvider? provider)
{
return (ulong) BigInteger;
}

public float ToSingle(IFormatProvider provider)
public float ToSingle(IFormatProvider? provider)
{
return (float) DoubleValue;
}

public double ToDouble(IFormatProvider provider)
public double ToDouble(IFormatProvider? provider)
{
return DoubleValue;
}

public decimal ToDecimal(IFormatProvider provider)
public decimal ToDecimal(IFormatProvider? provider)
{
return (decimal) DoubleValue;
}

public DateTime ToDateTime(IFormatProvider provider)
public DateTime ToDateTime(IFormatProvider? provider)
{
ExceptionHelper.ThrowNotImplementedException();
return default;
}

public string ToString(IFormatProvider provider)
public string ToString(IFormatProvider? provider)
{
ExceptionHelper.ThrowNotImplementedException();
return default;
}

public object ToType(Type conversionType, IFormatProvider provider)
public object ToType(Type conversionType, IFormatProvider? provider)
{
if (conversionType == typeof(BigInteger) && Type == Types.BigInt)
{
Expand Down
2 changes: 1 addition & 1 deletion Jint/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public class InteropOptions
/// <summary>
/// Strategy to create a CLR object to hold converted <see cref="ObjectInstance"/>.
/// </summary>
public Func<ObjectInstance, IDictionary<string, object>> CreateClrObject = _ => new ExpandoObject();
public Func<ObjectInstance, IDictionary<string, object?>> CreateClrObject = _ => new ExpandoObject();

/// <summary>
/// Strategy to create a CLR object from TypeReference.
Expand Down
16 changes: 8 additions & 8 deletions Jint/Runtime/Interop/DefaultTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class DefaultTypeConverter : ITypeConverter
private static readonly Type engineType = typeof(Engine);
private static readonly Type typeType = typeof(Type);

private static readonly MethodInfo convertChangeType = typeof(Convert).GetMethod("ChangeType", new[] { objectType, typeType, typeof(IFormatProvider) });
private static readonly MethodInfo jsValueFromObject = jsValueType.GetMethod(nameof(JsValue.FromObject));
private static readonly MethodInfo jsValueToObject = jsValueType.GetMethod(nameof(JsValue.ToObject));
private static readonly MethodInfo convertChangeType = typeof(Convert).GetMethod("ChangeType", new[] { objectType, typeType, typeof(IFormatProvider) })!;
private static readonly MethodInfo jsValueFromObject = jsValueType.GetMethod(nameof(JsValue.FromObject))!;
private static readonly MethodInfo jsValueToObject = jsValueType.GetMethod(nameof(JsValue.ToObject))!;


public DefaultTypeConverter(Engine engine)
Expand Down Expand Up @@ -86,7 +86,7 @@ private bool TryConvert(object? value, Type type, IFormatProvider formatProvider

if (type.IsNullable())
{
type = Nullable.GetUnderlyingType(type);
type = Nullable.GetUnderlyingType(type)!;
}

if (type.IsEnum)
Expand Down Expand Up @@ -136,7 +136,7 @@ private bool TryConvert(object? value, Type type, IFormatProvider formatProvider
return false;
}

var targetElementType = type.GetElementType();
var targetElementType = type.GetElementType()!;
var itemsConverted = new object?[source.Length];
for (var i = 0; i < source.Length; i++)
{
Expand Down Expand Up @@ -197,7 +197,7 @@ private bool TryConvert(object? value, Type type, IFormatProvider formatProvider
}
}

var obj = Activator.CreateInstance(type, constructorParameters);
var obj = Activator.CreateInstance(type, constructorParameters)!;

var members = type.GetMembers();
foreach (var member in members)
Expand Down Expand Up @@ -248,7 +248,7 @@ private bool TryConvert(object? value, Type type, IFormatProvider formatProvider
private Delegate BuildDelegate(Type type, Func<JsValue, JsValue[], JsValue> function)
{
var method = type.GetMethod("Invoke");
var arguments = method.GetParameters();
var arguments = method!.GetParameters();

var parameters = new ParameterExpression[arguments.Length];
for (var i = 0; i < parameters.Length; i++)
Expand Down Expand Up @@ -336,7 +336,7 @@ private static bool TryCastWithOperators(object value, Type type, Type valueType
try
{
converted = castOperator.Invoke(null, new[] { value });
return true;
return converted is not null;
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Interop/DelegateWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected internal override JsValue Call(JsValue thisObject, JsValue[] jsArgumen
{
converted = Engine.ClrTypeConverter.Convert(
value.ToObject(),
paramsParameterType,
paramsParameterType!,
CultureInfo.InvariantCulture);
}

Expand Down
Loading

0 comments on commit 75a7b12

Please sign in to comment.