Commit 7f927ced authored by yangguo's avatar yangguo Committed by Commit bot

Correctly accept already preprocessed stack traces.

When we preprocess stack traces, we turn code pointer and offset to
source position, and store it in place of code pointer as smi.

Preprocessing stack traces is currently disabled due to issue 4065.

R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/1125723002

Cr-Commit-Position: refs/heads/master@{#28213}
parent 785845e0
...@@ -502,8 +502,7 @@ class CaptureStackTraceHelper { ...@@ -502,8 +502,7 @@ class CaptureStackTraceHelper {
} }
} }
Handle<JSObject> NewStackFrameObject(Handle<JSFunction> fun, Handle<JSObject> NewStackFrameObject(Handle<JSFunction> fun, int position,
Handle<Code> code, Address pc,
bool is_constructor) { bool is_constructor) {
Handle<JSObject> stack_frame = Handle<JSObject> stack_frame =
factory()->NewJSObject(isolate_->object_function()); factory()->NewJSObject(isolate_->object_function());
...@@ -512,7 +511,6 @@ class CaptureStackTraceHelper { ...@@ -512,7 +511,6 @@ class CaptureStackTraceHelper {
if (!line_key_.is_null()) { if (!line_key_.is_null()) {
int script_line_offset = script->line_offset()->value(); int script_line_offset = script->line_offset()->value();
int position = code->SourcePosition(pc);
int line_number = Script::GetLineNumber(script, position); int line_number = Script::GetLineNumber(script, position);
// line_number is already shifted by the script_line_offset. // line_number is already shifted by the script_line_offset.
int relative_line_number = line_number - script_line_offset; int relative_line_number = line_number - script_line_offset;
...@@ -586,6 +584,19 @@ class CaptureStackTraceHelper { ...@@ -586,6 +584,19 @@ class CaptureStackTraceHelper {
}; };
int PositionFromStackTrace(Handle<FixedArray> elements, int index) {
DisallowHeapAllocation no_gc;
Object* maybe_code = elements->get(index + 2);
if (maybe_code->IsSmi()) {
return Smi::cast(maybe_code)->value();
} else {
Code* code = Code::cast(maybe_code);
Address pc = code->address() + Smi::cast(elements->get(index + 3))->value();
return code->SourcePosition(pc);
}
}
Handle<JSArray> Isolate::GetDetailedFromSimpleStackTrace( Handle<JSArray> Isolate::GetDetailedFromSimpleStackTrace(
Handle<JSObject> error_object) { Handle<JSObject> error_object) {
Handle<Name> key = factory()->stack_trace_symbol(); Handle<Name> key = factory()->stack_trace_symbol();
...@@ -608,15 +619,13 @@ Handle<JSArray> Isolate::GetDetailedFromSimpleStackTrace( ...@@ -608,15 +619,13 @@ Handle<JSArray> Isolate::GetDetailedFromSimpleStackTrace(
Handle<Object> recv = handle(elements->get(i), this); Handle<Object> recv = handle(elements->get(i), this);
Handle<JSFunction> fun = Handle<JSFunction> fun =
handle(JSFunction::cast(elements->get(i + 1)), this); handle(JSFunction::cast(elements->get(i + 1)), this);
Handle<Code> code = handle(Code::cast(elements->get(i + 2)), this);
Handle<Smi> offset = handle(Smi::cast(elements->get(i + 3)), this);
Address pc = code->address() + offset->value();
bool is_constructor = bool is_constructor =
recv->IsJSObject() && recv->IsJSObject() &&
Handle<JSObject>::cast(recv)->map()->GetConstructor() == *fun; Handle<JSObject>::cast(recv)->map()->GetConstructor() == *fun;
int position = PositionFromStackTrace(elements, i);
Handle<JSObject> stack_frame = Handle<JSObject> stack_frame =
helper.NewStackFrameObject(fun, code, pc, is_constructor); helper.NewStackFrameObject(fun, position, is_constructor);
FixedArray::cast(stack_trace->elements())->set(frames_seen, *stack_frame); FixedArray::cast(stack_trace->elements())->set(frames_seen, *stack_frame);
frames_seen++; frames_seen++;
...@@ -648,9 +657,9 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace( ...@@ -648,9 +657,9 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace(
// Filter frames from other security contexts. // Filter frames from other security contexts.
if (!(options & StackTrace::kExposeFramesAcrossSecurityOrigins) && if (!(options & StackTrace::kExposeFramesAcrossSecurityOrigins) &&
!this->context()->HasSameSecurityTokenAs(fun->context())) continue; !this->context()->HasSameSecurityTokenAs(fun->context())) continue;
int position = frames[i].code()->SourcePosition(frames[i].pc());
Handle<JSObject> stack_frame = helper.NewStackFrameObject( Handle<JSObject> stack_frame =
fun, frames[i].code(), frames[i].pc(), frames[i].is_constructor()); helper.NewStackFrameObject(fun, position, frames[i].is_constructor());
FixedArray::cast(stack_trace->elements())->set(frames_seen, *stack_frame); FixedArray::cast(stack_trace->elements())->set(frames_seen, *stack_frame);
frames_seen++; frames_seen++;
...@@ -1303,14 +1312,11 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, ...@@ -1303,14 +1312,11 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
Handle<JSFunction> fun = Handle<JSFunction> fun =
handle(JSFunction::cast(elements->get(i + 1)), this); handle(JSFunction::cast(elements->get(i + 1)), this);
if (fun->IsFromNativeScript()) continue; if (fun->IsFromNativeScript()) continue;
Handle<Code> code = handle(Code::cast(elements->get(i + 2)), this);
Handle<Smi> offset = handle(Smi::cast(elements->get(i + 3)), this);
Address pc = code->address() + offset->value();
Object* script = fun->shared()->script(); Object* script = fun->shared()->script();
if (script->IsScript() && if (script->IsScript() &&
!(Script::cast(script)->source()->IsUndefined())) { !(Script::cast(script)->source()->IsUndefined())) {
int pos = code->SourcePosition(pc); int pos = PositionFromStackTrace(elements, i);
Handle<Script> casted_script(Script::cast(script)); Handle<Script> casted_script(Script::cast(script));
*target = MessageLocation(casted_script, pos, pos + 1); *target = MessageLocation(casted_script, pos, pos + 1);
return true; return true;
......
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