Skip to content

Commit

Permalink
[dart2wasm] Fix js-string builtin detection
Browse files Browse the repository at this point in the history
The `detectJsStringBuiltins` should've negated the validation (i.e.
validation will fail if `js-string` builtins is enabled as enabling the
builtins causes stricter validation of imports)

Closes #59697

Change-Id: I5bcfdcf34e9fad89a84090c5f20284a7aae9e209
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400280
Reviewed-by: Slava Egorov <[email protected]>
Commit-Queue: Martin Kustermann <[email protected]>
  • Loading branch information
mkustermann authored and Commit Queue committed Dec 12, 2024
1 parent 1d684cd commit 684018e
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions pkg/dart2wasm/lib/js/runtime_blob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,22 @@
// 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']});
}
// Compiles a dart2wasm-generated main module from `source` which can then
// instantiatable via the `instantiate` method.
//
// `source` needs to be a `Response` object (or promise thereof) e.g. created
// via the `fetch()` JS API.
export async function compileStreaming(source) {
const builtins = detectJsStringBuiltins()
? {builtins: ['js-string']} : {};
const builtins = {builtins: ['js-string']};
return new CompiledApp(
await WebAssembly.compileStreaming(source, builtins), builtins);
}
// Compiles a dart2wasm-generated wasm modules from `bytes` which is then
// instantiatable via the `instantiate` method.
export async function compile(bytes) {
const builtins = detectJsStringBuiltins()
? {builtins: ['js-string']} : {};
const builtins = {builtins: ['js-string']};
return new CompiledApp(await WebAssembly.compile(bytes, builtins), builtins);
}
Expand Down

0 comments on commit 684018e

Please sign in to comment.