Bug 308136
| Summary: | WebAssembly.compileStreaming + instantiate does not work with JS string builtins. | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | konsoletyper |
| Component: | WebAssembly | Assignee: | Vassili Bykov <v_bykov> |
| Status: | REOPENED | ||
| Severity: | Normal | CC: | commit-queue, keith_miller, syg, webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 26 | ||
| Hardware: | Unspecified | ||
| OS: | macOS 15 | ||
| Bug Depends on: | 308698 | ||
| Bug Blocks: | |||
konsoletyper
## Steps to reproduce
1. Open a web page with following content:
```
<html>
<body>
<script>
async function testStrings2() {
let bytes = new Int8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 1, 127, 1, 100, 111, 2, 31, 1, 14, 119, 97,
115, 109, 58, 106, 115, 45, 115, 116, 114, 105, 110, 103, 12, 102, 114, 111, 109, 67, 104, 97, 114, 67, 111,
100, 101, 0, 0, 3, 1, 0, 5, 4, 1, 1, 0, 0, 7, 10, 1, 6, 109, 101, 109, 111, 114, 121, 2, 0, 10,
-127, -128, -128, 0, 0]);
let supported = true;
try {
let response = new Response(bytes, {
headers: {
"Content-Type": "application/wasm"
}
});
let module = await WebAssembly.compileStreaming(response, { builtins: ["js-string"] });
await WebAssembly.instantiate(module, {}, { builtins: ["js-string"] });
} catch (e) {
supported = false;
}
if (supported) {
console.log("String builtins are *supported* in your browser (new check 2)");
} else {
console.log("String builtins are *not* supported in your browser (new check 2)");
}
}
async function testStrings() {
let bytes = new Int8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 1, 127, 1, 100, 111, 2, 31, 1, 14, 119, 97,
115, 109, 58, 106, 115, 45, 115, 116, 114, 105, 110, 103, 12, 102, 114, 111, 109, 67, 104, 97, 114, 67, 111,
100, 101, 0, 0, 3, 1, 0, 5, 4, 1, 1, 0, 0, 7, 10, 1, 6, 109, 101, 109, 111, 114, 121, 2, 0, 10,
-127, -128, -128, 0, 0]);
let supported = true;
try {
await WebAssembly.instantiate(bytes, {}, { builtins: ["js-string"] });
} catch (e) {
supported = false;
}
if (supported) {
console.log("String builtins are *supported* in your browser (new check)");
} else {
console.log("String builtins are *not* supported in your browser (new check)");
}
}
function testStringsOld() {
let bytes = new Int8Array([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, 3, 1, 0,
5, 4, 1, 1, 0, 0, 10, -127, -128, -128, 0, 0]);
let supported = !WebAssembly.validate(bytes, { builtins: ["js-string"] });
if (supported) {
console.log("String builtins are *supported* in your browser (old check)");
} else {
console.log("String builtins are *not* supported in your browser (old check)");
}
}
testStrings();
testStrings2();
testStringsOld();
</script>
</body>
</html>
```
2. Open developer console
## Expected result
```
String builtins are *supported* in your browser (old check)
String builtins are *supported* in your browser (new check)
String builtins are *supported* in your browser (new check 2)
```
## Actual result
```
String builtins are *supported* in your browser (old check)
String builtins are *supported* in your browser (new check)
String builtins are *not* supported in your browser (new check 2)
```
the exception message is: "TypeError: import wasm:js-string:fromCharCode must be an object"
## Notes
I tried with various combinations. Looks like compile + instantiate works as well.
More context. After updating to Safari 26.2 users started complaining on the code that used to work with prior versions of Safari and with all other major browsers. Safari before 26.2 did not support JS string builtins, so my runtime detected string builtins support and provided polyfill on absence.
As a workaround I improved feature detection to use the approach from `testStrings2`.
I also tried with Epiphany, but it looks like the version on my machine does not include support for JS string builtins.
The module, encoded by the byte sequence in the example is following:
```
(module
(; 0000000b ;) (type (; 0 ;)
(; 0000000b ;) (func
(; 0000000d ;) (param i32)
(; 0000000f ;) (result (ref extern)
)
)
(; 00000011 ;) (import "wasm:js-string" "fromCharCode" (func (; 0 ;) (type 0)
(param (; 0 ;) i32)
(result (ref extern)
))
)
)
```
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/170989896>
Vassili Bykov
Pull request: https://github.com/WebKit/WebKit/pull/59278
EWS
Committed 308234@main (e075761ea48f): <https://commits.webkit.org/308234@main>
Reviewed commits have been landed. Closing PR #59278 and removing active labels.
WebKit Commit Bot
Re-opened since this is blocked by bug 308698
Vassili Bykov
Pull request: https://github.com/WebKit/WebKit/pull/59534