Revision: 10499
Author:   [email protected]
Date:     Wed Jan 25 04:45:54 2012
Log:      Provide access to function inferred name in v8 public API
Review URL: https://chromiumcodereview.appspot.com/9146039
http://code.google.com/p/v8/source/detail?r=10499

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

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Jan 24 05:07:21 2012
+++ /branches/bleeding_edge/include/v8.h        Wed Jan 25 04:45:54 2012
@@ -1731,6 +1731,14 @@
   V8EXPORT void SetName(Handle<String> name);
   V8EXPORT Handle<Value> GetName() const;

+  /**
+   * Name inferred from variable or property assignment of this function.
+   * Used to facilitate debugging and profiling of JavaScript code written
+   * in an OO style, where many functions are anonymous but are assigned
+   * to object properties.
+   */
+  V8EXPORT Handle<Value> GetInferredName() const;
+
   /**
    * Returns zero based line number of function body and
    * kLineOffsetNotFound if no information available.
=======================================
--- /branches/bleeding_edge/src/api.cc  Wed Jan 18 08:16:11 2012
+++ /branches/bleeding_edge/src/api.cc  Wed Jan 25 04:45:54 2012
@@ -3620,6 +3620,12 @@
   i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
   return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name()));
 }
+
+
+Handle<Value> Function::GetInferredName() const {
+  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
+ return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name()));
+}


 ScriptOrigin Function::GetScriptOrigin() const {
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Tue Jan 24 08:36:55 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Wed Jan 25 04:45:54 2012
@@ -14042,6 +14042,17 @@
   CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
 }

+THREADED_TEST(FunctionGetInferredName) {
+  v8::HandleScope scope;
+  LocalContext env;
+  v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
+  v8::Handle<v8::String> script = v8::String::New(
+      "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
+  v8::Script::Compile(script, &origin)->Run();
+  v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+      env->Global()->Get(v8::String::New("f")));
+  CHECK_EQ("foo.bar.baz", *v8::String::AsciiValue(f->GetInferredName()));
+}

 THREADED_TEST(ScriptLineNumber) {
   v8::HandleScope scope;

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

Reply via email to