Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: test/mjsunit/wasm/instantiate-module-basic.js

Issue 2084573002: Upgrade Wasm JS API, step 1 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Separate test refactorings Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/wasm/instantiate-module-basic.js
diff --git a/test/mjsunit/wasm/instantiate-module-basic.js b/test/mjsunit/wasm/instantiate-module-basic.js
index 800dcc1f12fca070da25ae6a20a3c31ce515565b..72a3425c906de342f569d108b40871c6fae6807b 100644
--- a/test/mjsunit/wasm/instantiate-module-basic.js
+++ b/test/mjsunit/wasm/instantiate-module-basic.js
@@ -7,44 +7,54 @@
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
-var kReturnValue = 117;
-
-var module = (function Build() {
- var builder = new WasmModuleBuilder();
+let kReturnValue = 117;
+let buffer = (() => {
+ let builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addFunction("main", kSig_i)
.addBody([kExprI8Const, kReturnValue])
.exportFunc();
- return builder.instantiate();
-})();
-
-// Check the module exists.
-assertFalse(module === undefined);
-assertFalse(module === null);
-assertFalse(module === 0);
-assertEquals("object", typeof module);
-
-// Check the memory is an ArrayBuffer.
-var mem = module.exports.memory;
-assertFalse(mem === undefined);
-assertFalse(mem === null);
-assertFalse(mem === 0);
-assertEquals("object", typeof mem);
-assertTrue(mem instanceof ArrayBuffer);
-for (var i = 0; i < 4; i++) {
- module.exports.memory = 0; // should be ignored
- assertEquals(mem, module.exports.memory);
+ return builder.toBuffer();
+})()
+
+function CheckInstance(instance) {
+ assertFalse(instance === undefined);
+ assertFalse(instance === null);
+ assertFalse(instance === 0);
+ assertEquals("object", typeof instance);
+
+ // Check the memory is an ArrayBuffer.
+ var mem = instance.exports.memory;
+ assertFalse(mem === undefined);
+ assertFalse(mem === null);
+ assertFalse(mem === 0);
+ assertEquals("object", typeof mem);
+ assertTrue(mem instanceof ArrayBuffer);
+ for (let i = 0; i < 4; i++) {
+ instance.exports.memory = 0; // should be ignored
+ assertSame(mem, instance.exports.memory);
+ }
+
+ assertEquals(65536, instance.exports.memory.byteLength);
+
+ // Check the properties of the main function.
+ let main = instance.exports.main;
+ assertFalse(main === undefined);
+ assertFalse(main === null);
+ assertFalse(main === 0);
+ assertEquals("function", typeof main);
+
+ assertEquals(kReturnValue, main());
}
-assertEquals(65536, module.exports.memory.byteLength);
+// Deprecated experimental API.
+CheckInstance(Wasm.instantiateModule(buffer));
-// Check the properties of the main function.
-var main = module.exports.main;
-assertFalse(main === undefined);
-assertFalse(main === null);
-assertFalse(main === 0);
-assertEquals("function", typeof main);
+// Official API
+let module = new WebAssembly.Module(buffer);
+CheckInstance(new WebAssembly.Instance(module));
-assertEquals(kReturnValue, main());
+let promise = WebAssembly.compile(buffer);
+promise.then(module => CheckInstance(new WebAssembly.Instance(module)));

Powered by Google App Engine
This is Rietveld 408576698