Revision: 16459
Author:   [email protected]
Date:     Fri Aug 30 14:54:59 2013 UTC
Log:      Add scriptId to StackTrace frames.

BUG=v8:2865
[email protected], [email protected]

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

Patch from Vsevolod Vlasov <[email protected]>.
http://code.google.com/p/v8/source/detail?r=16459

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Fri Aug 30 09:03:27 2013 UTC
+++ /branches/bleeding_edge/include/v8.h        Fri Aug 30 14:54:59 2013 UTC
@@ -1157,6 +1157,7 @@

   static const int kNoLineNumberInfo = 0;
   static const int kNoColumnInfo = 0;
+  static const int kNoScriptIdInfo = 0;
 };


@@ -1179,6 +1180,7 @@
     kIsEval = 1 << 4,
     kIsConstructor = 1 << 5,
     kScriptNameOrSourceURL = 1 << 6,
+    kScriptId = 1 << 7,
     kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
   };
@@ -1233,6 +1235,14 @@
    */
   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
    * function for this StackFrame.
=======================================
--- /branches/bleeding_edge/src/api.cc  Fri Aug 30 14:08:15 2013 UTC
+++ /branches/bleeding_edge/src/api.cc  Fri Aug 30 14:54:59 2013 UTC
@@ -2354,6 +2354,22 @@
   }
   return i::Smi::cast(*column)->value();
 }
+
+
+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 {
=======================================
--- /branches/bleeding_edge/src/isolate.cc      Thu Aug 29 09:58:30 2013 UTC
+++ /branches/bleeding_edge/src/isolate.cc      Fri Aug 30 14:54:59 2013 UTC
@@ -734,7 +734,9 @@
       factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column"));
   Handle<String> line_key =
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"));
   Handle<String> script_name_or_source_url_key =
       factory()->InternalizeOneByteString(
@@ -789,12 +791,21 @@
                 stack_frame, line_key,
                 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) {
         Handle<Object> script_name(script->name(), this);
         CHECK_NOT_EMPTY_HANDLE(this,
                                JSObject::SetLocalPropertyIgnoreAttributes(
- stack_frame, script_key, script_name, NONE)); + stack_frame, script_name_key, script_name,
+                                   NONE));
       }

       if (options & StackTrace::kScriptNameOrSourceURL) {
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Wed Aug 28 08:35:04 2013 UTC +++ /branches/bleeding_edge/test/cctest/test-api.cc Fri Aug 30 14:54:59 2013 UTC
@@ -16663,6 +16663,42 @@
   i::OS::SNPrintF(code, source, "//@ sourceURL=eval_url");
   CHECK(CompileRun(code.start())->IsUndefined());
 }
+
+
+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(

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to