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
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<value>Invalid argument: {0} can not be null.</value>
</data>
<data name="ArgumentCannotBeNullWithLength" xml:space="preserve">
<value>Invalid argument: {0} can not be null and must have a length</value>
<value>Invalid argument: {0} can not be null and must have a length.</value>
</data>
<data name="SystemRuntimeInteropServicesJavaScript_PlatformNotSupported" xml:space="preserve">
<value>System.Runtime.InteropServices.JavaScript is not supported on this platform.</value>
Expand All @@ -135,4 +135,73 @@
<data name="UnableCastObjectToType" xml:space="preserve">
<value>Unable to cast object of type {0} to type {1}.</value>
</data>
<data name="MissingManagedEntrypointHandle" xml:space="preserve">
<value>Managed entrypoint handle is not set.</value>
</data>
<data name="CannotResolveManagedEntrypointHandle" xml:space="preserve">
<value>Cannot resolve managed entrypoint handle.</value>
</data>
<data name="ReturnTypeNotSupportedForMain" xml:space="preserve">
<value>Return type '{0}' from main method in not supported.</value>
</data>
<data name="NullToManagedCallback" xml:space="preserve">
<value>ToManagedCallback is null.</value>
</data>
<data name="NullTaskCallback" xml:space="preserve">
<value>TaskCallback is null.</value>
</data>
<data name="EmptyProfileData" xml:space="preserve">
<value>Empty profile data.</value>
</data>
<data name="ErrorLegacySettingProperty" xml:space="preserve">
<value>Error setting {0} on (js-obj js '{1}'): {2}.</value>
</data>
<data name="ErrorResolvingFromGlobalThis" xml:space="preserve">
<value>Error resolving property {0} from globalThis.</value>
</data>
<data name="FailedToMarshalException" xml:space="preserve">
<value>Failed to marshal exception.</value>
</data>
<data name="FailedToMarshalTaskCallback" xml:space="preserve">
<value>Failed to marshal Task callback.</value>
</data>
<data name="InvalidInFlightCounter" xml:space="preserve">
<value>Invalid InFlightCounter for JSObject {0}, expected: {1}, actual: {2}.</value>
</data>
<data name="ToJSNotImplemented" xml:space="preserve">
<value>ToJS for {0} is not implemented.</value>
</data>
<data name="ToManagedNotImplemented" xml:space="preserve">
<value>ToManaged for {0} is not implemented.</value>
</data>
<data name="UnableToResolveHandleAsException" xml:space="preserve">
<value>Unable to resolve the handle as an Exception.</value>
</data>
<data name="UnsupportedArrayType" xml:space="preserve">
<value>Unsupported array type {0}. Only single-dimensional arrays with a zero lower bound can be marshaled to JS.</value>
</data>
<data name="UnsupportedElementType" xml:space="preserve">
<value>Unsupported element type {0}.</value>
</data>
<data name="UnsupportedEnumType" xml:space="preserve">
<value>Unsupported enum type {0}.</value>
</data>
<data name="UnsupportedLegacyMarshlerType" xml:space="preserve">
<value>Unsupported marshal type {0}.</value>
</data>
<data name="UnsupportedNullableType" xml:space="preserve">
<value>Unsupported nullable type {0}.</value>
</data>
<data name="UnsupportedTaskResultType" xml:space="preserve">
<value>Unsupported task result type {0}.</value>
</data>
<data name="UriConstructorMissing" xml:space="preserve">
<value>Constructor on type 'System.Uri' not found. Please consider to protect it's constructor from trimming.</value>
</data>
<data name="UriTypeMissing" xml:space="preserve">
<value>The type System.Uri could not be found. Please consider to protect the class and it's constructor from trimming.</value>
</data>
<data name="ValueOutOf52BitRange" xml:space="preserve">
<value>Overflow: value {0} is out of {1} {2} range.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public static void CallEntrypoint(JSMarshalerArgument* arguments_buffer)
arg_1.ToManaged(out IntPtr entrypointPtr);
if (entrypointPtr == IntPtr.Zero)
{
throw new MissingMethodException("Missing entrypoint");
throw new MissingMethodException(SR.MissingManagedEntrypointHandle);
}

RuntimeMethodHandle methodHandle = JSHostImplementation.GetMethodHandleFromIntPtr(entrypointPtr);
// this would not work for generic types. But Main() could not be generic, so we are fine.
MethodInfo? method = MethodBase.GetMethodFromHandle(methodHandle) as MethodInfo;
if (method == null)
{
throw new InvalidProgramException("Can't resolve entrypoint handle");
throw new InvalidOperationException(SR.CannotResolveManagedEntrypointHandle);
}

