Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.Format(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 InvalidProgramException(SR.Format(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 InvalidProgramException(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.Format(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.Format(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.Format(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.Format(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 InvalidProgramException(SR.Format(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.Format(SR.UriConstructorMissing), ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ 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));
}

internal static void CheckArray(JSMarshalerType underlyingSig)
Expand All @@ -457,7 +457,7 @@ internal static void CheckArray(JSMarshalerType underlyingSig)
|| underlying == MarshalerType.Object
|| underlying == MarshalerType.JSObject
) return;
throw new ArgumentException("Bad array element type");
throw new ArgumentException(SR.Format(SR.UnsupportedElementType, underlying));
}

internal static void CheckArraySegment(JSMarshalerType underlyingSig)
Expand All @@ -467,7 +467,7 @@ internal static void CheckArraySegment(JSMarshalerType underlyingSig)
|| underlying == MarshalerType.Int32
|| underlying == MarshalerType.Double
) return;
throw new ArgumentException("Bad array element type");
throw new ArgumentException(SR.Format(SR.UnsupportedElementType, underlying));
}

internal static void CheckTask(JSMarshalerType underlyingSig)
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));
}
}
}
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));
}
}

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));

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));
}
}
else if (type == typeof(IntPtr))
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 InvalidProgramException(SR.Format(SR.UnsupportedLegacyMarshlerType, t));
}
}

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 InvalidProgramException(SR.Format(SR.UnsupportedLegacyMarshlerType, self.JSHandle, expectedInFlightCount, self.InFlightCounter));
}
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public unsafe void ToManaged(out object? value)
}
else
{
throw new NotImplementedException("ToManaged: " + slot.ElementType+ "[]");
throw new NotImplementedException(SR.Format(SR.ToManagedNotImplemented, slot.ElementType+ "[]"));
}
}
else if (slot.Type == MarshalerType.Task)
Expand All @@ -101,7 +101,7 @@ public unsafe void ToManaged(out object? value)
}
else
{
throw new NotImplementedException("ToManaged: " + slot.Type);
throw new NotImplementedException(SR.Format(SR.ToManagedNotImplemented, slot.Type));
}
}

Expand All @@ -125,7 +125,7 @@ public void ToJS(object? value)
if (typeof(long) == type)
{
// we do it because not all Int64 could fit into Int52 of the JS Number
throw new NotImplementedException("ToJS: " + type.FullName);
throw new NotImplementedException(SR.Format(SR.ToJSNotImplemented, type.FullName));
}
else if (typeof(int) == type)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ public void ToJS(object? value)
}
else
{
throw new NotImplementedException("ToJS: " + type.FullName);
throw new NotImplementedException(SR.Format(SR.ToJSNotImplemented, type.FullName));
}
}
else if (typeof(string) == type)
Expand All @@ -192,7 +192,7 @@ public void ToJS(object? value)
if (typeof(long) == ut)
{
// we do it because not all Int64 could fit into Int52 of the JS Number
throw new NotImplementedException("ToJS: " + type.FullName);
throw new NotImplementedException(SR.Format(SR.ToJSNotImplemented, type.FullName));
}
else if (typeof(int) == ut)
{
Expand Down Expand Up @@ -246,7 +246,7 @@ public void ToJS(object? value)
}
else
{
throw new NotImplementedException("ToJS: " + type.FullName);
throw new NotImplementedException(SR.Format(SR.ToJSNotImplemented, type.FullName));
}
}
else if (typeof(JSObject).IsAssignableFrom(type))
Expand Down Expand Up @@ -301,19 +301,19 @@ public void ToJS(object? value)
}
else if (type.IsArray)
{
throw new NotImplementedException("ToJS: " + type.FullName);
throw new NotImplementedException(SR.Format(SR.ToJSNotImplemented, type.FullName));
}
else if (typeof(MulticastDelegate).IsAssignableFrom(type.BaseType))
{
throw new NotImplementedException("ToJS: " + type.FullName);
throw new NotImplementedException(SR.Format(SR.ToJSNotImplemented, type.FullName));
}
else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ArraySegment<>))
{
throw new NotImplementedException("ToJS: " + type.FullName);
throw new NotImplementedException(SR.Format(SR.ToJSNotImplemented, type.FullName));
}
else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Span<>))
{
throw new NotImplementedException("ToJS: " + type.FullName);
throw new NotImplementedException(SR.Format(SR.ToJSNotImplemented, type.FullName));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public unsafe void ToManaged(out Task? value)

GCHandle gcHandle = (GCHandle)slot.GCHandle;
JSHostImplementation.TaskCallback? holder = (JSHostImplementation.TaskCallback?)gcHandle.Target;
if (holder == null) throw new NullReferenceException("JSHostImplementation.TaskCallback");
if (holder == null) throw new InvalidProgramException(SR.Format(SR.FailedToMarshalTaskCallback));

TaskCompletionSource tcs = new TaskCompletionSource(gcHandle);
JSHostImplementation.ToManagedCallback callback = (JSMarshalerArgument* arguments_buffer) =>
Expand Down Expand Up @@ -83,7 +83,7 @@ public unsafe void ToManaged<T>(out Task<T>? value, ArgumentToManagedCallback<T>

GCHandle gcHandle = (GCHandle)slot.GCHandle;
JSHostImplementation.TaskCallback? holder = (JSHostImplementation.TaskCallback?)gcHandle.Target;
if (holder == null) throw new NullReferenceException("JSHostImplementation.TaskCallback");
if (holder == null) throw new InvalidProgramException(SR.Format(SR.FailedToMarshalTaskCallback));

TaskCompletionSource<T> tcs = new TaskCompletionSource<T>(gcHandle);
JSHostImplementation.ToManagedCallback callback = (JSMarshalerArgument* arguments_buffer) =>
Expand All @@ -93,7 +93,7 @@ public unsafe void ToManaged<T>(out Task<T>? value, ArgumentToManagedCallback<T>
if (arg_2.slot.Type != MarshalerType.None)
{
arg_2.ToManaged(out Exception? fail);
if (fail == null) throw new NullReferenceException("Exception");
if (fail == null) throw new InvalidProgramException(SR.Format(SR.FailedToMarshalException));
tcs.SetException(fail);
}
else
Expand Down