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

Side by Side Diff: test/mjsunit/wasm/trap-location.js

Issue 1924253002: [wasm] Patch trapping position into stack trace (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@pass-wasm-position-to-runtime
Patch Set: add TODO with tracking bug Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « test/mjsunit/wasm/stack.js ('k') | test/mjsunit/wasm/wasm-constants.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --expose-wasm
6
7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js");
9
10 // Collect the Callsite objects instead of just a string:
11 Error.prepareStackTrace = function(error, frames) {
12 return frames;
13 };
14
15 var builder = new WasmModuleBuilder();
16
17 var sig_index = builder.addSignature(kSig_i_v)
18
19 // Build a function to resemble this code:
20 // if (idx < 2) {
21 // return load(-2 / idx);
22 // } else if (idx == 2) {
23 // unreachable;
24 // } else {
25 // return call_indirect(idx);
26 // }
27 // There are four different traps which are triggered by different input values:
28 // (0) division by zero; (1) mem oob; (2) unreachable; (3) invalid call target
29 // Each of them also has a different location where it traps.
30 builder.addFunction("main", kSig_i_i)
31 .addBody([
32 // offset 1
33 kExprBlock,
34 kExprGetLocal, 0,
35 kExprI32Const, 2,
36 kExprI32LtU,
37 kExprIf,
38 // offset 8
39 kExprI32Const, 0x7e /* -2 */,
40 kExprGetLocal, 0,
41 kExprI32DivU,
42 // offset 13
43 kExprI32LoadMem, 0, 0,
44 kExprBr, 1, 1,
45 kExprEnd,
46 // offset 20
47 kExprGetLocal, 0,
48 kExprI32Const, 2,
49 kExprI32Eq,
50 kExprIf,
51 kExprUnreachable,
52 kExprEnd,
53 // offset 28
54 kExprGetLocal, 0,
55 kExprCallIndirect, kArity0, sig_index,
56 kExprEnd,
57 ])
58 .exportAs("main");
59
60 var module = builder.instantiate();
61
62 function testWasmTrap(value, reason, position) {
63 try {
64 module.exports.main(value);
65 fail("expected wasm exception");
66 } catch (e) {
67 assertEquals(kTrapMsgs[reason], e.message, "trap reason");
68 assertEquals(3, e.stack.length, "number of frames");
69 assertEquals(0, e.stack[0].getLineNumber(), "wasmFunctionIndex");
70 assertEquals(position, e.stack[0].getPosition(), "position");
71 }
72 }
73
74 // The actual tests:
75 testWasmTrap(0, kTrapDivByZero, 12);
76 testWasmTrap(1, kTrapMemOutOfBounds, 13);
77 testWasmTrap(2, kTrapUnreachable, 26);
78 testWasmTrap(3, kTrapFuncInvalid, 30);
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/stack.js ('k') | test/mjsunit/wasm/wasm-constants.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698