arg_2.ToManaged(out string?[]? args);
Expand Down Expand Up @@ -75,7 +75,7 @@ public static void CallEntrypoint(JSMarshalerArgument* arguments_buffer)
}
else
{
throw new InvalidProgramException($"Return type '{method.ReturnType.FullName}' from main method in not supported");
throw new InvalidOperationException(SR.Format(SR.ReturnTypeNotSupportedForMain, method.ReturnType.FullName));
}
arg_result.ToJS(result, (ref JSMarshalerArgument arg, int value) =>
{
Expand Down Expand Up @@ -154,7 +154,7 @@ public static void CallDelegate(JSMarshalerArgument* arguments_buffer)
}
else
{
throw new InvalidOperationException("ToManagedCallback is null");
throw new InvalidOperationException(SR.NullToManagedCallback);
}
}
catch (Exception ex)
Expand All @@ -181,7 +181,7 @@ public static void CompleteTask(JSMarshalerArgument* arguments_buffer)
}
else
{
throw new InvalidOperationException("TaskCallback is null");
throw new InvalidOperationException(SR.NullTaskCallback);
}
}
catch (Exception ex)
Expand All @@ -206,7 +206,7 @@ public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer)
}
else
{
throw new InvalidOperationException("Exception is null");
throw new InvalidOperationException(SR.UnableToResolveHandleAsException);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -243,7 +243,7 @@ public static void StopProfile()
public static unsafe void DumpAotProfileData(ref byte buf, int len, string extraArg)
{
if (len == 0)
throw new JSException("Profile data length is 0");
throw new InvalidOperationException(SR.EmptyProfileData);

var arr = new byte[len];
fixed (void* p = &buf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static object GetGlobalObject(string? str = null)
Interop.Runtime.GetGlobalObjectRef(str, out exception, out object jsObj);

if (exception != 0)
throw new JSException($"Error obtaining a handle to global {str}");
throw new JSException(SR.Format(SR.ErrorResolvingFromGlobalThis, str));

JSHostImplementation.ReleaseInFlight(jsObj);
return jsObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ public static void CreateUriRef(string uri, out object? result)
uriType = Type.GetType(sb.ToString());
}
// See: https://devblogs.microsoft.com/dotnet/customizing-trimming-in-net-core-5/
if (uriType == null) throw new InvalidProgramException("The type System.Uri could not be found. Please consider to protect the class and it's constructor from trimming.");
if (uriType == null) throw new InvalidOperationException(SR.UriTypeMissing);
try
{
result = Activator.CreateInstance(uriType, uri);
}
catch (MissingMethodException ex)
{
throw new MissingMethodException("Constructor on type 'System.Uri' not found. Please consider to protect it's constructor from trimming.", ex);
throw new MissingMethodException(SR.UriConstructorMissing, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static void ThrowException(ref JSMarshalerArgument arg)
{
throw ex;
}
throw new InvalidProgramException();
throw new InvalidOperationException();
}

public static async Task<JSObject> ImportAsync(string moduleName, string moduleUrl, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ public static JSMarshalerType Function(JSMarshalerType arg1, JSMarshalerType arg
});
}

internal static void CheckNullable(JSMarshalerType underlyingSig)
internal static void CheckNullable(JSMarshalerType underlyingType)
{
MarshalerType underlying = underlyingSig._signatureType.Type;
MarshalerType underlying = underlyingType._signatureType.Type;
if (underlying == MarshalerType.Boolean
|| underlying == MarshalerType.Byte
|| underlying == MarshalerType.Int16
Expand All @@ -444,35 +444,35 @@ internal static void CheckNullable(JSMarshalerType underlyingSig)
|| underlying == MarshalerType.DateTime
|| underlying == MarshalerType.DateTimeOffset
) return;
throw new ArgumentException("Bad nullable value type");
throw new ArgumentException(SR.Format(SR.UnsupportedNullableType, underlying), nameof(underlyingType));
}

internal static void CheckArray(JSMarshalerType underlyingSig)
internal static void CheckArray(JSMarshalerType underlyingType)
{
MarshalerType underlying = underlyingSig._signatureType.Type;
MarshalerType underlying = underlyingType._signatureType.Type;
if (underlying == MarshalerType.Byte
|| underlying == MarshalerType.Int32
|| underlying == MarshalerType.Double
|| underlying == MarshalerType.String
|| underlying == MarshalerType.Object
|| underlying == MarshalerType.JSObject
) return;
throw new ArgumentException("Bad array element type");
throw new ArgumentException(SR.Format(SR.UnsupportedElementType, underlying), nameof(underlyingType));
}

internal static void CheckArraySegment(JSMarshalerType underlyingSig)
internal static void CheckArraySegment(JSMarshalerType underlyingType)
{
MarshalerType underlying = underlyingSig._signatureType.Type;
MarshalerType underlying = underlyingType._signatureType.Type;
if (underlying == MarshalerType.Byte
|| underlying == MarshalerType.Int32
|| underlying == MarshalerType.Double
) return;
throw new ArgumentException("Bad array element type");
throw new ArgumentException(SR.Format(SR.UnsupportedElementType, underlying), nameof(underlyingType));
}

internal static void CheckTask(JSMarshalerType underlyingSig)
internal static void CheckTask(JSMarshalerType underlyingType)
{
MarshalerType underlying = underlyingSig._signatureType.Type;
MarshalerType underlying = underlyingType._signatureType.Type;
// TODO maybe allow Task<byte[]> and Task<int[]> which don't need element marshaler
if (underlying == MarshalerType.Array
|| underlying == MarshalerType.ArraySegment
Expand All @@ -483,7 +483,7 @@ internal static void CheckTask(JSMarshalerType underlyingSig)
|| underlying == MarshalerType.Function
)
{
throw new ArgumentException("Bad task result type");
throw new ArgumentException(SR.Format(SR.UnsupportedTaskResultType, underlying), nameof(underlyingType));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static MarshalType GetMarshalTypeFromType(Type type)
case TypeCode.UInt64:
return MarshalType.ENUM64;
default:
throw new JSException($"Unsupported enum underlying type {typeCode}");
throw new ArgumentException(SR.Format(SR.UnsupportedEnumType, type.FullName), nameof(type));
}
}

Expand Down Expand Up @@ -69,7 +69,7 @@ public static MarshalType GetMarshalTypeFromType(Type type)
if (type.IsArray)
{
if (!type.IsSZArray)
throw new JSException("Only single-dimensional arrays with a zero lower bound can be marshaled to JS");
throw new ArgumentException(SR.Format(SR.UnsupportedArrayType, type.FullName), nameof(type));

var elementType = type.GetElementType();
switch (Type.GetTypeCode(elementType))
Expand All @@ -91,7 +91,7 @@ public static MarshalType GetMarshalTypeFromType(Type type)
case TypeCode.Double:
return MarshalType.ARRAY_DOUBLE;
default:
throw new JSException($"Unsupported array element type {elementType}");
throw new ArgumentException(SR.Format(SR.UnsupportedElementType, elementType), nameof(type));
}
}
else if (type == typeof(IntPtr))
Expand All @@ -115,9 +115,9 @@ public static MarshalType GetMarshalTypeFromType(Type type)
return MarshalType.OBJECT;
}

