Commit 6a3756f9 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Fix names for forward declared functions.

This fixes the name stored with functions where the declaration was
hoisted above the actual function definition. It also extends test
coverage and emits proper source position mapping for such cases.

R=clemensh@chromium.org
TEST=mjsunit/wasm/asm-wasm-stack
BUG=v8:6127

Change-Id: I675a98b244fe2157925e799b5c46b7f6bd53c9da
Reviewed-on: https://chromium-review.googlesource.com/466247Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44361}
parent 31700b7f
......@@ -723,19 +723,17 @@ void AsmJsParser::ValidateFunction() {
if (function_info->kind == VarKind::kUnused) {
function_info->kind = VarKind::kFunction;
function_info->function_builder = module_builder_->AddFunction();
// TODO(bradnelson): Cleanup memory management here.
// WasmModuleBuilder should own these.
char* function_name = zone()->NewArray<char>(function_name_raw.size());
memcpy(function_name, function_name_raw.data(), function_name_raw.size());
function_info->function_builder->SetName(
{function_name, static_cast<int>(function_name_raw.size())});
function_info->index = function_info->function_builder->func_index();
function_info->function_defined = true;
} else if (function_info->function_defined) {
FAIL("Function redefined");
} else {
function_info->function_defined = true;
}
function_info->function_defined = true;
// TODO(bradnelson): Cleanup memory management here.
// WasmModuleBuilder should own these.
char* function_name_chr = zone()->NewArray<char>(function_name_raw.size());
memcpy(function_name_chr, function_name_raw.data(), function_name_raw.size());
function_info->function_builder->SetName(
{function_name_chr, static_cast<int>(function_name_raw.size())});
current_function_builder_ = function_info->function_builder;
return_type_ = nullptr;
......@@ -2088,10 +2086,8 @@ AsmType* AsmJsParser::ValidateCall() {
function_info->function_builder = module_builder_->AddFunction();
function_info->index = function_info->function_builder->func_index();
function_info->type = function_type;
// TODO(bradnelson): Figure out the right debug scanner offset and
// re-enable.
// current_function_builder_->AddAsmWasmOffset(scanner_.GetPosition(),
// scanner_.GetPosition());
// TODO(mstarzinger): Fix the {to_number_position} and test it.
current_function_builder_->AddAsmWasmOffset(pos, pos);
current_function_builder_->Emit(kExprCallFunction);
current_function_builder_->EmitDirectCallIndex(function_info->index);
} else if (function_info->kind == VarKind::kImportedFunction) {
......
......@@ -69,8 +69,12 @@ function generateWasmFromAsmJs(stdlib, foreign) {
case 1: redirectFun(0); break;
case 2: redirectFun(1); break;
case 3: funTable[i & 0](2); break;
case 4: forwardFun(); break;
}
}
function forwardFun() {
redirectFun(3);
}
var funTable = [ redirectFun ];
return redirectFun;
}
......@@ -90,8 +94,8 @@ function generateWasmFromAsmJs(stdlib, foreign) {
'^ *at throwException \\(' + filename + ':56:9\\)$',
'^ *at callThrow \\(' + filename + ':63:5\\)$',
'^ *at redirectFun \\(' + filename + ':68:15\\)$',
'^ *at PreformattedStackTraceFromJS \\(' + filename + ':83:5\\)$',
'^ *at ' + filename + ':96:3$'
'^ *at PreformattedStackTraceFromJS \\(' + filename + ':87:5\\)$',
'^ *at ' + filename + ':100:3$'
]);
})();
......@@ -105,7 +109,7 @@ Error.prepareStackTrace = function(error, frames) {
assertTrue(%IsWasmCode(fun));
var e = null;
try {
fun(3);
fun(4);
} catch (ex) {
e = ex;
}
......@@ -117,8 +121,10 @@ Error.prepareStackTrace = function(error, frames) {
['redirectFun', 69, 15], // --
['redirectFun', 70, 15], // --
['redirectFun', 71, 30], // --
['CallsiteObjectsFromJS', 108, 5], // --
[null, 123, 3]
['forwardFun', 76, 5], // --
['redirectFun', 72, 15], // --
['CallsiteObjectsFromJS', 112, 5], // --
[null, 129, 3]
]);
})();
......@@ -142,9 +148,9 @@ function generateOverflowWasmFromAsmJs() {
}
assertInstanceof(e, RangeError, 'RangeError should have been thrown');
checkTopFunctionsOnCallsites(e, [
['f', 127, 13], // --
['f', 129, 12], // --
['f', 129, 12], // --
['f', 129, 12] // --
['f', 133, 13], // --
['f', 135, 12], // --
['f', 135, 12], // --
['f', 135, 12] // --
]);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment