From c48ae2d96cbfdc2216706a5e9a79ae1dce5a638b Mon Sep 17 00:00:00 2001 From: bcoe Date: Wed, 18 Nov 2020 12:12:41 -0800 Subject: [PATCH] stack-trace-api: implement getEnclosingLine/Column Introduces getEnclosingColumn and getEnclosingLine on CallSite so that the position can be used to lookup the original symbol for function when source maps are used. BUG=v8:11157 Change-Id: I06c4c374d172d206579abb170c7b7a2bd3bb159f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2547218 Reviewed-by: Jakob Kummerow Commit-Queue: Benjamin Coe Cr-Commit-Position: refs/heads/master@{#71343} --- src/builtins/builtins-callsite.cc | 16 ++++++++++ src/builtins/builtins-definitions.h | 2 ++ src/execution/messages.cc | 46 +++++++++++++++++++++++++++++ src/execution/messages.h | 11 +++++++ src/init/bootstrapper.cc | 4 +++ test/mjsunit/stack-traces.js | 20 +++++++++++++ test/mjsunit/wasm/asm-wasm-stack.js | 15 ++++++++++ 7 files changed, 114 insertions(+) diff --git a/src/builtins/builtins-callsite.cc b/src/builtins/builtins-callsite.cc index 5b7807ed4a..63e4d7a572 100644 --- a/src/builtins/builtins-callsite.cc +++ b/src/builtins/builtins-callsite.cc @@ -53,6 +53,22 @@ BUILTIN(CallSitePrototypeGetColumnNumber) { return PositiveNumberOrNull(it.Frame()->GetColumnNumber(), isolate); } +BUILTIN(CallSitePrototypeGetEnclosingColumnNumber) { + HandleScope scope(isolate); + CHECK_CALLSITE(recv, "getEnclosingColumnNumber"); + FrameArrayIterator it(isolate, GetFrameArray(isolate, recv), + GetFrameIndex(isolate, recv)); + return PositiveNumberOrNull(it.Frame()->GetEnclosingColumnNumber(), isolate); +} + +BUILTIN(CallSitePrototypeGetEnclosingLineNumber) { + HandleScope scope(isolate); + CHECK_CALLSITE(recv, "getEnclosingLineNumber"); + FrameArrayIterator it(isolate, GetFrameArray(isolate, recv), + GetFrameIndex(isolate, recv)); + return PositiveNumberOrNull(it.Frame()->GetEnclosingLineNumber(), isolate); +} + BUILTIN(CallSitePrototypeGetEvalOrigin) { HandleScope scope(isolate); CHECK_CALLSITE(recv, "getEvalOrigin"); diff --git a/src/builtins/builtins-definitions.h b/src/builtins/builtins-definitions.h index a30520d150..30fd5a3944 100644 --- a/src/builtins/builtins-definitions.h +++ b/src/builtins/builtins-definitions.h @@ -367,6 +367,8 @@ namespace internal { \ /* CallSite */ \ CPP(CallSitePrototypeGetColumnNumber) \ + CPP(CallSitePrototypeGetEnclosingColumnNumber) \ + CPP(CallSitePrototypeGetEnclosingLineNumber) \ CPP(CallSitePrototypeGetEvalOrigin) \ CPP(CallSitePrototypeGetFileName) \ CPP(CallSitePrototypeGetFunction) \ diff --git a/src/execution/messages.cc b/src/execution/messages.cc index ea31dc3374..343711b765 100644 --- a/src/execution/messages.cc +++ b/src/execution/messages.cc @@ -514,6 +514,26 @@ int JSStackFrame::GetColumnNumber() { return kNone; } +int JSStackFrame::GetEnclosingLineNumber() { + if (HasScript()) { + Handle shared = handle(function_->shared(), isolate_); + return Script::GetLineNumber(GetScript(), + shared->function_token_position()) + 1; + } else { + return kNone; + } +} + +int JSStackFrame::GetEnclosingColumnNumber() { + if (HasScript()) { + Handle shared = handle(function_->shared(), isolate_); + return Script::GetColumnNumber(GetScript(), + shared->function_token_position()) + 1; + } else { + return kNone; + } +} + int JSStackFrame::GetPromiseIndex() const { return (is_promise_all_ || is_promise_any_) ? offset_ : kNone; } @@ -602,6 +622,12 @@ int WasmStackFrame::GetPosition() const { int WasmStackFrame::GetColumnNumber() { return GetModuleOffset(); } +int WasmStackFrame::GetEnclosingColumnNumber() { + const int function_offset = + GetWasmFunctionOffset(wasm_instance_->module(), wasm_func_index_); + return function_offset; +} + int WasmStackFrame::GetModuleOffset() const { const int function_offset = GetWasmFunctionOffset(wasm_instance_->module(), wasm_func_index_); @@ -672,6 +698,26 @@ int AsmJsWasmStackFrame::GetColumnNumber() { return Script::GetColumnNumber(script, GetPosition()) + 1; } +int AsmJsWasmStackFrame::GetEnclosingLineNumber() { + DCHECK_LE(0, GetPosition()); + Handle