public static char GetCallSignatureCharacterForMarshalType(MarshalType t, char? defaultValue)
public static char GetCallSignatureCharacterForMarshalType(MarshalType type, char? defaultValue)
{
switch (t)
switch (type)
{
case MarshalType.BOOL:
return 'b';
Expand Down Expand Up @@ -154,7 +154,7 @@ public static char GetCallSignatureCharacterForMarshalType(MarshalType t, char?
if (defaultValue.HasValue)
return defaultValue.Value;
else
throw new JSException($"Unsupported marshal type {t}");
throw new ArgumentException(SR.Format(SR.UnsupportedLegacyMarshlerType, type), nameof(type));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static void SetObjectProperty(this JSObject self, string name, object? va

Interop.Runtime.SetObjectPropertyRef(self.JSHandle, name, in value, createIfNotExists, hasOwnProperty, out int exception, out object res);
if (exception != 0)
throw new JSException($"Error setting {name} on (js-obj js '{self.JSHandle}'): {res}");
throw new JSException(SR.Format(SR.ErrorLegacySettingProperty, name, self.JSHandle, res));
}

public static void AssertNotDisposed(this JSObject self)
Expand All @@ -107,7 +107,7 @@ public static void AssertNotDisposed(this JSObject self)

public static void AssertInFlight(this JSObject self, int expectedInFlightCount)
{
if (self.InFlightCounter != expectedInFlightCount) throw new InvalidProgramException($"Invalid InFlightCounter for JSObject {self.JSHandle}, expected: {expectedInFlightCount}, actual: {self.InFlightCounter}");
if (self.InFlightCounter != expectedInFlightCount) throw new InvalidOperationException(SR.Format(SR.UnsupportedLegacyMarshlerType, self.JSHandle, expectedInFlightCount, self.InFlightCounter));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static unsafe Uint8Array From(ReadOnlySpan<byte> span)
// source has to be instantiated.
if (span == null)
{
throw new System.ArgumentException(SR.Format(SR.ArgumentCannotBeNull, nameof(span)));
throw new System.ArgumentException(SR.Format(SR.ArgumentCannotBeNull, nameof(span)), nameof(span));
}

ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void ToJS(long value)
{
if (value < I52_MIN_VALUE || value > I52_MAX_VALUE)
{
throw new OverflowException($"Overflow: value ${value} is out of ${I52_MIN_VALUE} ${I52_MAX_VALUE} range");
throw new OverflowException(SR.Format(SR.ValueOutOf52BitRange, value, I52_MIN_VALUE, I52_MAX_VALUE));
}

slot.Type = MarshalerType.Int52;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void ToJS(long? value)
{
if (value.Value < I52_MIN_VALUE || value.Value > I52_MAX_VALUE)
{
throw new OverflowException($"Overflow: value ${value} is out of ${I52_MIN_VALUE} ${I52_MAX_VALUE} range");
throw new OverflowException(SR.Format(SR.ValueOutOf52BitRange, value, I52_MIN_VALUE, I52_MAX_VALUE));
}
slot.Type = MarshalerType.Int52;
slot.DoubleValue = value.Value;
Expand Down
Loading