OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 22634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22645 Local<Script> script = v8::ScriptCompiler::Compile( | 22645 Local<Script> script = v8::ScriptCompiler::Compile( |
22646 isolate, &script_source); | 22646 isolate, &script_source); |
22647 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); | 22647 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); |
22648 CHECK(!script_name.IsEmpty()); | 22648 CHECK(!script_name.IsEmpty()); |
22649 CHECK(script_name->IsString()); | 22649 CHECK(script_name->IsString()); |
22650 String::Utf8Value utf8_name(script_name); | 22650 String::Utf8Value utf8_name(script_name); |
22651 CHECK_EQ(url, *utf8_name); | 22651 CHECK_EQ(url, *utf8_name); |
22652 int line_number = script->GetUnboundScript()->GetLineNumber(0); | 22652 int line_number = script->GetUnboundScript()->GetLineNumber(0); |
22653 CHECK_EQ(13, line_number); | 22653 CHECK_EQ(13, line_number); |
22654 } | 22654 } |
| 22655 |
| 22656 |
| 22657 void SourceURLHelper(const char* source, const char* expected_source_url, |
| 22658 const char* expected_source_mapping_url) { |
| 22659 Local<Script> script = v8_compile(source); |
| 22660 if (expected_source_url != NULL) { |
| 22661 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); |
| 22662 CHECK_EQ(expected_source_url, *url); |
| 22663 } else { |
| 22664 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); |
| 22665 } |
| 22666 if (expected_source_mapping_url != NULL) { |
| 22667 v8::String::Utf8Value url( |
| 22668 script->GetUnboundScript()->GetSourceMappingURL()); |
| 22669 CHECK_EQ(expected_source_mapping_url, *url); |
| 22670 } else { |
| 22671 CHECK(script->GetUnboundScript()->GetSourceMappingURL()->IsUndefined()); |
| 22672 } |
| 22673 } |
| 22674 |
| 22675 |
| 22676 TEST(ScriptSourceURLAndSourceMappingURL) { |
| 22677 LocalContext env; |
| 22678 v8::Isolate* isolate = env->GetIsolate(); |
| 22679 v8::HandleScope scope(isolate); |
| 22680 SourceURLHelper("function foo() {}\n" |
| 22681 "//# sourceURL=bar1.js\n", "bar1.js", NULL); |
| 22682 SourceURLHelper("function foo() {}\n" |
| 22683 "//# sourceMappingURL=bar2.js\n", NULL, "bar2.js"); |
| 22684 |
| 22685 // Both sourceURL and sourceMappingURL. |
| 22686 SourceURLHelper("function foo() {}\n" |
| 22687 "//# sourceURL=bar3.js\n" |
| 22688 "//# sourceMappingURL=bar4.js\n", "bar3.js", "bar4.js"); |
| 22689 |
| 22690 // Two source URLs; the first one is ignored. |
| 22691 SourceURLHelper("function foo() {}\n" |
| 22692 "//# sourceURL=ignoreme.js\n" |
| 22693 "//# sourceURL=bar5.js\n", "bar5.js", NULL); |
| 22694 SourceURLHelper("function foo() {}\n" |
| 22695 "//# sourceMappingURL=ignoreme.js\n" |
| 22696 "//# sourceMappingURL=bar6.js\n", NULL, "bar6.js"); |
| 22697 |
| 22698 // SourceURL or sourceMappingURL in the middle of the script. |
| 22699 SourceURLHelper("function foo() {}\n" |
| 22700 "//# sourceURL=bar7.js\n" |
| 22701 "function baz() {}\n", "bar7.js", NULL); |
| 22702 SourceURLHelper("function foo() {}\n" |
| 22703 "//# sourceMappingURL=bar8.js\n" |
| 22704 "function baz() {}\n", NULL, "bar8.js"); |
| 22705 |
| 22706 // Too much whitespace. |
| 22707 SourceURLHelper("function foo() {}\n" |
| 22708 "//# sourceURL=bar9.js\n" |
| 22709 "//# sourceMappingURL=bar10.js\n", NULL, NULL); |
| 22710 SourceURLHelper("function foo() {}\n" |
| 22711 "//# sourceURL =bar11.js\n" |
| 22712 "//# sourceMappingURL =bar12.js\n", NULL, NULL); |
| 22713 |
| 22714 // Not too much whitespace. |
| 22715 SourceURLHelper("function foo() {}\n" |
| 22716 "//# sourceURL= bar11.js \n" |
| 22717 "//# sourceMappingURL= bar12.js \n", "bar11.js", "bar12.js"); |
| 22718 } |
OLD | NEW |