Skip to content

Commit bda61b9

Browse files
authored
[browser] es6 test main (#85542)
1 parent 6a5a704 commit bda61b9

File tree

19 files changed

+301
-226
lines changed

19 files changed

+301
-226
lines changed

eng/testing/WasmRunnerAOTTemplate.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ if [[ -z "$XHARNESS_COMMAND" ]]; then
3434
fi
3535

3636
if [[ "$XHARNESS_COMMAND" == "test" ]]; then
37-
if [[ -z "$JS_ENGINE_ARGS" ]]; then
38-
JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000 --engine-arg=--experimental-wasm-eh"
39-
fi
40-
4137
if [[ -z "$JS_ENGINE" ]]; then
4238
if [[ "$SCENARIO" == "WasmTestOnNodeJS" || "$SCENARIO" == "wasmtestonnodejs" ]]; then
4339
JS_ENGINE="--engine=NodeJS"
@@ -46,6 +42,16 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then
4642
fi
4743
fi
4844

45+
if [[ -z "$JS_ENGINE_ARGS" ]]; then
46+
JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000"
47+
if [[ "$SCENARIO" != "WasmTestOnNodeJS" && "$SCENARIO" != "wasmtestonnodejs" ]]; then
48+
JS_ENGINE_ARGS="$JS_ENGINE_ARGS --engine-arg=--module"
49+
fi
50+
if [[ "$SCENARIO" == "WasmTestOnNodeJS" || "$SCENARIO" == "wasmtestonnodejs" ]]; then
51+
JS_ENGINE_ARGS="$JS_ENGINE_ARGS --engine-arg=--experimental-wasm-eh"
52+
fi
53+
fi
54+
4955
if [[ -z "$MAIN_JS" ]]; then
5056
MAIN_JS="--js-file=test-main.js"
5157
fi

eng/testing/WasmRunnerTemplate.cmd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ if /I [%XHARNESS_COMMAND%] == [test] (
4545
)
4646

4747
if [%JS_ENGINE_ARGS%] == [] (
48-
set "JS_ENGINE_ARGS=--engine-arg^=--stack-trace-limit^=1000 --engine-arg^=--experimental-wasm-eh"
48+
set "JS_ENGINE_ARGS=--engine-arg^=--stack-trace-limit^=1000"
49+
if /I NOT [%SCENARIO%] == [WasmTestOnNodeJS] (
50+
set "JS_ENGINE_ARGS=%JS_ENGINE_ARGS% --engine-arg^=--module"
51+
)
52+
if /I [%SCENARIO%] == [WasmTestOnNodeJS] (
53+
set "JS_ENGINE_ARGS=%JS_ENGINE_ARGS% --engine-arg^=--experimental-wasm-eh"
54+
)
4955
)
5056
) else (
5157
if [%BROWSER_PATH%] == [] if not [%HELIX_CORRELATION_PAYLOAD%] == [] (

eng/testing/WasmRunnerTemplate.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then
4747
fi
4848

4949
if [[ -z "$JS_ENGINE_ARGS" ]]; then
50-
JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000 --engine-arg=--experimental-wasm-eh"
50+
JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000"
51+
if [[ "$SCENARIO" != "WasmTestOnNodeJS" && "$SCENARIO" != "wasmtestonnodejs" ]]; then
52+
JS_ENGINE_ARGS="$JS_ENGINE_ARGS --engine-arg=--module"
53+
fi
54+
if [[ "$SCENARIO" == "WasmTestOnNodeJS" || "$SCENARIO" == "wasmtestonnodejs" ]]; then
55+
JS_ENGINE_ARGS="$JS_ENGINE_ARGS --engine-arg=--experimental-wasm-eh"
56+
fi
5157
fi
5258
fi
5359

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,10 @@ public void JsExportCatchStack()
14281428
{
14291429
var stack = JavaScriptTestHelper.catch1stack("-t-e-s-t-", nameof(JavaScriptTestHelper.ThrowFromJSExport));
14301430
Assert.Contains(nameof(JavaScriptTestHelper.ThrowFromJSExport), stack);
1431-
Assert.Contains("catch1stack", stack);
1431+
if (PlatformDetection.IsBrowserDomSupportedOrNodeJS)
1432+
{
1433+
Assert.Contains("catch1stack", stack);
1434+
}
14321435
}
14331436

14341437
#endregion Exception

src/mono/sample/wasm/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</PropertyGroup>
5454
</Target>
5555
<Target Name="RunSampleWithV8" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
56-
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="v8 --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
56+
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="v8 --expose_wasm --module $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
5757
</Target>
5858
<Target Name="RunSampleWithNode" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
5959
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />

src/mono/sample/wasm/console-node/main.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { dotnet } from './dotnet.js'
55

6-
dotnet
6+
await dotnet
77
.withDiagnosticTracing(false)
88
.withApplicationArguments("dotnet", "is", "great!")
99
.run()

src/mono/sample/wasm/console-v8/main.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { dotnet } from './dotnet.js'
55

6-
dotnet
6+
await dotnet
77
.withDiagnosticTracing(false)
88
.withApplicationArguments(...arguments)
99
.run()

src/mono/sample/wasm/wasm.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ run-browser:
4242
fi
4343

4444
run-console:
45-
cd bin/$(CONFIG)/AppBundle && $(V8_PATH) --stack-trace-limit=1000 --single-threaded --expose_wasm $(MAIN_JS) -- $(ARGS)
45+
cd bin/$(CONFIG)/AppBundle && $(V8_PATH) --stack-trace-limit=1000 --single-threaded --expose_wasm --module $(MAIN_JS) -- $(ARGS)
4646

4747
run-console-node:
4848
cd bin/$(CONFIG)/AppBundle && node --stack-trace-limit=1000 --single-threaded --expose_wasm $(MAIN_JS) $(ARGS)

src/mono/wasm/build/WasmApp.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424
<Error Condition="'$(WasmMainAssemblyFileName)' == ''" Text="%24(WasmMainAssemblyFileName) property needs to be set for generating $(WasmRunV8ScriptPath)." />
425425
<WriteLinesToFile
426426
File="$(WasmRunV8ScriptPath)"
427-
Lines="v8 --expose_wasm $(_WasmMainJSFileName) -- ${RUNTIME_ARGS} --run $(WasmMainAssemblyFileName) $*"
427+
Lines="v8 --expose_wasm --module $(_WasmMainJSFileName) -- ${RUNTIME_ARGS} --run $(WasmMainAssemblyFileName) $*"
428428
Overwrite="true">
429429
</WriteLinesToFile>
430430

src/mono/wasm/runtime/assets.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,15 @@ export async function instantiate_wasm_asset(
514514
}
515515
const arrayBuffer = await response.arrayBuffer();
516516
if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: instantiate_wasm_module buffered");
517-
const arrayBufferResult = await WebAssembly.instantiate(arrayBuffer, wasmModuleImports!);
518-
compiledInstance = arrayBufferResult.instance;
519-
compiledModule = arrayBufferResult.module;
517+
if (ENVIRONMENT_IS_SHELL) {
518+
// workaround for old versions of V8 with https://bugs.chromium.org/p/v8/issues/detail?id=13823
519+
compiledModule = new WebAssembly.Module(arrayBuffer);
520+
compiledInstance = new WebAssembly.Instance(compiledModule, wasmModuleImports);
521+
} else {
522+
const arrayBufferResult = await WebAssembly.instantiate(arrayBuffer, wasmModuleImports!);
523+
compiledInstance = arrayBufferResult.instance;
524+
compiledModule = arrayBufferResult.module;
525+
}
520526
}
521527
successCallback(compiledInstance, compiledModule);
522528
}

0 commit comments

Comments
 (0)