Skip to content

detectJsStringBuiltins() returns incorrect resultΒ #59697

@jakobkummerow

Description

@jakobkummerow

The function detectJsStringBuiltins in

function detectJsStringBuiltins() {
is missing a boolean inversion of its result: those module bytes will fail to validate when the Wasm engine implements support for String Builtins (because the opt-in causes type checks to be applied to imports that in classic Wasm would be allowed to have any type they want), so the function should return !WebAssembly.validate(...) (note the !).

To verify, you can copy-paste that function into the DevTools console of any recent-ish Chrome build: it should return true. E.g.:

> 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
  ];
< undefined
> WebAssembly.validate(new Uint8Array(bytes))
< true
> WebAssembly.validate(new Uint8Array(bytes), {builtins: ["js-string"]})
< false

Looking at how the result of that feature detection is used in compileStreaming and compile a couple of lines further down in the same file, detectJsStringBuiltins() could also be dropped entirely: it never hurts to request {builtins: ['js-string']} in compile/compileStreaming, if the feature isn't present then that parameter will just silently be ignored.

(I noticed this when looking at https://github.com/mkustermann/wasm_gc_benchmarks/blob/main/micro-benchmarks-out/non_devirtualized_typed_data_access.dart2wasm.mjs.)

Metadata

Metadata

Assignees

Labels

area-dart2wasmIssues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions