Skip to content

Commit

Permalink
Version 3.6.0-167.0.dev
Browse files Browse the repository at this point in the history
Merge 4cd6096 into dev
  • Loading branch information
Dart CI committed Aug 21, 2024
2 parents 060e409 + 4cd6096 commit 025bf8d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
20 changes: 3 additions & 17 deletions pkg/dart2wasm/bin/run_wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,7 @@ if (argsSplit != -1) {
const main = async () => {
const dart2wasm = await import(args[jsRuntimeArg]);

/// Returns whether the `js-string` built-in is supported.
function detectImportedStrings() {
let bytes = [
0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0,
0, 2, 23, 1, 14, 119, 97, 115, 109, 58, 106, 115, 45,
115, 116, 114, 105, 110, 103, 4, 99, 97, 115, 116, 0, 0
];
return !WebAssembly.validate(
new Uint8Array(bytes), {builtins: ['js-string']});
}

function compile(filename, withJsStringBuiltins) {
function compile(filename) {
// Create a Wasm module from the binary Wasm file.
var bytes;
if (isJSC) {
Expand All @@ -391,10 +380,7 @@ const main = async () => {
} else {
bytes = readRelativeToScript(filename, "binary");
}
return WebAssembly.compile(
bytes,
withJsStringBuiltins ? {builtins: ['js-string']} : {}
);
return dart2wasm.compile(bytes);
}

globalThis.window ??= globalThis;
Expand All @@ -411,7 +397,7 @@ const main = async () => {

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

Expand Down
36 changes: 36 additions & 0 deletions pkg/dart2wasm/lib/js/runtime_blob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,42 @@
// BSD-style license that can be found in the LICENSE file.

const jsRuntimeBlobPart1 = r'''
// Returns whether the `js-string` built-in is supported.
function detectJsStringBuiltins() {
let bytes = [
0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0,
0, 2, 23, 1, 14, 119, 97, 115, 109, 58, 106, 115, 45,
115, 116, 114, 105, 110, 103, 4, 99, 97, 115, 116, 0, 0
];
return WebAssembly.validate(
new Uint8Array(bytes), {builtins: ['js-string']});
}
// Compile a dart2wasm-generated Wasm module using
// `WebAssembly.compileStreaming`, with the flags needed by dart2wasm. `source`
// needs to have a type expected by `WebAssembly.compileStreaming`.
//
// Pass the output of this to `instantiate` below to instantiate the compiled
// module.
export const compileStreaming = (source) => {
return WebAssembly.compileStreaming(
source,
detectJsStringBuiltins() ? {builtins: ['js-string']} : {}
);
}
// Compile a dart2wasm-generated Wasm module using `WebAssembly.compile`, with
// the flags needed by dart2wasm. `source` needs to have a type expected by
// `WebAssembly.compileStreaming`.
//
// Pass the output of this to `instantiate` below to instantiate the compiled
// module.
export const compile = (bytes) => {
return WebAssembly.compile(
bytes,
detectJsStringBuiltins() ? {builtins: ['js-string']} : {}
);
}
// `modulePromise` is a promise to the `WebAssembly.module` object to be
// instantiated.
Expand Down
6 changes: 3 additions & 3 deletions pkg/test_runner/lib/src/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ String dart2wasmHtml(String title, String wasmPath, String mjsPath) {
src="/root_dart/pkg/test_runner/lib/src/test_controller.js">
</script>
<script type="module">
const dartModulePromise = WebAssembly.compileStreaming(fetch('$wasmPath'));
const imports = {};
let dart2wasm_runtime = await import('$mjsPath');
const dartModulePromise =
dart2wasm_runtime.compileStreaming(fetch('$wasmPath'));
let moduleInstance =
await dart2wasm_runtime.instantiate(dartModulePromise, imports);
await dart2wasm_runtime.instantiate(dartModulePromise, {});
dartMainRunner(() => {
dart2wasm_runtime.invoke(moduleInstance);
Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 6
PATCH 0
PRERELEASE 166
PRERELEASE 167
PRERELEASE_PATCH 0

0 comments on commit 025bf8d

Please sign in to comment.