Commit 0c6fa172 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Make reported "lines" on stack frames 1-based

In captured stack traces, all lines and columns must be 1-based.
Even though this makes things a bit ugly, we have to comply also for
wasm locations, where line and column encode function index and byte
offset (both are originally 0-based).

If we don't comply, the frontend might complain, as e.g. DevTools does.

BUG=chromium:659715
R=yangguo@chromium.org, kozyatinskiy@chromium.org
CC=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2493943002
Cr-Commit-Position: refs/heads/master@{#40971}
parent 7f21e67b
......@@ -706,13 +706,14 @@ class CaptureStackTraceHelper {
frame->function_index());
JSObject::AddProperty(stack_frame, function_key_, name, NONE);
}
// Encode the function index as line number.
// Encode the function index as line number (1-based).
if (!line_key_.is_null()) {
JSObject::AddProperty(
stack_frame, line_key_,
isolate_->factory()->NewNumberFromInt(frame->function_index()), NONE);
isolate_->factory()->NewNumberFromInt(frame->function_index() + 1),
NONE);
}
// Encode the byte offset as column.
// Encode the byte offset as column (1-based).
if (!column_key_.is_null()) {
Code* code = frame->LookupCode();
int offset = static_cast<int>(frame->pc() - code->instruction_start());
......
......@@ -110,13 +110,13 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(returnObjMaybe.is_null());
// The column is 1-based, so add 1 to the actual byte offset.
// Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = {
{"a", 3, 8}, // -
{"js", 4, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index), 3}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 2}, // -
{"callFn", 1, 24} // -
{"a", 3, 8}, // -
{"js", 4, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 3}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // -
{"callFn", 1, 24} // -
};
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
}
......@@ -154,11 +154,11 @@ TEST(CollectDetailedWasmStack_WasmError) {
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(maybe_return_obj.is_null());
// The column is 1-based, so add 1 to the actual byte offset.
// Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index), 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 2}, // -
{"callFn", 1, 24} //-
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // -
{"callFn", 1, 24} //-
};
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
}
......@@ -88,10 +88,10 @@ TEST(Unreachable) {
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(returnObjMaybe.is_null());
// The column is 1-based, so add 1 to the actual byte offset.
// Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index), 2}, // --
{"callFn", 1, 24} // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // --
{"callFn", 1, 24} // --
};
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
}
......@@ -130,11 +130,11 @@ TEST(IllegalLoad) {
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(returnObjMaybe.is_null());
// The column is 1-based, so add 1 to the actual byte offset.
// Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index), 8}, // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 3}, // --
{"callFn", 1, 24} // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 8}, // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // --
{"callFn", 1, 24} // --
};
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
}
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