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 @@ -16,4 +16,7 @@
<NativeFileReference Include="fibonacci.c" />
<TrimmerRootDescriptor Include="$(MSBuildThisFileDirectory)ILLink.Descriptors.xml" />
</ItemGroup>

<Target Name="RunSample" DependsOnTargets="RunSampleWithBrowserAndSimpleServer" />

</Project>
18 changes: 18 additions & 0 deletions src/mono/sample/wasm/browser-advanced/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ function add(a, b) {
return a + b;
}

let testAbort = true;
let testError = true;

try {
const { runtimeBuildInfo, setModuleImports, getAssemblyExports, runMain, getConfig, Module } = await dotnet
.withElementOnExit()
Expand All @@ -22,6 +25,21 @@ try {
config.environmentVariables["MONO_LOG_LEVEL"] = "debug";
config.browserProfilerOptions = {};
},
imports: {
fetch: (url, fetchArgs) => {
console.log("fetching " + url);
// we are testing that we can retry loading of the assembly
if (testAbort && url.indexOf('System.Private.Uri.dll') != -1) {
testAbort = false;
return fetch(url + "?testAbort=true", fetchArgs);
}
if (testError && url.indexOf('System.Console.dll') != -1) {
testError = false;
return fetch(url + "?testError=true", fetchArgs);
}
return fetch(url, fetchArgs);
}
},
preInit: () => { console.log('user code Module.preInit'); },
preRun: () => { console.log('user code Module.preRun'); },
onRuntimeInitialized: () => {
Expand Down
28 changes: 26 additions & 2 deletions src/mono/sample/wasm/simple-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,43 @@ private async void ServeAsync(HttpListenerContext context)
string? contentType = null;
if (path.EndsWith(".wasm"))
contentType = "application/wasm";
if (path.EndsWith(".webcil"))
if (path.EndsWith(".webcil") || path.EndsWith(".dll") || path.EndsWith(".pdb"))
contentType = "application/octet-stream";
if (path.EndsWith(".json"))
contentType = "application/json";
if (path.EndsWith(".js") || path.EndsWith(".mjs") || path.EndsWith(".cjs"))
contentType = "text/javascript";

var stream = context.Response.OutputStream;

// test download re-try
if (url.Query.Contains("testError"))
{
Console.WriteLine("Faking 500 " + url);
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
await stream.WriteAsync(buffer, 0, 0).ConfigureAwait(false);
await stream.FlushAsync();
context.Response.Close();
return;
}

if (contentType != null)
context.Response.ContentType = contentType;

context.Response.ContentLength64 = buffer.Length;
context.Response.AppendHeader("cache-control", "public, max-age=31536000");
var stream = context.Response.OutputStream;

// test download re-try
if (url.Query.Contains("testAbort"))
{
Console.WriteLine("Faking abort " + url);
await stream.WriteAsync(buffer, 0, 10).ConfigureAwait(false);
await stream.FlushAsync();
await Task.Delay(100);
context.Response.Abort();
return;
}

try
{
await stream.WriteAsync(buffer).ConfigureAwait(false);
Expand Down