From 87792715c9c82e0a6981c01ef56d9b309b4fdf5a Mon Sep 17 00:00:00 2001 From: Frederik Gossen Date: Mon, 15 Apr 2019 15:03:55 +0200 Subject: [PATCH] [wasm-hints] Add Tests for Lazy Modules Added test cases for entirely lazily compiled modules. They are treated just like empty modules are. Bug: v8:9003 Change-Id: Ic0fcae7de32e50a0aac271567c18159bf8154028 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1562130 Commit-Queue: Frederik Gossen Reviewed-by: Michael Starzinger Reviewed-by: Clemens Hammacher Cr-Commit-Position: refs/heads/master@{#60846} --- .../wasm/compilation-hints-compiler.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/mjsunit/wasm/compilation-hints-compiler.js b/test/mjsunit/wasm/compilation-hints-compiler.js index ce74cc94e5..b54be5e1a3 100644 --- a/test/mjsunit/wasm/compilation-hints-compiler.js +++ b/test/mjsunit/wasm/compilation-hints-compiler.js @@ -71,3 +71,28 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); assertUnreachable, error => assertEquals("WebAssembly.compile(): call[1] expected type f32, found get_local of type i32 @+94", error.message))); })(); + +(function testInstantiateStreamingEmptyModule() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + builder.addImport('mod', 'pow', kSig_i_ii); + let bytes = builder.toBuffer(); + assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes), {mod: {pow: Math.pow}})); +})(); + +(function testInstantiateStreamingAllHintsLazy() { + print(arguments.callee.name); + let builder = new WasmModuleBuilder(); + builder.addImport('mod', 'pow', kSig_i_ii); + builder.addFunction('upow', kSig_i_i) + .addBody([kExprGetLocal, 0, + kExprGetLocal, 0, + kExprCallFunction, 0]) + .giveCompilationHint(kCompilationHintStrategyLazy, + kCompilationHintTierDefault, + kCompilationHintTierDefault) + .exportFunc(); + let bytes = builder.toBuffer(); + assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes), {mod: {pow: Math.pow}}).then( + ({module, instance}) => assertEquals(27, instance.exports.upow(3)))); +})();