Commit 1379f4ef authored by yurys@chromium.org's avatar yurys@chromium.org

Add scriptId to StackTrace frames.

BUG=v8:2865
R=verwaest@chromium.org, yurys@chromium.org

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

Patch from Vsevolod Vlasov <vsevik@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16459 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 68488915
...@@ -1157,6 +1157,7 @@ class V8_EXPORT Message { ...@@ -1157,6 +1157,7 @@ class V8_EXPORT Message {
static const int kNoLineNumberInfo = 0; static const int kNoLineNumberInfo = 0;
static const int kNoColumnInfo = 0; static const int kNoColumnInfo = 0;
static const int kNoScriptIdInfo = 0;
}; };
...@@ -1179,6 +1180,7 @@ class V8_EXPORT StackTrace { ...@@ -1179,6 +1180,7 @@ class V8_EXPORT StackTrace {
kIsEval = 1 << 4, kIsEval = 1 << 4,
kIsConstructor = 1 << 5, kIsConstructor = 1 << 5,
kScriptNameOrSourceURL = 1 << 6, kScriptNameOrSourceURL = 1 << 6,
kScriptId = 1 << 7,
kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
}; };
...@@ -1233,6 +1235,14 @@ class V8_EXPORT StackFrame { ...@@ -1233,6 +1235,14 @@ class V8_EXPORT StackFrame {
*/ */
int GetColumn() const; int GetColumn() const;
/**
* Returns the id of the script for the function for this StackFrame.
* This method will return Message::kNoScriptIdInfo if it is unable to
* retrieve the script id, or if kScriptId was not passed as an option when
* capturing the StackTrace.
*/
int GetScriptId() const;
/** /**
* Returns the name of the resource that contains the script for the * Returns the name of the resource that contains the script for the
* function for this StackFrame. * function for this StackFrame.
......
...@@ -2356,6 +2356,22 @@ int StackFrame::GetColumn() const { ...@@ -2356,6 +2356,22 @@ int StackFrame::GetColumn() const {
} }
int StackFrame::GetScriptId() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptId()")) {
return Message::kNoScriptIdInfo;
}
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> scriptId = GetProperty(self, "scriptId");
if (!scriptId->IsSmi()) {
return Message::kNoScriptIdInfo;
}
return i::Smi::cast(*scriptId)->value();
}
Local<String> StackFrame::GetScriptName() const { Local<String> StackFrame::GetScriptName() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) { if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) {
......
...@@ -734,7 +734,9 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace( ...@@ -734,7 +734,9 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace(
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column")); factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column"));
Handle<String> line_key = Handle<String> line_key =
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("lineNumber")); factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("lineNumber"));
Handle<String> script_key = Handle<String> script_id_key =
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("scriptId"));
Handle<String> script_name_key =
factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("scriptName")); factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("scriptName"));
Handle<String> script_name_or_source_url_key = Handle<String> script_name_or_source_url_key =
factory()->InternalizeOneByteString( factory()->InternalizeOneByteString(
...@@ -790,11 +792,20 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace( ...@@ -790,11 +792,20 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace(
Handle<Smi>(Smi::FromInt(line_number + 1), this), NONE)); Handle<Smi>(Smi::FromInt(line_number + 1), this), NONE));
} }
if (options & StackTrace::kScriptId) {
Handle<Smi> script_id(script->id(), this);
CHECK_NOT_EMPTY_HANDLE(this,
JSObject::SetLocalPropertyIgnoreAttributes(
stack_frame, script_id_key, script_id,
NONE));
}
if (options & StackTrace::kScriptName) { if (options & StackTrace::kScriptName) {
Handle<Object> script_name(script->name(), this); Handle<Object> script_name(script->name(), this);
CHECK_NOT_EMPTY_HANDLE(this, CHECK_NOT_EMPTY_HANDLE(this,
JSObject::SetLocalPropertyIgnoreAttributes( JSObject::SetLocalPropertyIgnoreAttributes(
stack_frame, script_key, script_name, NONE)); stack_frame, script_name_key, script_name,
NONE));
} }
if (options & StackTrace::kScriptNameOrSourceURL) { if (options & StackTrace::kScriptNameOrSourceURL) {
......
...@@ -16665,6 +16665,42 @@ TEST(SourceURLInStackTrace) { ...@@ -16665,6 +16665,42 @@ TEST(SourceURLInStackTrace) {
} }
static int scriptIdInStack[2];
void AnalyzeScriptIdInStack(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope scope(args.GetIsolate());
v8::Handle<v8::StackTrace> stackTrace =
v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kScriptId);
CHECK_EQ(2, stackTrace->GetFrameCount());
for (int i = 0; i < 2; i++) {
scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId();
}
}
TEST(ScriptIdInStackTrace) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
Local<ObjectTemplate> templ = ObjectTemplate::New();
templ->Set(v8_str("AnalyzeScriptIdInStack"),
v8::FunctionTemplate::New(AnalyzeScriptIdInStack));
LocalContext context(0, templ);
v8::Handle<v8::String> scriptSource = v8::String::New(
"function foo() {\n"
" AnalyzeScriptIdInStack();"
"}\n"
"foo();\n");
v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
script->Run();
for (int i = 0; i < 2; i++) {
CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo);
CHECK_EQ(scriptIdInStack[i], script->GetId());
}
}
void AnalyzeStackOfInlineScriptWithSourceURL( void AnalyzeStackOfInlineScriptWithSourceURL(
const v8::FunctionCallbackInfo<v8::Value>& args) { const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope scope(args.GetIsolate()); v8::HandleScope scope(args.GetIsolate());
......
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