2016-10-12 09:17:12 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 09:43:04 +00:00
|
|
|
function printCallsites(stack) {
|
2016-10-12 09:17:12 +00:00
|
|
|
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() + ')');
|
|
|
|
}
|
2017-01-09 09:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkCallsiteArray(stack, expected) {
|
|
|
|
assertEquals(expected.length, stack.length, 'stack size');
|
|
|
|
for (var i = 0; i < expected.length; ++i) {
|
2016-10-12 09:17:12 +00:00
|
|
|
var cs = stack[i];
|
|
|
|
assertMatches('^' + filename + '$', cs.getFileName(), 'file name at ' + i);
|
2017-01-09 09:43:04 +00:00
|
|
|
assertEquals(expected[i][0], cs.getFunctionName(), 'function name at ' + i);
|
|
|
|
assertEquals(expected[i][1], cs.getLineNumber(), 'line number at ' + i);
|
|
|
|
assertEquals(expected[i][2], cs.getColumnNumber(), 'column number at ' + i);
|
2016-10-12 09:17:12 +00:00
|
|
|
assertNotNull(cs.getThis(), 'receiver should be global');
|
|
|
|
assertEquals(stack[0].getThis(), cs.getThis(), 'receiver should be global');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 09:43:04 +00:00
|
|
|
function checkFunctionsOnCallsites(e, expected) {
|
|
|
|
printCallsites(e.stack);
|
|
|
|
checkCallsiteArray(e.stack, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkTopFunctionsOnCallsites(e, expected) {
|
|
|
|
printCallsites(e.stack);
|
|
|
|
assertTrue(
|
|
|
|
e.stack.length >= expected.length, 'expected at least ' +
|
|
|
|
expected.length + ' callsites, got ' + e.stack.length);
|
|
|
|
checkCallsiteArray(e.stack.slice(0, expected.length), expected);
|
|
|
|
}
|
|
|
|
|
2016-10-12 09:17:12 +00:00
|
|
|
function throwException() {
|
|
|
|
throw new Error('exception from JS');
|
|
|
|
}
|
|
|
|
|
2017-01-09 09:43:04 +00:00
|
|
|
function generateWasmFromAsmJs(stdlib, foreign) {
|
2016-10-12 09:17:12 +00:00
|
|
|
'use asm';
|
|
|
|
var throwFunc = foreign.throwFunc;
|
|
|
|
function callThrow() {
|
|
|
|
throwFunc();
|
|
|
|
}
|
2016-10-25 09:00:42 +00:00
|
|
|
function redirectFun(i) {
|
2017-01-09 09:43:04 +00:00
|
|
|
i = i | 0;
|
|
|
|
switch (i | 0) {
|
2016-10-25 09:00:42 +00:00
|
|
|
case 0: callThrow(); break;
|
|
|
|
case 1: redirectFun(0); break;
|
|
|
|
case 2: redirectFun(1); break;
|
2017-04-03 14:46:10 +00:00
|
|
|
case 3: funTable[i & 0](2); break;
|
2017-04-03 15:48:03 +00:00
|
|
|
case 4: forwardFun(); break;
|
2016-10-25 09:00:42 +00:00
|
|
|
}
|
2016-10-12 09:17:12 +00:00
|
|
|
}
|
2017-04-03 15:48:03 +00:00
|
|
|
function forwardFun() {
|
|
|
|
redirectFun(3);
|
|
|
|
}
|
2017-04-03 14:46:10 +00:00
|
|
|
var funTable = [ redirectFun ];
|
2016-10-12 09:17:12 +00:00
|
|
|
return redirectFun;
|
|
|
|
}
|
|
|
|
|
|
|
|
(function PreformattedStackTraceFromJS() {
|
2017-01-09 09:43:04 +00:00
|
|
|
var fun = generateWasmFromAsmJs(this, {throwFunc: throwException});
|
|
|
|
assertTrue(%IsWasmCode(fun));
|
2016-10-12 09:17:12 +00:00
|
|
|
var e = null;
|
|
|
|
try {
|
2016-10-25 09:00:42 +00:00
|
|
|
fun(0);
|
2016-10-12 09:17:12 +00:00
|
|
|
} catch (ex) {
|
|
|
|
e = ex;
|
|
|
|
}
|
|
|
|
assertInstanceof(e, Error, 'exception should have been thrown');
|
|
|
|
checkPreformattedStack(e, [
|
|
|
|
'^Error: exception from JS$',
|
2017-01-09 09:43:04 +00:00
|
|
|
'^ *at throwException \\(' + filename + ':56:9\\)$',
|
|
|
|
'^ *at callThrow \\(' + filename + ':63:5\\)$',
|
|
|
|
'^ *at redirectFun \\(' + filename + ':68:15\\)$',
|
2017-04-03 15:48:03 +00:00
|
|
|
'^ *at PreformattedStackTraceFromJS \\(' + filename + ':87:5\\)$',
|
|
|
|
'^ *at ' + filename + ':100:3$'
|
2016-10-12 09:17:12 +00:00
|
|
|
]);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Now collect the Callsite objects instead of just a string.
|
|
|
|
Error.prepareStackTrace = function(error, frames) {
|
|
|
|
return frames;
|
|
|
|
};
|
|
|
|
|
|
|
|
(function CallsiteObjectsFromJS() {
|
2017-01-09 09:43:04 +00:00
|
|
|
var fun = generateWasmFromAsmJs(this, {throwFunc: throwException});
|
|
|
|
assertTrue(%IsWasmCode(fun));
|
2016-10-12 09:17:12 +00:00
|
|
|
var e = null;
|
|
|
|
try {
|
2017-04-03 15:48:03 +00:00
|
|
|
fun(4);
|
2016-10-12 09:17:12 +00:00
|
|
|
} catch (ex) {
|
|
|
|
e = ex;
|
|
|
|
}
|
|
|
|
assertInstanceof(e, Error, 'exception should have been thrown');
|
|
|
|
checkFunctionsOnCallsites(e, [
|
2017-01-09 09:43:04 +00:00
|
|
|
['throwException', 56, 9], // --
|
|
|
|
['callThrow', 63, 5], // --
|
|
|
|
['redirectFun', 68, 15], // --
|
|
|
|
['redirectFun', 69, 15], // --
|
|
|
|
['redirectFun', 70, 15], // --
|
2017-04-03 14:46:10 +00:00
|
|
|
['redirectFun', 71, 30], // --
|
2017-04-03 15:48:03 +00:00
|
|
|
['forwardFun', 76, 5], // --
|
|
|
|
['redirectFun', 72, 15], // --
|
|
|
|
['CallsiteObjectsFromJS', 112, 5], // --
|
|
|
|
[null, 129, 3]
|
2017-01-09 09:43:04 +00:00
|
|
|
]);
|
|
|
|
})();
|
|
|
|
|
|
|
|
function generateOverflowWasmFromAsmJs() {
|
|
|
|
'use asm';
|
|
|
|
function f(a) {
|
|
|
|
a = a | 0;
|
|
|
|
return f(a) | 0;
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
(function StackOverflowPosition() {
|
|
|
|
var fun = generateOverflowWasmFromAsmJs();
|
|
|
|
assertTrue(%IsWasmCode(fun));
|
|
|
|
var e = null;
|
|
|
|
try {
|
2017-04-03 14:46:10 +00:00
|
|
|
fun(23);
|
2017-01-09 09:43:04 +00:00
|
|
|
} catch (ex) {
|
|
|
|
e = ex;
|
|
|
|
}
|
2017-01-12 18:30:17 +00:00
|
|
|
assertInstanceof(e, RangeError, 'RangeError should have been thrown');
|
2017-01-09 09:43:04 +00:00
|
|
|
checkTopFunctionsOnCallsites(e, [
|
2017-04-03 15:48:03 +00:00
|
|
|
['f', 133, 13], // --
|
|
|
|
['f', 135, 12], // --
|
|
|
|
['f', 135, 12], // --
|
|
|
|
['f', 135, 12] // --
|
2016-10-12 09:17:12 +00:00
|
|
|
]);
|
|
|
|
})();
|