[stack-trace] Add 'IsUserJavaScript' flag to stack frame API

This CL extends the stack frame API to include a flag to distinguish
between user and V8 builtin frames. The intention is to extend the API in
a later CL, so stack traces include builtin frames.
This flag gives embedders more control what to do with builtin frames.

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

Bug: v8:8742
Change-Id: Ieda5782dd2073c1e7fd49492bfdfa829a43dc710
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1583723
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61233}
This commit is contained in:
Simon Zünd 2019-05-03 10:55:17 +02:00 committed by Commit Bot
parent 5c182baa14
commit 7ebcb5a153
7 changed files with 24 additions and 2 deletions

View File

@ -1901,6 +1901,11 @@ class V8_EXPORT StackFrame {
* Returns whether or not the associated functions is defined in wasm.
*/
bool IsWasm() const;
/**
* Returns whether or not the associated function is defined by the user.
*/
bool IsUserJavaScript() const;
};

View File

@ -3033,6 +3033,10 @@ bool StackFrame::IsWasm() const {
return i::StackTraceFrame::IsWasm(Utils::OpenHandle(this));
}
bool StackFrame::IsUserJavaScript() const {
return i::StackTraceFrame::IsUserJavaScript(Utils::OpenHandle(this));
}
// --- J S O N ---
MaybeLocal<Value> JSON::Parse(Local<Context> context,

View File

@ -3826,8 +3826,11 @@ Handle<StackFrameInfo> Factory::NewStackFrameInfo(
if (!is_wasm) {
Handle<Object> function = it.Frame()->GetFunction();
if (function->IsJSFunction()) {
function_name =
JSFunction::GetDebugName(Handle<JSFunction>::cast(function));
Handle<JSFunction> fun = Handle<JSFunction>::cast(function);
function_name = JSFunction::GetDebugName(fun);
const bool is_user_java_script = fun->shared()->IsUserJavaScript();
info->set_is_user_java_script(is_user_java_script);
}
}
info->set_function_name(*function_name);

View File

@ -35,6 +35,7 @@ SMI_ACCESSORS(StackFrameInfo, flag, kFlagOffset)
BOOL_ACCESSORS(StackFrameInfo, flag, is_eval, kIsEvalBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_constructor, kIsConstructorBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_wasm, kIsWasmBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_user_java_script, kIsUserJavaScriptBit)
OBJECT_CONSTRUCTORS_IMPL(StackTraceFrame, Struct)
NEVER_READ_ONLY_SPACE_IMPL(StackTraceFrame)

View File

@ -61,6 +61,11 @@ bool StackTraceFrame::IsWasm(Handle<StackTraceFrame> frame) {
return GetFrameInfo(frame)->is_wasm();
}
bool StackTraceFrame::IsUserJavaScript(Handle<StackTraceFrame> frame) {
if (frame->frame_info()->IsUndefined()) InitializeFrameInfo(frame);
return GetFrameInfo(frame)->is_user_java_script();
}
Handle<StackFrameInfo> StackTraceFrame::GetFrameInfo(
Handle<StackTraceFrame> frame) {
return handle(StackFrameInfo::cast(frame->frame_info()), frame->GetIsolate());

View File

@ -27,6 +27,7 @@ class StackFrameInfo : public Struct {
DECL_BOOLEAN_ACCESSORS(is_eval)
DECL_BOOLEAN_ACCESSORS(is_constructor)
DECL_BOOLEAN_ACCESSORS(is_wasm)
DECL_BOOLEAN_ACCESSORS(is_user_java_script)
DECL_INT_ACCESSORS(flag)
DECL_CAST(StackFrameInfo)
@ -43,6 +44,7 @@ class StackFrameInfo : public Struct {
static const int kIsEvalBit = 0;
static const int kIsConstructorBit = 1;
static const int kIsWasmBit = 2;
static const int kIsUserJavaScriptBit = 3;
OBJECT_CONSTRUCTORS(StackFrameInfo, Struct);
};
@ -80,6 +82,7 @@ class StackTraceFrame : public Struct {
static bool IsEval(Handle<StackTraceFrame> frame);
static bool IsConstructor(Handle<StackTraceFrame> frame);
static bool IsWasm(Handle<StackTraceFrame> frame);
static bool IsUserJavaScript(Handle<StackTraceFrame> frame);
private:
OBJECT_CONSTRUCTORS(StackTraceFrame, Struct);

View File

@ -16446,6 +16446,7 @@ void checkStackFrame(const char* expected_script_name,
CHECK_EQ(expected_column, frame->GetColumn());
CHECK_EQ(is_eval, frame->IsEval());
CHECK_EQ(is_constructor, frame->IsConstructor());
CHECK(frame->IsUserJavaScript());
}