Reviewers: Søren Gjesse, Michail Naganov, pfeldman,

Message:
A patch for v8 for extending Timeline panel's functionality.

Description:
That is a patch for v8 debug api.
New function GetFunctionLocation is introduced.
It will be used for Timeline panel's Function Call records.
If Timeline is in operation then for each call of JS function from
V8Proxy.cpp code Timeline agent will try to get the location of the
function and save it as Function Call event.

in-param a function handle,
out-param a pointer to handle which is used for returning the file name,
out-param a pointer to int which is used for returning the line number.

static void GetFunctionLocation(v8::Handle<v8::Function> func,
                              v8::Local<v8::String>* file_name,
                              int* line_number);


Please review this at http://codereview.chromium.org/565007

SVN Base: http://v8.googlecode.com/svn/trunk/

Affected files:
  M     include/v8-debug.h
  M     src/api.cc


Index: include/v8-debug.h
===================================================================
--- include/v8-debug.h  (revision 3690)
+++ include/v8-debug.h  (working copy)
@@ -263,6 +263,16 @@
   */
   static bool EnableAgent(const char* name, int port,
                           bool wait_for_connection = false);
+
+ /**
+  * Returns a file name and line number of the specified function.
+  * \param a function handle.
+ * \param a pointer to handle which will be used for returning the file name. + * \param a pointer to int which will be used for returning the line number.
+  */
+  static void GetFunctionLocation(v8::Handle<v8::Function> func,
+                              v8::Local<v8::String>* file_name,
+                              int* line_number);
 };


Index: src/api.cc
===================================================================
--- src/api.cc  (revision 3690)
+++ src/api.cc  (working copy)
@@ -3608,6 +3608,23 @@
 // --- D e b u g   S u p p o r t ---

 #ifdef ENABLE_DEBUGGER_SUPPORT
+void Debug::GetFunctionLocation(v8::Handle<v8::Function> func,
+                                v8::Local<v8::String>* file_name,
+                                int* line_number) {
+  EnsureInitialized("v8::Debug::GetFunctionLocation()");
+  i::Handle<i::JSFunction> js_func = Utils::OpenHandle(*func);
+  i::Handle<i::SharedFunctionInfo> shared(js_func->shared());
+  if (shared->script()->IsScript()) {
+    i::Handle<i::Script> script(i::Script::cast(shared->script()));
+    if (script->name()->IsString()) {
+      *line_number = GetScriptLineNumber(script, shared->start_position());
+      i::Handle<i::String> name(i::String::cast(script->name()));
+      *file_name = Utils::ToLocal(name);
+    }
+  }
+}
+
+
 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
   EnsureInitialized("v8::Debug::SetDebugEventListener()");
   ON_BAILOUT("v8::Debug::SetDebugEventListener()", return false);


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to