| 1 |
// |jit-test| --wasm-compiler=optimizing; skip-if: !wasmIsSupported() |
| 2 |
|
| 3 |
// In this case we're setting things up so that wasm can't be compiled, as the |
| 4 |
// only available compiler is Ion, and enabling the Debugger will disable Ion. |
| 5 |
// |
| 6 |
// The test tests that the lazy creation of the WebAssembly object is not |
| 7 |
// dependent on whether WebAssembly can be compiled or not: if wasm is supported |
| 8 |
// then the WebAssembly object should always be created. The fact that wasm |
| 9 |
// can't be compiled is a separate matter. |
| 10 |
// |
| 11 |
// IT'S IMPORTANT NOT TO MENTION THE WEBASSEMBLY OBJECT UNTIL AFTER THE DEBUGGER |
| 12 |
// HAS BEEN CREATED, AND NOT TO LOAD lib/wasm.js OR OTHER WASM CODE HERE. |
| 13 |
|
| 14 |
var g7 = newGlobal({newCompartment: true}); |
| 15 |
g7.parent = this; |
| 16 |
g7.eval("var dbg = Debugger(parent)"); |
| 17 |
assertEq(typeof WebAssembly, "object"); |
| 18 |
|
| 19 |
// Test that validation works even if compilers are not available. |
| 20 |
|
| 21 |
WebAssembly.validate(wasmTextToBinary('(module (func))')); |
| 22 |
|
| 23 |
// Test that compilation fails with a sensible error. |
| 24 |
|
| 25 |
var bits = wasmTextToBinary('(module (func))'); |
| 26 |
var msg = /no WebAssembly compiler available/ |
| 27 |
var exn; |
| 28 |
|
| 29 |
exn = null; |
| 30 |
try { new WebAssembly.Module(bits); } catch (e) { exn = e; } |
| 31 |
assertEq(Boolean(exn), true); |
| 32 |
assertEq(Boolean(String(exn).match(msg)), true); |
| 33 |
|
| 34 |
exn = null; |
| 35 |
try { WebAssembly.compile(bits); } catch (e) { exn = e; } |
| 36 |
assertEq(Boolean(exn), true); |
| 37 |
assertEq(Boolean(String(exn).match(msg)), true); |
| 38 |
|
| 39 |
exn = null; |
| 40 |
try { WebAssembly.instantiate(bits); } catch (e) { exn = e; } |
| 41 |
assertEq(Boolean(exn), true); |
| 42 |
assertEq(Boolean(String(exn).match(msg)), true); |
| 43 |
|
| 44 |
// We do not use wasmStreamingEnabled() here because that checks whether |
| 45 |
// compilers are available, and that is precisely what we want to be checking |
| 46 |
// ourselves. But streaming compilation is available only if there are helper |
| 47 |
// threads, so that's an OK proxy. |
| 48 |
|
| 49 |
if (helperThreadCount() > 0) { |
| 50 |
exn = null; |
| 51 |
WebAssembly.compileStreaming(bits).catch(e => { exn = e; }); |
| 52 |
drainJobQueue(); |
| 53 |
assertEq(Boolean(exn), true); |
| 54 |
assertEq(Boolean(String(exn).match(msg)), true); |
| 55 |
|
| 56 |
exn = null; |
| 57 |
WebAssembly.instantiateStreaming(bits).catch(e => { exn = e; }); |
| 58 |
drainJobQueue(); |
| 59 |
assertEq(Boolean(exn), true); |
| 60 |
assertEq(Boolean(String(exn).match(msg)), true); |
| 61 |
} |