Skip to content

Commit da7f55a

Browse files
committed
misc/wasm: change "var" to "let", "const", add missing semicolons, place polyfill before wasm_exec.js to fix crashing in Edge
Fixes #27295
1 parent faa0667 commit da7f55a

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

misc/wasm/wasm_exec.html

+24-23
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,19 @@
1212
</head>
1313

1414
<body>
15-
<script src="wasm_exec.js"></script>
1615
<script>
17-
if (!WebAssembly.instantiateStreaming) { // polyfill
18-
WebAssembly.instantiateStreaming = async (resp, importObject) => {
19-
const source = await (await resp).arrayBuffer();
20-
return await WebAssembly.instantiate(source, importObject);
21-
};
22-
}
23-
2416
// Add polyfill for TextEncoder and TextDecoder for Microsoft Edge 17/18 support
2517
// https://caniuse.com/#feat=textencoder
2618
if (!window.TextEncoder) {
27-
TextEncoder = function(){}
19+
window.TextEncoder = function(){}
2820
TextEncoder.prototype.encode = function (string) {
29-
var octets = [];
30-
var length = string.length;
31-
var i = 0;
21+
const octets = [];
22+
const length = string.length;
23+
let i = 0;
3224
while (i < length) {
33-
var codePoint = string.codePointAt(i);
34-
var c = 0;
35-
var bits = 0;
25+
let codePoint = string.codePointAt(i);
26+
let c = 0;
27+
let bits = 0;
3628
if (codePoint <= 0x0000007F) {
3729
c = 0;
3830
bits = 0x00;
@@ -58,14 +50,14 @@
5850
};
5951
}
6052
if (!window.TextDecoder) {
61-
TextDecoder = function(){}
53+
window.TextDecoder = function(){}
6254
TextDecoder.prototype.decode = function (octets) {
63-
var string = "";
64-
var i = 0;
55+
let string = "";
56+
let i = 0;
6557
while (i < octets.length) {
66-
var octet = octets[i];
67-
var bytesNeeded = 0;
68-
var codePoint = 0;
58+
const octet = octets[i];
59+
let bytesNeeded = 0;
60+
let codePoint = 0;
6961
if (octet <= 0x7F) {
7062
bytesNeeded = 0;
7163
codePoint = octet & 0xFF;
@@ -80,7 +72,7 @@
8072
codePoint = octet & 0x07;
8173
}
8274
if (octets.length - i - bytesNeeded > 0) {
83-
var k = 0;
75+
let k = 0;
8476
while (k < bytesNeeded) {
8577
octet = octets[i + k + 1];
8678
codePoint = (codePoint << 6) | (octet & 0x3F);
@@ -93,7 +85,16 @@
9385
string += String.fromCodePoint(codePoint);
9486
i += bytesNeeded + 1;
9587
}
96-
return string
88+
return string;
89+
};
90+
}
91+
</script>
92+
<script src="wasm_exec.js"></script>
93+
<script>
94+
if (!WebAssembly.instantiateStreaming) { // polyfill
95+
WebAssembly.instantiateStreaming = async (resp, importObject) => {
96+
const source = await (await resp).arrayBuffer();
97+
return await WebAssembly.instantiate(source, importObject);
9798
};
9899
}
99100

0 commit comments

Comments
 (0)