| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --expose-wasm --expose-gc --allow-natives-syntax | 5 // Flags: --expose-wasm --expose-gc --allow-natives-syntax |
| 6 | 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 | 9 |
| 10 function assertTraps(code, msg) { | 10 function assertTraps(code, msg) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 return; | 27 return; |
| 28 } | 28 } |
| 29 throw new MjsUnitAssertionError("Did not throw exception"); | 29 throw new MjsUnitAssertionError("Did not throw exception"); |
| 30 } | 30 } |
| 31 | 31 |
| 32 | 32 |
| 33 function makeBinop(opcode) { | 33 function makeBinop(opcode) { |
| 34 var builder = new WasmModuleBuilder(); | 34 var builder = new WasmModuleBuilder(); |
| 35 | 35 |
| 36 builder.addFunction("main", [kAstI32, kAstI32, kAstI32]) | 36 builder.addFunction("main", [kAstI32, kAstI32, kAstI32]) |
| 37 .addBody([opcode, kExprGetLocal, 0, kExprGetLocal, 1]) | 37 .addBody([ |
| 38 kExprGetLocal, 0, // -- |
| 39 kExprGetLocal, 1, // -- |
| 40 opcode, // -- |
| 41 ]) |
| 38 .exportFunc(); | 42 .exportFunc(); |
| 39 | 43 |
| 40 return builder.instantiate().exports.main; | 44 return builder.instantiate().exports.main; |
| 41 } | 45 } |
| 42 | 46 |
| 43 var divs = makeBinop(kExprI32DivS); | 47 var divs = makeBinop(kExprI32DivS); |
| 44 var divu = makeBinop(kExprI32DivU); | 48 var divu = makeBinop(kExprI32DivU); |
| 45 | 49 |
| 46 assertEquals( 33, divs( 333, 10)); | 50 assertEquals( 33, divs( 333, 10)); |
| 47 assertEquals(-33, divs(-336, 10)); | 51 assertEquals(-33, divs(-336, 10)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 69 assertEquals( 3, remu(-443, 10)); | 73 assertEquals( 3, remu(-443, 10)); |
| 70 | 74 |
| 71 assertTraps(kTrapRemByZero, "rems(100, 0);"); | 75 assertTraps(kTrapRemByZero, "rems(100, 0);"); |
| 72 assertTraps(kTrapRemByZero, "rems(-1009, 0);"); | 76 assertTraps(kTrapRemByZero, "rems(-1009, 0);"); |
| 73 | 77 |
| 74 assertTraps(kTrapRemByZero, "remu(200, 0);"); | 78 assertTraps(kTrapRemByZero, "remu(200, 0);"); |
| 75 assertTraps(kTrapRemByZero, "remu(-2009, 0);"); | 79 assertTraps(kTrapRemByZero, "remu(-2009, 0);"); |
| 76 | 80 |
| 77 assertEquals(-2147483648, remu(0x80000000, -1)); | 81 assertEquals(-2147483648, remu(0x80000000, -1)); |
| 78 assertEquals(0, rems(0x80000000, -1)); | 82 assertEquals(0, rems(0x80000000, -1)); |
| OLD | NEW |