Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b40abf8
add test demonstrating runtime exit on failing to marshal task result…
ArcadeMode Jan 23, 2026
c5358b7
fix by marshalling error to dotnet task
ArcadeMode Jan 23, 2026
5004c25
add jsimport test
ArcadeMode Jan 23, 2026
ab6efdd
test another range limited type
ArcadeMode Jan 23, 2026
c2bfc28
demonstrate with a different assertion
ArcadeMode Jan 23, 2026
5aed026
remove leftover console writes
ArcadeMode Jan 23, 2026
d049f55
colocate tests, add datetime overflow im+export tests that crash runtime
ArcadeMode Jan 23, 2026
bc4ff51
add range assert for date unitTime that .net accepts
ArcadeMode Jan 23, 2026
3e42d91
move range check to marshal.ts
ArcadeMode Jan 24, 2026
51cb10a
line up error message with mono impl
ArcadeMode Jan 24, 2026
4534795
marshal exception if task result conversion fails in native interop impl
ArcadeMode Jan 25, 2026
baf1281
assert supported date range in mono and native
ArcadeMode Jan 25, 2026
593e417
update tests to reflect friendly messages
ArcadeMode Jan 25, 2026
9c7afea
test correctness of date boundary value marshalling
ArcadeMode Jan 25, 2026
253aa3c
min/max boundary tests
ArcadeMode Jan 25, 2026
e341358
add test for date precision loss
ArcadeMode Jan 25, 2026
b6ce6bc
add datetime and delegate datetime/long overflow tests
ArcadeMode Jan 25, 2026
0c15303
naming convention
ArcadeMode Jan 25, 2026
ffa1535
Merge branch 'main' into wasm-runtime-exit-outofrange-task-value
pavelsavara Jan 26, 2026
3078e9d
mono check instead of assert
ArcadeMode Jan 28, 2026
78ba06c
demonstrate array elements value overflow for int32
ArcadeMode Jan 28, 2026
bb43231
test name
ArcadeMode Jan 28, 2026
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