Commit 26721b7d authored by yurys@chromium.org's avatar yurys@chromium.org

This issue is for landing patch by vsevik: http://codereview.chromium.org/10966011/

SourceURL comments for scripts having a name. 

sourceURL comment is now preferred script name for all scripts except 
for those with non zero start position (e.g. inline scripts in HTML). 


BUG=v8:2342
Review URL: https://codereview.chromium.org/10959038

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12576 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 083ee63a
......@@ -532,8 +532,8 @@ function ScriptLineCount() {
/**
* Returns the name of script if available, contents of sourceURL comment
* otherwise. See
* If sourceURL comment is available and script starts at zero returns sourceURL
* comment contents. Otherwise, script name is returned. See
* http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt
* for details on using //@ sourceURL comment to identify scritps that don't
* have name.
......@@ -542,14 +542,15 @@ function ScriptLineCount() {
* otherwise.
*/
function ScriptNameOrSourceURL() {
if (this.name) {
if (this.line_offset > 0 || this.column_offset > 0) {
return this.name;
}
// The result is cached as on long scripts it takes noticable time to search
// for the sourceURL.
if (this.hasCachedNameOrSourceURL)
return this.cachedNameOrSourceURL;
if (this.hasCachedNameOrSourceURL) {
return this.cachedNameOrSourceURL;
}
this.hasCachedNameOrSourceURL = true;
// TODO(608): the spaces in a regexp below had to be escaped as \040
......
......@@ -213,5 +213,16 @@ static inline v8::Local<v8::Value> CompileRun(const char* source) {
return v8::Script::Compile(v8::String::New(source))->Run();
}
// Helper function that compiles and runs the source with given origin.
static inline v8::Local<v8::Value> CompileRunWithOrigin(const char* source,
const char* origin_url,
int line_number,
int column_number) {
v8::ScriptOrigin origin(v8::String::New(origin_url),
v8::Integer::New(line_number),
v8::Integer::New(column_number));
return v8::Script::Compile(v8::String::New(source), &origin)->Run();
}
#endif // ifndef CCTEST_H_
......@@ -14452,6 +14452,89 @@ TEST(SourceURLInStackTrace) {
}
v8::Handle<Value> AnalyzeStackOfInlineScriptWithSourceURL(
const v8::Arguments& args) {
v8::HandleScope scope;
v8::Handle<v8::StackTrace> stackTrace =
v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
CHECK_EQ(4, stackTrace->GetFrameCount());
v8::Handle<v8::String> url = v8_str("url");
for (int i = 0; i < 3; i++) {
v8::Handle<v8::String> name =
stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
CHECK(!name.IsEmpty());
CHECK_EQ(url, name);
}
return v8::Undefined();
}
TEST(InlineScriptWithSourceURLInStackTrace) {
v8::HandleScope scope;
Local<ObjectTemplate> templ = ObjectTemplate::New();
templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"),
v8::FunctionTemplate::New(
AnalyzeStackOfInlineScriptWithSourceURL));
LocalContext context(0, templ);
const char *source =
"function outer() {\n"
"function bar() {\n"
" AnalyzeStackOfInlineScriptWithSourceURL();\n"
"}\n"
"function foo() {\n"
"\n"
" bar();\n"
"}\n"
"foo();\n"
"}\n"
"outer()\n"
"//@ sourceURL=source_url";
CHECK(CompileRunWithOrigin(source, "url", 0, 1)->IsUndefined());
}
v8::Handle<Value> AnalyzeStackOfDynamicScriptWithSourceURL(
const v8::Arguments& args) {
v8::HandleScope scope;
v8::Handle<v8::StackTrace> stackTrace =
v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
CHECK_EQ(4, stackTrace->GetFrameCount());
v8::Handle<v8::String> url = v8_str("source_url");
for (int i = 0; i < 3; i++) {
v8::Handle<v8::String> name =
stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
CHECK(!name.IsEmpty());
CHECK_EQ(url, name);
}
return v8::Undefined();
}
TEST(DynamicWithSourceURLInStackTrace) {
v8::HandleScope scope;
Local<ObjectTemplate> templ = ObjectTemplate::New();
templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"),
v8::FunctionTemplate::New(
AnalyzeStackOfDynamicScriptWithSourceURL));
LocalContext context(0, templ);
const char *source =
"function outer() {\n"
"function bar() {\n"
" AnalyzeStackOfDynamicScriptWithSourceURL();\n"
"}\n"
"function foo() {\n"
"\n"
" bar();\n"
"}\n"
"foo();\n"
"}\n"
"outer()\n"
"//@ sourceURL=source_url";
CHECK(CompileRunWithOrigin(source, "url", 0, 0)->IsUndefined());
}
static void CreateGarbageInOldSpace() {
v8::HandleScope scope;
i::AlwaysAllocateScope always_allocate;
......
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