OLD | NEW |
(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: --validate-asm |
| 6 |
| 7 var filename = '(?:[^ ]+/)?test/mjsunit/wasm/asm-wasm-exception-in-tonumber.js'; |
| 8 filename = filename.replace(/\//g, '[/\\\\]'); |
| 9 |
| 10 function verifyStack(frames, expected) { |
| 11 assertTrue(frames.length >= expected.length, 'too few frames'); |
| 12 print('frames on detailed stack (' + frames.length + '):'); |
| 13 frames.forEach((fr, i) => print('[' + i + '] ' + fr)); |
| 14 expected.forEach(function(exp, i) { |
| 15 assertEquals( |
| 16 exp[0], frames[i].getFunctionName(), '[' + i + '].getFunctionName()'); |
| 17 assertEquals( |
| 18 exp[1], frames[i].getColumnNumber(), '[' + i + '].getColumnNumber()'); |
| 19 }); |
| 20 } |
| 21 |
| 22 function verifyPreformattedStack(e, expected_lines) { |
| 23 print('preformatted stack: ' + e.stack); |
| 24 var lines = e.stack.split('\n'); |
| 25 assertTrue(lines.length >= expected_lines.length, 'too few lines'); |
| 26 for (var i = 0; i < expected_lines.length; ++i) { |
| 27 assertMatches(expected_lines[i], lines[i], 'line ' + i); |
| 28 } |
| 29 } |
| 30 |
| 31 function sym(return_sym) { |
| 32 if (return_sym) return Symbol(); |
| 33 throw Error("user-thrown"); |
| 34 } |
| 35 |
| 36 function generateAsmJs(stdlib, foreign) { |
| 37 'use asm'; |
| 38 var sym = foreign.sym; |
| 39 function callSym(i) { |
| 40 i=i|0; |
| 41 return sym(i|0) | 0; |
| 42 } |
| 43 return callSym; |
| 44 } |
| 45 |
| 46 function testHelper(use_asm_js, check_detailed, expected, input) { |
| 47 if (check_detailed) { |
| 48 Error.prepareStackTrace = (error, frames) => frames; |
| 49 } else { |
| 50 delete Error.prepareStackTrace; |
| 51 } |
| 52 |
| 53 var fn_code = '(' + generateAsmJs.toString() + ')({}, {sym: sym})'; |
| 54 if (!use_asm_js) fn_code = fn_code.replace('use asm', ''); |
| 55 //print('executing:\n' + fn_code); |
| 56 var asm_js_fn = eval(fn_code); |
| 57 try { |
| 58 asm_js_fn(input); |
| 59 } catch (e) { |
| 60 if (check_detailed) { |
| 61 verifyStack(e.stack, expected); |
| 62 } else { |
| 63 verifyPreformattedStack(e, expected); |
| 64 } |
| 65 } |
| 66 } |
| 67 |
| 68 function testAll(expected_stack, expected_frames, input) { |
| 69 for (use_asm_js = 0; use_asm_js <= 1; ++use_asm_js) { |
| 70 for (test_detailed = 0; test_detailed <= 1; ++test_detailed) { |
| 71 print('\nConfig: asm ' + use_asm_js + '; detailed ' + test_detailed); |
| 72 testHelper( |
| 73 use_asm_js, test_detailed, |
| 74 test_detailed ? expected_frames : expected_stack, input); |
| 75 } |
| 76 } |
| 77 } |
| 78 |
| 79 (function testStackForThrowAtCall() { |
| 80 var expected_stack = [ |
| 81 '^Error: user-thrown$', |
| 82 '^ *at sym \\(' + filename + ':\\d+:9\\)$', |
| 83 '^ *at callSym \\(.*<anonymous>:\\d+:12\\)$', |
| 84 ]; |
| 85 var expected_frames = [ |
| 86 // function pos |
| 87 [ "sym", 9], |
| 88 [ "callSym", 12], |
| 89 ]; |
| 90 |
| 91 testAll(expected_stack, expected_frames, 0); |
| 92 })(); |
| 93 |
| 94 (function testStackForThrowAtConversion() { |
| 95 var expected_stack = [ |
| 96 '^TypeError: Cannot convert a Symbol value to a number$', |
| 97 '^ *at callSym \\(.*<anonymous>:\\d+:21\\)$', |
| 98 ]; |
| 99 var expected_frames = [ |
| 100 // function pos |
| 101 [ "callSym", 21], |
| 102 ]; |
| 103 |
| 104 testAll(expected_stack, expected_frames, 1); |
| 105 })(); |
OLD | NEW |