Commit e295ca07 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[stack trace] Change API to use new StackTraceFrame class

This CL changes "CaptureCurrentStackTrace" to use the
FrameArrayBuilder. This way, simple and detailed stack traces use
the same mechanism to capture stack traces.

The stack trace API is implemented using the previously introduced
StackTraceFrame class, which uses FrameArray as a backing store and
can lazily initialize StackFrameInfo objects.

R=jgruber@chromium.org, yangguo@chromium.org

Bug: v8:8742
Change-Id: I716a9baa33d9ca1d2ef41a73fba26234a03b045b
Reviewed-on: https://chromium-review.googlesource.com/c/1469822
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59651}
parent 68ed2f17
...@@ -94,7 +94,7 @@ MAKE_TO_LOCAL(AccessorSignatureToLocal, FunctionTemplateInfo, AccessorSignature) ...@@ -94,7 +94,7 @@ MAKE_TO_LOCAL(AccessorSignatureToLocal, FunctionTemplateInfo, AccessorSignature)
MAKE_TO_LOCAL(MessageToLocal, Object, Message) MAKE_TO_LOCAL(MessageToLocal, Object, Message)
MAKE_TO_LOCAL(PromiseToLocal, JSObject, Promise) MAKE_TO_LOCAL(PromiseToLocal, JSObject, Promise)
MAKE_TO_LOCAL(StackTraceToLocal, FixedArray, StackTrace) MAKE_TO_LOCAL(StackTraceToLocal, FixedArray, StackTrace)
MAKE_TO_LOCAL(StackFrameToLocal, StackFrameInfo, StackFrame) MAKE_TO_LOCAL(StackFrameToLocal, StackTraceFrame, StackFrame)
MAKE_TO_LOCAL(NumberToLocal, Object, Number) MAKE_TO_LOCAL(NumberToLocal, Object, Number)
MAKE_TO_LOCAL(IntegerToLocal, Object, Integer) MAKE_TO_LOCAL(IntegerToLocal, Object, Integer)
MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32) MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32)
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "src/objects/api-callbacks.h" #include "src/objects/api-callbacks.h"
#include "src/objects/embedder-data-array-inl.h" #include "src/objects/embedder-data-array-inl.h"
#include "src/objects/embedder-data-slot-inl.h" #include "src/objects/embedder-data-slot-inl.h"
#include "src/objects/frame-array-inl.h"
#include "src/objects/hash-table-inl.h" #include "src/objects/hash-table-inl.h"
#include "src/objects/heap-object.h" #include "src/objects/heap-object.h"
#include "src/objects/js-array-inl.h" #include "src/objects/js-array-inl.h"
...@@ -2949,8 +2950,8 @@ Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate, ...@@ -2949,8 +2950,8 @@ Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
EscapableHandleScope scope(v8_isolate); EscapableHandleScope scope(v8_isolate);
auto obj = handle(Utils::OpenHandle(this)->get(index), isolate); auto obj = handle(Utils::OpenHandle(this)->get(index), isolate);
auto info = i::Handle<i::StackFrameInfo>::cast(obj); auto frame = i::Handle<i::StackTraceFrame>::cast(obj);
return scope.Escape(Utils::StackFrameToLocal(info)); return scope.Escape(Utils::StackFrameToLocal(frame));
} }
int StackTrace::GetFrameCount() const { int StackTrace::GetFrameCount() const {
...@@ -2973,29 +2974,26 @@ Local<StackTrace> StackTrace::CurrentStackTrace( ...@@ -2973,29 +2974,26 @@ Local<StackTrace> StackTrace::CurrentStackTrace(
// --- S t a c k F r a m e --- // --- S t a c k F r a m e ---
int StackFrame::GetLineNumber() const { int StackFrame::GetLineNumber() const {
int v = Utils::OpenHandle(this)->line_number(); return i::StackTraceFrame::GetLineNumber(Utils::OpenHandle(this));
return v ? v : Message::kNoLineNumberInfo;
} }
int StackFrame::GetColumn() const { int StackFrame::GetColumn() const {
int v = Utils::OpenHandle(this)->column_number(); return i::StackTraceFrame::GetColumnNumber(Utils::OpenHandle(this));
return v ? v : Message::kNoLineNumberInfo;
} }
int StackFrame::GetScriptId() const { int StackFrame::GetScriptId() const {
int v = Utils::OpenHandle(this)->script_id(); return i::StackTraceFrame::GetScriptId(Utils::OpenHandle(this));
return v ? v : Message::kNoScriptIdInfo;
} }
Local<String> StackFrame::GetScriptName() const { Local<String> StackFrame::GetScriptName() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this); i::Handle<i::Object> name =
i::Handle<i::Object> obj(self->script_name(), isolate); i::StackTraceFrame::GetFileName(Utils::OpenHandle(this));
return obj->IsString() return name->IsString()
? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
: Local<String>(); : Local<String>();
} }
...@@ -3003,10 +3001,10 @@ Local<String> StackFrame::GetScriptName() const { ...@@ -3003,10 +3001,10 @@ Local<String> StackFrame::GetScriptName() const {
Local<String> StackFrame::GetScriptNameOrSourceURL() const { Local<String> StackFrame::GetScriptNameOrSourceURL() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this); i::Handle<i::Object> name =
i::Handle<i::Object> obj(self->script_name_or_source_url(), isolate); i::StackTraceFrame::GetScriptNameOrSourceUrl(Utils::OpenHandle(this));
return obj->IsString() return name->IsString()
? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
: Local<String>(); : Local<String>();
} }
...@@ -3014,21 +3012,24 @@ Local<String> StackFrame::GetScriptNameOrSourceURL() const { ...@@ -3014,21 +3012,24 @@ Local<String> StackFrame::GetScriptNameOrSourceURL() const {
Local<String> StackFrame::GetFunctionName() const { Local<String> StackFrame::GetFunctionName() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this); i::Handle<i::Object> name =
i::Handle<i::Object> obj(self->function_name(), isolate); i::StackTraceFrame::GetFunctionName(Utils::OpenHandle(this));
return obj->IsString() return name->IsString()
? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
: Local<String>(); : Local<String>();
} }
bool StackFrame::IsEval() const { return Utils::OpenHandle(this)->is_eval(); } bool StackFrame::IsEval() const {
return i::StackTraceFrame::IsEval(Utils::OpenHandle(this));
}
bool StackFrame::IsConstructor() const { bool StackFrame::IsConstructor() const {
return Utils::OpenHandle(this)->is_constructor(); return i::StackTraceFrame::IsConstructor(Utils::OpenHandle(this));
} }
bool StackFrame::IsWasm() const { return Utils::OpenHandle(this)->is_wasm(); } bool StackFrame::IsWasm() const {
return i::StackTraceFrame::IsWasm(Utils::OpenHandle(this));
}
// --- J S O N --- // --- J S O N ---
......
...@@ -123,7 +123,7 @@ class RegisteredExtension { ...@@ -123,7 +123,7 @@ class RegisteredExtension {
V(Context, Context) \ V(Context, Context) \
V(External, Object) \ V(External, Object) \
V(StackTrace, FixedArray) \ V(StackTrace, FixedArray) \
V(StackFrame, StackFrameInfo) \ V(StackFrame, StackTraceFrame) \
V(Proxy, JSProxy) \ V(Proxy, JSProxy) \
V(debug::GeneratorObject, JSGeneratorObject) \ V(debug::GeneratorObject, JSGeneratorObject) \
V(debug::Script, Script) \ V(debug::Script, Script) \
...@@ -214,7 +214,7 @@ class Utils { ...@@ -214,7 +214,7 @@ class Utils {
static inline Local<StackTrace> StackTraceToLocal( static inline Local<StackTrace> StackTraceToLocal(
v8::internal::Handle<v8::internal::FixedArray> obj); v8::internal::Handle<v8::internal::FixedArray> obj);
static inline Local<StackFrame> StackFrameToLocal( static inline Local<StackFrame> StackFrameToLocal(
v8::internal::Handle<v8::internal::StackFrameInfo> obj); v8::internal::Handle<v8::internal::StackTraceFrame> obj);
static inline Local<Number> NumberToLocal( static inline Local<Number> NumberToLocal(
v8::internal::Handle<v8::internal::Object> obj); v8::internal::Handle<v8::internal::Object> obj);
static inline Local<Integer> IntegerToLocal( static inline Local<Integer> IntegerToLocal(
......
This diff is collapsed.
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