Index: test/mjsunit/wasm/asm-wasm-exception-in-tonumber.js |
diff --git a/test/mjsunit/wasm/asm-wasm-exception-in-tonumber.js b/test/mjsunit/wasm/asm-wasm-exception-in-tonumber.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b7fb19947451e762d56d9ebed7dcc379d2cf403a |
--- /dev/null |
+++ b/test/mjsunit/wasm/asm-wasm-exception-in-tonumber.js |
@@ -0,0 +1,110 @@ |
+// Copyright 2016 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Flags: --validate-asm |
+ |
+var filename = '(?:[^ ]+/)?test/mjsunit/wasm/asm-wasm-exception-in-tonumber.js'; |
+filename = filename.replace(/\//g, '[/\\\\]'); |
+ |
+function verifyStack(frames, expected) { |
+ assertTrue(frames.length >= expected.length, 'too few frames'); |
+ print('frames on detailed stack (' + frames.length + '):'); |
+ frames.forEach((fr, i) => print('[' + i + '] ' + fr)); |
+ expected.forEach(function(exp, i) { |
+ assertEquals( |
+ exp[0], frames[i].getFunctionName(), '[' + i + '].getFunctionName()'); |
+ assertEquals( |
+ exp[1], frames[i].getLineNumber(), '[' + i + '].getLineNumber()'); |
+ assertEquals( |
+ exp[2], frames[i].getColumnNumber(), '[' + i + '].getColumnNumber()'); |
+ assertContains( |
+ ':' + exp[1] + ':' + exp[2], frames[i].toString(), |
+ '[' + i + '].toString()'); |
+ }); |
+} |
+ |
+function verifyPreformattedStack(e, expected_lines) { |
+ print('preformatted stack: ' + e.stack); |
+ var lines = e.stack.split('\n'); |
+ assertTrue(lines.length >= expected_lines.length, 'too few lines'); |
+ for (var i = 0; i < expected_lines.length; ++i) { |
+ assertMatches(expected_lines[i], lines[i], 'line ' + i); |
+ } |
+} |
+ |
+function sym(return_sym) { |
+ if (return_sym) return Symbol(); |
+ throw Error("user-thrown"); |
+} |
+ |
+function generateAsmJs(stdlib, foreign) { |
+ 'use asm'; |
+ var sym = foreign.sym; |
+ function callSym(i) { |
+ i=i|0; |
+ return sym(i|0) | 0; |
+ } |
+ return callSym; |
+} |
+ |
+function testHelper(use_asm_js, check_detailed, expected, input) { |
+ if (check_detailed) { |
+ Error.prepareStackTrace = (error, frames) => frames; |
+ } else { |
+ delete Error.prepareStackTrace; |
+ } |
+ |
+ var fn_code = '(' + generateAsmJs.toString() + ')({}, {sym: sym})'; |
+ if (!use_asm_js) fn_code = fn_code.replace('use asm', ''); |
+ //print('executing:\n' + fn_code); |
+ var asm_js_fn = eval(fn_code); |
+ try { |
+ asm_js_fn(input); |
+ } catch (e) { |
+ if (check_detailed) { |
+ verifyStack(e.stack, expected); |
+ } else { |
+ verifyPreformattedStack(e, expected); |
+ } |
+ } |
+} |
+ |
+function testAll(expected_stack, expected_frames, input) { |
+ for (use_asm_js = 0; use_asm_js <= 1; ++use_asm_js) { |
+ for (test_detailed = 0; test_detailed <= 1; ++test_detailed) { |
+ print('\nConfig: asm ' + use_asm_js + '; detailed ' + test_detailed); |
+ testHelper( |
+ use_asm_js, test_detailed, |
+ test_detailed ? expected_frames : expected_stack, input); |
+ } |
+ } |
+} |
+ |
+(function testStackForThrowAtCall() { |
+ var expected_stack = [ |
+ '^Error: user-thrown$', |
+ '^ *at sym \\(' + filename + ':41:9\\)$', |
bradnelson
2016/12/07 19:19:06
Might be worth being less picky about the row to b
Clemens Hammacher
2016/12/08 10:50:23
Yep, removed all line number information.
|
+ '^ *at callSym \\(.*<anonymous>:6:12\\)$', |
+ ]; |
+ var expected_frames = [ |
+ // function line pos |
+ [ "sym", 41, 9], |
+ [ "callSym", 6, 12], |
+ ]; |
+ |
+ testAll(expected_stack, expected_frames, 0); |
+})(); |
+ |
+(function testStackForThrowAtConversion() { |
+ var expected_stack = [ |
+ '^TypeError: Cannot convert a Symbol value to a number$', |
+ '^ *at callSym \\(.*<anonymous>:6:21\\)$', |
+ ]; |
+ var expected_frames = [ |
+ // function line pos |
+ [ "callSym", 6, 21], |
+ ]; |
+ |
+ testAll(expected_stack, expected_frames, 1); |
+})(); |