Skip to content

Commit

Permalink
[dart2wasm] Migrate our embedders to new mjs API
Browse files Browse the repository at this point in the history
To test that the deprecated mjs API functions still work we landed the
new mjs API in [0] seperately.

This CL then migrates our 2 different users of the mjs api
in the Dart SDK (for testing and benchmarking) to the new API.

[0] https://dart-review.googlesource.com/c/sdk/+/383242

Change-Id: Ibbe58c9a977326a8fbff780d328d7f54784bd323
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382888
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
  • Loading branch information
mkustermann authored and Commit Queue committed Sep 3, 2024
1 parent 56178c2 commit 3deaa76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
8 changes: 3 additions & 5 deletions pkg/dart2wasm/bin/run_wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,13 @@ const main = async () => {
}

// Instantiate the Dart module, importing from the global scope.
const dartInstance = await dart2wasm.instantiate(
dart2wasm.compile(readBytes(args[wasmArg])),
Promise.resolve(importObject),
);
const compiledApp = await dart2wasm.compile(readBytes(args[wasmArg]));
const appInstance = await compiledApp.instantiate(importObject);

// Call `main`. If tasks are placed into the event loop (by scheduling tasks
// explicitly or awaiting Futures), these will automatically keep the script
// alive even after `main` returns.
await dart2wasm.invoke(dartInstance, ...dartArgs);
await appInstance.invokeMain(...dartArgs);
};

dartMainRunner(main, []);
17 changes: 9 additions & 8 deletions pkg/test_runner/lib/src/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,16 @@ String dart2wasmHtml(String title, String wasmPath, String mjsPath) {
src="/root_dart/pkg/test_runner/lib/src/test_controller.js">
</script>
<script type="module">
let dart2wasm_runtime = await import('$mjsPath');
const dartModulePromise =
dart2wasm_runtime.compileStreaming(fetch('$wasmPath'));
let moduleInstance =
await dart2wasm_runtime.instantiate(dartModulePromise, {});
async function loadAndRun(mjsPath, wasmPath) {
const mjs = await import(mjsPath);
const compiledApp = await mjs.compileStreaming(fetch(wasmPath));
const appInstance = await compiledApp.instantiate({});
dartMainRunner(() => {
appInstance.invokeMain();
});
}
dartMainRunner(() => {
dart2wasm_runtime.invoke(moduleInstance);
});
loadAndRun('$mjsPath', '$wasmPath');
</script>
</body>
</html>""";
Expand Down

0 comments on commit 3deaa76

Please sign in to comment.