Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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 @@ -403,6 +403,24 @@ public async Task JsExportTaskOfLong(long value)
Assert.Equal(value, rr);
}

[Fact]
public async Task JsExportTaskOfShortOutOfRange_ThrowsAssertionInTaskContinuation()
{
// 1<<16 is out of range, passed to js and back, marshalling ts code asserts out of range and throws
Task<short> res = JavaScriptTestHelper.invoke1_TaskOfOutOfRangeShort(Task.FromResult(1 << 16), nameof(JavaScriptTestHelper.AwaitTaskOfShort));
JSException ex = await Assert.ThrowsAsync<JSException>(() => res);
Assert.Equal("Error: Assert failed: Overflow: value 65536 is out of -32768 32767 range", ex.Message);
}

[Fact]
public async Task JsExportTaskOfStringTypeAssertion_ThrowsAssertionInTaskContinuation()
{
// long value cannot be converted to string, error thrown through continuation in CS
Task<string> res = JavaScriptTestHelper.invoke1_TaskOfLong_ExceptionReturnTypeAssert(Task.FromResult(1L << 32), nameof(JavaScriptTestHelper.AwaitTaskOfString));
JSException ex = await Assert.ThrowsAsync<JSException>(() => res);
Assert.Equal("Error: Assert failed: Value is not a String", ex.Message);
}

[Theory]
[MemberData(nameof(MarshalBigInt64Cases))]
public async Task JsExportCompletedTaskOfLong(long value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ public unsafe void OptimizedPaths()
Assert.Equal(43 + 123 + 31, JavaScriptTestHelper.optimizedReached);
}

[Fact]
public async Task TaskOfShortOutOfRange_ThrowsAssertionInTaskContinuation()
{
Task<short> res = JavaScriptTestHelper.ReturnResolvedPromiseWithIntMaxValue_AsShortToBeOutOfRange();
JSException ex = await Assert.ThrowsAsync<JSException>(() => res);
Console.WriteLine(ex.Message);
Assert.Equal("Error: Assert failed: Overflow: value 2147483647 is out of -32768 32767 range", ex.Message);
}

[Fact]
public async Task TaskOfByteOutOfRange_ThrowsAssertionInTaskContinuation()
{
Task<byte> res = JavaScriptTestHelper.ReturnResolvedPromiseWithIntMaxValue_AsByteToBeOutOfRange();
JSException ex = await Assert.ThrowsAsync<JSException>(() => res);
Console.WriteLine(ex.Message);
Assert.Equal("Error: Assert failed: Overflow: value 2147483647 is out of 0 255 range", ex.Message);
}

#region Get/Set Property

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ public static Exception EchoException([JSMarshalAs<JSType.Error>] Exception arg1
[JSImport("invoke1", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.BigInt>>]
internal static partial Task<long> invoke1_TaskOfLong([JSMarshalAs<JSType.Promise<JSType.BigInt>>] Task<long> value, [JSMarshalAs<JSType.String>] string name);
[JSImport("invoke1", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.String>>]
internal static partial Task<string> invoke1_TaskOfLong_ExceptionReturnTypeAssert([JSMarshalAs<JSType.Promise<JSType.BigInt>>] Task<long> value, [JSMarshalAs<JSType.String>] string name);
[JSImport("invoke1", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.Number>>]
internal static partial Task<short> invoke1_TaskOfOutOfRangeShort([JSMarshalAs<JSType.Promise<JSType.Number>>] Task<int> value, [JSMarshalAs<JSType.String>] string name);
[JSImport("returnResolvedPromiseWithIntMaxValue", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.Number>>]
internal static partial Task<short> ReturnResolvedPromiseWithIntMaxValue_AsShortToBeOutOfRange();
[JSImport("returnResolvedPromiseWithIntMaxValue", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.Number>>]
internal static partial Task<byte> ReturnResolvedPromiseWithIntMaxValue_AsByteToBeOutOfRange();
[JSImport("returnResolvedPromise", "JavaScriptTestHelper")]
internal static partial Task ReturnResolvedPromise();

Expand Down Expand Up @@ -472,6 +484,22 @@ public static async Task<long> AwaitTaskOfInt64([JSMarshalAs<JSType.Promise<JSTy
return res;
}

[JSExport]
[return: JSMarshalAs<JSType.Promise<JSType.Number>>]
public static async Task<short> AwaitTaskOfShort([JSMarshalAs<JSType.Promise<JSType.Number>>] Task<short> arg1)
{
var res = await arg1;
return res;
}

[JSExport]
[return: JSMarshalAs<JSType.Promise<JSType.String>>]
public static async Task<string> AwaitTaskOfString([JSMarshalAs<JSType.Promise<JSType.String>>] Task<string> arg1)
{
var res = await arg1;
return res;
}

#endregion

#region Action + Func
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ export function returnResolvedPromise() {
return Promise.resolve();
}

export function returnResolvedPromiseWithIntMaxValue() {
return Promise.resolve(2147483647);
}

export async function invokeReturnCompletedTask() {
await dllExports.System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper.ReturnCompletedTask();
return "resolved";
Expand Down Expand Up @@ -490,4 +494,4 @@ export function isSetTimeoutHit() {

export function isPromiseThenHit() {
return promiseThenHit;
}
}
13 changes: 9 additions & 4 deletions src/mono/browser/runtime/managed-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,18 @@ export function complete_task (holder_gc_handle: GCHandle, error?: any, data?: a
set_arg_type(arg1, MarshalerType.Object);
set_gc_handle(arg1, holder_gc_handle);
const arg2 = get_arg(args, 3);
if (error) {
marshal_exception_to_cs(arg2, error);
} else {
if (!error) {
set_arg_type(arg2, MarshalerType.None);
const arg3 = get_arg(args, 4);
mono_assert(res_converter, "res_converter missing");
res_converter(arg3, data);
try {
res_converter(arg3, data);
} catch (ex) {
error = ex;
}
}
if (error) {
marshal_exception_to_cs(arg2, error);
}
invoke_async_jsexport(runtimeHelpers.ioThreadTID, managedExports.CompleteTask, args, size);
} finally {
Expand Down
Loading