Commit 09959efe authored by yurys@chromium.org's avatar yurys@chromium.org

Add support for //# sourceURL similar to deprecated //@ sourceURL one.

BUG=v8:2702
R=yangguo@chromium.org, yurys@chromium.org

Review URL: https://codereview.chromium.org/15859010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14883 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 39e9a903
...@@ -1252,7 +1252,8 @@ class V8EXPORT StackFrame { ...@@ -1252,7 +1252,8 @@ class V8EXPORT StackFrame {
/** /**
* Returns the name of the resource that contains the script for the * Returns the name of the resource that contains the script for the
* function for this StackFrame or sourceURL value if the script name * function for this StackFrame or sourceURL value if the script name
* is undefined and its source ends with //@ sourceURL=... string. * is undefined and its source ends with //# sourceURL=... string or
* deprecated //@ sourceURL=... string.
*/ */
Local<String> GetScriptNameOrSourceURL() const; Local<String> GetScriptNameOrSourceURL() const;
......
...@@ -543,11 +543,11 @@ function ScriptLineCount() { ...@@ -543,11 +543,11 @@ function ScriptLineCount() {
* If sourceURL comment is available and script starts at zero returns sourceURL * If sourceURL comment is available and script starts at zero returns sourceURL
* comment contents. Otherwise, script name is returned. See * comment contents. Otherwise, script name is returned. See
* http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt * 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 * and Source Map Revision 3 proposal for details on using //# sourceURL and
* have name. * deprecated //@ sourceURL comment to identify scripts that don't have name.
* *
* @return {?string} script name if present, value for //@ sourceURL comment * @return {?string} script name if present, value for //# sourceURL or
* otherwise. * deprecated //@ sourceURL comment otherwise.
*/ */
function ScriptNameOrSourceURL() { function ScriptNameOrSourceURL() {
if (this.line_offset > 0 || this.column_offset > 0) { if (this.line_offset > 0 || this.column_offset > 0) {
...@@ -572,7 +572,7 @@ function ScriptNameOrSourceURL() { ...@@ -572,7 +572,7 @@ function ScriptNameOrSourceURL() {
this.cachedNameOrSourceURL = this.name; this.cachedNameOrSourceURL = this.name;
if (sourceUrlPos > 4) { if (sourceUrlPos > 4) {
var sourceUrlPattern = var sourceUrlPattern =
/\/\/@[\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm; /\/\/[#@][\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm;
// Don't reuse lastMatchInfo here, so we create a new array with room // Don't reuse lastMatchInfo here, so we create a new array with room
// for four captures (array with length one longer than the index // for four captures (array with length one longer than the index
// of the fourth capture, where the numbering is zero-based). // of the fourth capture, where the numbering is zero-based).
......
...@@ -15732,8 +15732,13 @@ TEST(SourceURLInStackTrace) { ...@@ -15732,8 +15732,13 @@ TEST(SourceURLInStackTrace) {
"}\n" "}\n"
"foo();\n" "foo();\n"
"}\n" "}\n"
"eval('(' + outer +')()//@ sourceURL=eval_url');"; "eval('(' + outer +')()%s');";
CHECK(CompileRun(source)->IsUndefined());
i::ScopedVector<char> code(1024);
i::OS::SNPrintF(code, source, "//# sourceURL=eval_url");
CHECK(CompileRun(code.start())->IsUndefined());
i::OS::SNPrintF(code, source, "//@ sourceURL=eval_url");
CHECK(CompileRun(code.start())->IsUndefined());
} }
...@@ -15773,9 +15778,13 @@ TEST(InlineScriptWithSourceURLInStackTrace) { ...@@ -15773,9 +15778,13 @@ TEST(InlineScriptWithSourceURLInStackTrace) {
"}\n" "}\n"
"foo();\n" "foo();\n"
"}\n" "}\n"
"outer()\n" "outer()\n%s";
"//@ sourceURL=source_url";
CHECK(CompileRunWithOrigin(source, "url", 0, 1)->IsUndefined()); i::ScopedVector<char> code(1024);
i::OS::SNPrintF(code, source, "//# sourceURL=source_url");
CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined());
i::OS::SNPrintF(code, source, "//@ sourceURL=source_url");
CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined());
} }
...@@ -15815,9 +15824,13 @@ TEST(DynamicWithSourceURLInStackTrace) { ...@@ -15815,9 +15824,13 @@ TEST(DynamicWithSourceURLInStackTrace) {
"}\n" "}\n"
"foo();\n" "foo();\n"
"}\n" "}\n"
"outer()\n" "outer()\n%s";
"//@ sourceURL=source_url";
CHECK(CompileRunWithOrigin(source, "url", 0, 0)->IsUndefined()); i::ScopedVector<char> code(1024);
i::OS::SNPrintF(code, source, "//# sourceURL=source_url");
CHECK(CompileRunWithOrigin(code.start(), "url", 0, 0)->IsUndefined());
i::OS::SNPrintF(code, source, "//@ sourceURL=source_url");
CHECK(CompileRunWithOrigin(code.start(), "url", 0, 0)->IsUndefined());
} }
static void CreateGarbageInOldSpace() { static void CreateGarbageInOldSpace() {
......
...@@ -80,7 +80,7 @@ function listener(event, exec_state, event_data, data) { ...@@ -80,7 +80,7 @@ function listener(event, exec_state, event_data, data) {
var msg = eval('(' + json + ')'); var msg = eval('(' + json + ')');
assertTrue('context' in msg.body.script); assertTrue('context' in msg.body.script);
// Check that we pick script name from //@ sourceURL, iff present // Check that we pick script name from //# sourceURL, iff present
assertEquals(current_source.indexOf('sourceURL') >= 0 ? assertEquals(current_source.indexOf('sourceURL') >= 0 ?
'myscript.js' : undefined, 'myscript.js' : undefined,
event_data.script().name()); event_data.script().name());
...@@ -103,7 +103,7 @@ compileSource('eval("eval(\'(function(){return a;})\')")'); ...@@ -103,7 +103,7 @@ compileSource('eval("eval(\'(function(){return a;})\')")');
source_count += 2; // Using eval causes additional compilation event. source_count += 2; // Using eval causes additional compilation event.
compileSource('JSON.parse(\'{"a":1,"b":2}\')'); compileSource('JSON.parse(\'{"a":1,"b":2}\')');
// Using JSON.parse does not causes additional compilation events. // Using JSON.parse does not causes additional compilation events.
compileSource('x=1; //@ sourceURL=myscript.js'); compileSource('x=1; //# sourceURL=myscript.js');
// Make sure that the debug event listener was invoked. // Make sure that the debug event listener was invoked.
assertFalse(exception, "exception in listener") assertFalse(exception, "exception in listener")
......
...@@ -36,10 +36,10 @@ var exception = null; ...@@ -36,10 +36,10 @@ var exception = null;
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.BeforeCompile) { if (event == Debug.DebugEvent.BeforeCompile) {
event_data.script().setSource(event_data.script().source() + event_data.script().setSource(event_data.script().source() +
" //@ sourceURL=proper_location_" + (++script_number)); " //# sourceURL=proper_location_" + (++script_number));
} else if (event == Debug.DebugEvent.AfterCompile) { } else if (event == Debug.DebugEvent.AfterCompile) {
try { try {
event_data.script().setSource("a=1 //@ sourceURL=wrong_location"); event_data.script().setSource("a=1 //# sourceURL=wrong_location");
} catch(e) { } catch(e) {
exception = e; exception = e;
} }
......
...@@ -146,7 +146,7 @@ function g() { ...@@ -146,7 +146,7 @@ function g() {
}; };
eval('function h(){}'); eval('function h(){}');
eval('function sourceUrlFunc() { a = 2; }\n//@ sourceURL=sourceUrlScript'); eval('function sourceUrlFunc() { a = 2; }\n//# sourceURL=sourceUrlScript');
o = {a:function(){},b:function(){}} o = {a:function(){},b:function(){}}
......
...@@ -102,13 +102,13 @@ eval('function test1() { \n' + ...@@ -102,13 +102,13 @@ eval('function test1() { \n' +
' assertFalse(test_break_1); \n' + ' assertFalse(test_break_1); \n' +
' assertTrue(test_break_1); \n' + ' assertTrue(test_break_1); \n' +
'} \n' + '} \n' +
'//@ sourceURL=testScriptOne'); '//# sourceURL=testScriptOne');
eval('function test2() { \n' + eval('function test2() { \n' +
' assertFalse(test_break_2); \n' + ' assertFalse(test_break_2); \n' +
' assertTrue(test_break_2); \n' + ' assertTrue(test_break_2); \n' +
'} \n' + '} \n' +
'//@ sourceURL=testScriptTwo'); '//# sourceURL=testScriptTwo');
test1(); test1();
test2(); test2();
......
...@@ -64,13 +64,13 @@ function testNestedEval() { ...@@ -64,13 +64,13 @@ function testNestedEval() {
} }
function testEvalWithSourceURL() { function testEvalWithSourceURL() {
eval("function Doo() { FAIL; }; Doo();\n//@ sourceURL=res://name"); eval("function Doo() { FAIL; }; Doo();\n//# sourceURL=res://name");
} }
function testNestedEvalWithSourceURL() { function testNestedEvalWithSourceURL() {
var x = "FAIL"; var x = "FAIL";
var innerEval = 'function Inner() { eval(x); }\n//@ sourceURL=res://inner-eval'; var innerEval = 'function Inner() { eval(x); }\n//@ sourceURL=res://inner-eval';
eval("function Outer() { eval(innerEval); Inner(); }; Outer();\n//@ sourceURL=res://outer-eval"); eval("function Outer() { eval(innerEval); Inner(); }; Outer();\n//# sourceURL=res://outer-eval");
} }
function testValue() { function testValue() {
......
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