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

Unified Diff: test/mjsunit/wasm/divrem-trap.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 | « test/mjsunit/wasm/calls.js ('k') | test/mjsunit/wasm/export-table.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/wasm/divrem-trap.js
diff --git a/test/mjsunit/wasm/divrem-trap.js b/test/mjsunit/wasm/divrem-trap.js
index 08d1cd82a988e122510d2b748df0b989c1ba6bb2..976e4736bca371b7a01068d2857248a83dca0d7c 100644
--- a/test/mjsunit/wasm/divrem-trap.js
+++ b/test/mjsunit/wasm/divrem-trap.js
@@ -5,6 +5,7 @@
// Flags: --expose-wasm --expose-gc --allow-natives-syntax
load("test/mjsunit/wasm/wasm-constants.js");
+load("test/mjsunit/wasm/wasm-module-builder.js");
function assertTraps(code, msg) {
var threwException = true;
@@ -29,38 +30,18 @@ function assertTraps(code, msg) {
}
-function makeDivRem(opcode) {
- var kBodySize = 5;
- var kNameMainOffset = kHeaderSize + 6 + 11 + kBodySize + 1;
-
- var data = bytesWithHeader(
- // signatures
- kDeclSignatures, 1,
- 2, kAstI32, kAstI32, kAstI32, // (int,int) -> int
- // -- main function
- kDeclFunctions, 1,
- kDeclFunctionName | kDeclFunctionExport,
- 0, 0,
- kNameMainOffset, 0, 0, 0, // name offset
- kBodySize, 0,
- // main body
- opcode, // --
- kExprGetLocal, 0, // --
- kExprGetLocal, 1, // --
- // names
- kDeclEnd,
- 'm', 'a', 'i', 'n', 0 // --
- );
-
- var module = _WASMEXP_.instantiateModule(data);
-
- assertEquals("function", typeof module.main);
-
- return module.main;
+function makeBinop(opcode) {
+ var builder = new WasmModuleBuilder();
+
+ builder.addFunction("main", [kAstI32, kAstI32, kAstI32])
+ .addBody([opcode, kExprGetLocal, 0, kExprGetLocal, 1])
+ .exportFunc();
+
+ return builder.instantiate().exports.main;
}
-var divs = makeDivRem(kExprI32DivS);
-var divu = makeDivRem(kExprI32DivU);
+var divs = makeBinop(kExprI32DivS);
+var divu = makeBinop(kExprI32DivU);
assertEquals( 33, divs( 333, 10));
assertEquals(-33, divs(-336, 10));
@@ -78,8 +59,8 @@ assertTraps(kTrapDivUnrepresentable, "divs(0x80000000, -1)");
assertEquals(0, divu(0x80000000, -1));
-var rems = makeDivRem(kExprI32RemS);
-var remu = makeDivRem(kExprI32RemU);
+var rems = makeBinop(kExprI32RemS);
+var remu = makeBinop(kExprI32RemU);
assertEquals( 3, rems( 333, 10));
assertEquals(-6, rems(-336, 10));
« no previous file with comments | « test/mjsunit/wasm/calls.js ('k') | test/mjsunit/wasm/export-table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698