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

Unified Diff: test/mjsunit/wasm/calls.js

Issue 1770913002: [wasm] Use the JavaScript WasmModuleBuilder utility in JS tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | test/mjsunit/wasm/divrem-trap.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/calls.js
diff --git a/test/mjsunit/wasm/calls.js b/test/mjsunit/wasm/calls.js
index ad895f98d35150e2aa40864c9b782e2afc0dbf74..0acf859eaa05e836906e2560d565738a8c479841 100644
--- a/test/mjsunit/wasm/calls.js
+++ b/test/mjsunit/wasm/calls.js
@@ -5,141 +5,100 @@
// Flags: --expose-wasm
load("test/mjsunit/wasm/wasm-constants.js");
+load("test/mjsunit/wasm/wasm-module-builder.js");
+
+function assertModule(module, memsize) {
+ // 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.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.memory = 0; // should be ignored
+ assertEquals(mem, module.memory);
+ }
+
+ assertEquals(memsize, module.memory.byteLength);
+}
-var module = (function () {
- var kBodySize = 5;
- var kNameOffset = kHeaderSize + 21 + kBodySize + 1;
-
- return _WASMEXP_.instantiateModule(bytesWithHeader(
- // -- memory
- kDeclMemory,
- 1, 1, 1,
- // -- signatures
- kDeclSignatures, 1,
- 2, kAstI32, kAstI32, kAstI32, // int, int -> int
- // -- functions
- kDeclFunctions, 1,
- kDeclFunctionName | kDeclFunctionExport,
- 0, 0,
- kNameOffset, 0, 0, 0, // name offset
- kBodySize, 0,
- // -- body
- kExprI32Sub, // --
- kExprGetLocal, 0, // --
- kExprGetLocal, 1, // --
- kDeclEnd,
- 's', 'u', 'b', 0 // name
- ));
-})();
+function assertFunction(module, func) {
+ assertEquals("object", typeof module.exports);
+
+ var exp = module.exports[func];
+ assertFalse(exp === undefined);
+ assertFalse(exp === null);
+ assertFalse(exp === 0);
+ assertEquals("function", typeof exp);
-// 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.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.memory = 0; // should be ignored
- assertEquals(mem, module.memory);
+ return exp;
}
-assertEquals(65536, module.memory.byteLength);
-
-// Check the properties of the sub function.
-assertEquals("function", typeof module.sub);
-
-assertEquals(-55, module.sub(33, 88));
-assertEquals(-55555, module.sub(33333, 88888));
-assertEquals(-5555555, module.sub(3333333, 8888888));
-
-
-var module = (function() {
- var kBodySize = 1;
- var kNameOffset2 = kHeaderSize + 19 + kBodySize + 1;
-
- return _WASMEXP_.instantiateModule(bytesWithHeader(
- // -- memory
- kDeclMemory,
- 1, 1, 1,
- // -- signatures
- kDeclSignatures, 1,
- 0, kAstStmt, // signature: void -> void
- // -- functions
- kDeclFunctions, 1,
- kDeclFunctionName | kDeclFunctionExport,
- 0, 0, // signature index
- kNameOffset2, 0, 0, 0, // name offset
- kBodySize, 0,
- kExprNop, // body
- kDeclEnd,
- 'n', 'o', 'p', 0 // name
- ));
+(function SubTest() {
+
+ var builder = new WasmModuleBuilder();
+
+ builder.addMemory(1, 1, true);
+ builder.addFunction("sub", [kAstI32, kAstI32, kAstI32])
+ .addBody([
+ kExprI32Sub, // --
+ kExprGetLocal, 0, // --
+ kExprGetLocal, 1]) // --
+ .exportFunc()
+
+ var module = builder.instantiate();
+ assertModule(module, kPageSize);
+
+ // Check the properties of the sub function.
+ var sub = assertFunction(module, "sub");
+ assertEquals(-55, sub(33, 88));
+ assertEquals(-55555, sub(33333, 88888));
+ assertEquals(-5555555, sub(3333333, 8888888));
})();
-// 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.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.memory = 0; // should be ignored
- assertEquals(mem, module.memory);
-}
-assertEquals(65536, module.memory.byteLength);
+(function NopTest() {
+
+ var builder = new WasmModuleBuilder();
-// Check the properties of the sub function.
-assertFalse(module.nop === undefined);
-assertFalse(module.nop === null);
-assertFalse(module.nop === 0);
-assertEquals("function", typeof module.nop);
+ var kPages = 2;
+ builder.addMemory(kPages, kPages, true);
+ builder.addFunction("nop", [kAstStmt])
+ .addBody([kExprNop])
+ .exportFunc();
+
+ var module = builder.instantiate();
+ assertModule(module, kPageSize * kPages);
+
+ var nop = assertFunction(module, "nop");
+ assertEquals(undefined, nop());
+})();
-assertEquals(undefined, module.nop());
(function testLt() {
- var kBodySize = 5;
- var kNameOffset = kHeaderSize + 21 + kBodySize + 1;
-
- var data = bytesWithHeader(
- // -- memory
- kDeclMemory,
- 1, 1, 1,
- // -- signatures
- kDeclSignatures, 1,
- 2, kAstI32, kAstF64, kAstF64, // (f64,f64)->int
- // -- functions
- kDeclFunctions, 1,
- kDeclFunctionName | kDeclFunctionExport,
- 0, 0, // signature index
- kNameOffset, 0, 0, 0, // name offset
- kBodySize, 0,
- // -- body
- kExprF64Lt, // --
- kExprGetLocal, 0, // --
- kExprGetLocal, 1, // --
- kDeclEnd,
- 'f', 'l', 't', 0 // name
- );
-
- var module = _WASMEXP_.instantiateModule(data);
-
- assertEquals("function", typeof module.flt);
- assertEquals(1, module.flt(-2, -1));
- assertEquals(0, module.flt(7.3, 7.1));
- assertEquals(1, module.flt(7.1, 7.3));
+ var builder = new WasmModuleBuilder();
+
+ var kPages = 3;
+ builder.addMemory(kPages, kPages, true);
+ builder.addFunction("flt", [kAstI32, kAstF64, kAstF64])
+ .addBody([
+ kExprF64Lt, // --
+ kExprGetLocal, 0, // --
+ kExprGetLocal, 1]) // --
+ .exportFunc();
+
+ var module = builder.instantiate();
+ assertModule(module, kPageSize * kPages);
+
+ var flt = assertFunction(module, "flt");
+ assertEquals(1, flt(-2, -1));
+ assertEquals(0, flt(7.3, 7.1));
+ assertEquals(1, flt(7.1, 7.3));
})();
« no previous file with comments | « no previous file | test/mjsunit/wasm/divrem-trap.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698