Commit 09ff5c4c authored by yurys@chromium.org's avatar yurys@chromium.org

Provide access to function inferred name in v8 public API

Review URL: https://chromiumcodereview.appspot.com/9146039

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10499 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 557e2cd9
......@@ -1731,6 +1731,14 @@ class Function : public Object {
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.
......
......@@ -3622,6 +3622,12 @@ Handle<Value> Function::GetName() const {
}
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 {
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
if (func->shared()->script()->IsScript()) {
......
......@@ -14042,6 +14042,17 @@ THREADED_TEST(ScriptOrigin) {
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;
......
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