From eb24a86e1b8b539bb6b8d91461a39c6f5eb4acc2 Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Tue, 5 Oct 2010 08:53:51 +0000 Subject: [PATCH] StackTrace should provide access to //@ sourceURL=... value Review URL: http://codereview.chromium.org/3602013 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5586 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 10 +++++++++- src/api.cc | 15 +++++++++++++++ src/top.cc | 19 +++++++++++++++++++ test/cctest/test-api.cc | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/include/v8.h b/include/v8.h index 9ee1687d6..0c2cf8c15 100644 --- a/include/v8.h +++ b/include/v8.h @@ -758,8 +758,9 @@ class V8EXPORT StackTrace { kFunctionName = 1 << 3, kIsEval = 1 << 4, kIsConstructor = 1 << 5, + kScriptNameOrSourceURL = 1 << 6, kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, - kDetailed = kOverview | kIsEval | kIsConstructor + kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL }; /** @@ -818,6 +819,13 @@ class V8EXPORT StackFrame { */ Local GetScriptName() const; + /** + * Returns the name of the resource that contains the script for the + * function for this StackFrame or sourceURL value if the script name + * is undefined and its source ends with //@ sourceURL=... string. + */ + Local GetScriptNameOrSourceURL() const; + /** * Returns the name of the function associated with this stack frame. */ diff --git a/src/api.cc b/src/api.cc index 7ca9e8fad..37c3bfe47 100644 --- a/src/api.cc +++ b/src/api.cc @@ -1679,6 +1679,21 @@ Local StackFrame::GetScriptName() const { } +Local StackFrame::GetScriptNameOrSourceURL() const { + if (IsDeadCheck("v8::StackFrame::GetScriptNameOrSourceURL()")) { + return Local(); + } + ENTER_V8; + HandleScope scope; + i::Handle self = Utils::OpenHandle(this); + i::Handle name = GetProperty(self, "scriptNameOrSourceURL"); + if (!name->IsString()) { + return Local(); + } + return scope.Close(Local::Cast(Utils::ToLocal(name))); +} + + Local StackFrame::GetFunctionName() const { if (IsDeadCheck("v8::StackFrame::GetFunctionName()")) return Local(); ENTER_V8; diff --git a/src/top.cc b/src/top.cc index e172cb866..0f8c7274c 100644 --- a/src/top.cc +++ b/src/top.cc @@ -385,6 +385,25 @@ Handle Top::CaptureCurrentStackTrace( SetProperty(stackFrame, script_key, script_name, NONE); } + if (options & StackTrace::kScriptNameOrSourceURL) { + Handle script_name(script->name()); + Handle method_name = + Factory::LookupAsciiSymbol("nameOrSourceURL"); + Handle script_wrapper = GetScriptWrapper(Handle