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

Unified Diff: test/mjsunit/wasm/asm-wasm-stack.js

Issue 2404253002: [wasm] Provide better stack traces for asm.js code (Closed)
Patch Set: Pass encoded bytes directly instead of embedding them in the module Created 4 years, 2 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
Index: test/mjsunit/wasm/asm-wasm-stack.js
diff --git a/test/mjsunit/wasm/asm-wasm-stack.js b/test/mjsunit/wasm/asm-wasm-stack.js
new file mode 100644
index 0000000000000000000000000000000000000000..7be1014569e0d018fc306fcb020d241487f079b1
--- /dev/null
+++ b/test/mjsunit/wasm/asm-wasm-stack.js
@@ -0,0 +1,109 @@
+// 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 --allow-natives-syntax
+
+var filename = '(?:[^ ]+/)?test/mjsunit/wasm/asm-wasm-stack.js';
+filename = filename.replace(/\//g, '[/\\\\]');
+
+function checkPreformattedStack(e, expected_lines) {
+ print('preformatted stack: ' + e.stack);
+ var lines = e.stack.split('\n');
+ assertEquals(expected_lines.length, lines.length);
+ for (var i = 0; i < lines.length; ++i) {
+ assertMatches(expected_lines[i], lines[i], 'line ' + i);
+ }
+}
+
+function checkFunctionsOnCallsites(e, locations) {
+ var stack = e.stack;
+ print('callsite objects (size ' + stack.length + '):');
+ for (var i = 0; i < stack.length; ++i) {
+ var s = stack[i];
+ print(
+ ' [' + i + '] ' + s.getFunctionName() + ' (' + s.getFileName() + ':' +
+ s.getLineNumber() + ':' + s.getColumnNumber() + ')');
+ }
+ for (var i = 0; i < locations.length; ++i) {
+ var cs = stack[i];
+ assertMatches('^' + filename + '$', cs.getFileName(), 'file name at ' + i);
+ assertEquals(
+ locations[i][0], cs.getFunctionName(), 'function name at ' + i);
+ assertEquals(locations[i][1], cs.getLineNumber(), 'line number at ' + i);
+ assertEquals(
+ locations[i][2], cs.getColumnNumber(), 'column number at ' + i);
+ assertNotNull(cs.getThis(), 'receiver should be global');
+ assertEquals(stack[0].getThis(), cs.getThis(), 'receiver should be global');
+ }
+}
+
+function throwException() {
+ throw new Error('exception from JS');
+}
+
+(function PreformattedStackTraceFromJS() {
+ function generateWasmFromAsmJs(stdlib, foreign, heap) {
+ 'use asm';
+ var throwFunc = foreign.throwFunc;
+ function callThrow() {
+ throwFunc();
+ }
+ function redirectFun() {
+ callThrow();
+ }
+ return redirectFun;
+ }
+
+ var fun = generateWasmFromAsmJs(this, {throwFunc: throwException}, undefined);
+ //assertWasm(fun);
jgruber 2016/10/11 19:07:40 Is the commented code here still needed?
Clemens Hammacher 2016/10/12 07:37:18 Fixed already.
+ //assertNoWasm(throwException);
+ try {
+ fun();
+ assertUnreachable('exception should have been thrown');
jgruber 2016/10/11 19:07:40 This pattern may not work as intended - when asser
Clemens Hammacher 2016/10/12 07:37:19 Good catch! Fixed it for this test case.
+ } catch (e) {
+ assertInstanceof(e, Error);
+ checkPreformattedStack(e, [
+ '^Error: exception from JS$',
+ '^ *at throwException \\(' + filename + ':42:9\\)$',
+ '^ *at callThrow \\(' + filename + ':50:7\\)$',
+ '^ *at redirectFun \\(' + filename + ':53:7\\)$',
+ '^ *at PreformattedStackTraceFromJS \\(' + filename + ':62:5\\)$',
+ '^ *at ' + filename + ':75:3$'
+ ]);
+ }
+})();
+
+// Collect the Callsite objects instead of just a string.
+Error.prepareStackTrace = function(error, frames) {
+ return frames;
+};
+
+(function CallsiteObjectsFromJS() {
+ function generateWasmFromAsmJs(stdlib, foreign, heap) {
jgruber 2016/10/11 19:07:41 Could you reuse the function from above?
Clemens Hammacher 2016/10/12 07:37:19 Fixed already.
+ 'use asm';
+ var throwFunc = foreign.throwFunc;
+ function callThrow() {
+ throwFunc();
+ }
+ function redirectFun() {
+ callThrow();
+ }
+ return redirectFun;
+ }
+
+ var fun = generateWasmFromAsmJs(this, {throwFunc: throwException}, undefined);
+ try {
+ fun();
+ assertUnreachable('exception should have been thrown');
+ } catch (e) {
+ assertInstanceof(e, Error);
+ checkFunctionsOnCallsites(e, [
+ ['throwException', 42, 9], // --
jgruber 2016/10/11 19:07:41 What are the '// --' comments?
Clemens Hammacher 2016/10/12 07:37:19 They prevent clang format from joining the lines.
+ ['callThrow', 87, 7], // --
+ ['redirectFun', 90, 7], // --
+ ['CallsiteObjectsFromJS', 97, 5], // --
+ [null, 109, 3]
+ ]);
+ }
+})();

Powered by Google App Engine
This is Rietveld 408576698