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 22743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22754 call_eval_context = v8::Context::New(isolate); | 22754 call_eval_context = v8::Context::New(isolate); |
22755 v8::Context::Scope scope(call_eval_context); | 22755 v8::Context::Scope scope(call_eval_context); |
22756 call_eval_bound_function = | 22756 call_eval_bound_function = |
22757 Local<Function>::Cast(CompileRun("eval.bind(this, '1')")); | 22757 Local<Function>::Cast(CompileRun("eval.bind(this, '1')")); |
22758 } | 22758 } |
22759 env->Global()->Set(v8_str("CallEval"), | 22759 env->Global()->Set(v8_str("CallEval"), |
22760 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction()); | 22760 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction()); |
22761 Local<Value> result = CompileRun("CallEval();"); | 22761 Local<Value> result = CompileRun("CallEval();"); |
22762 CHECK_EQ(result, v8::Integer::New(isolate, 1)); | 22762 CHECK_EQ(result, v8::Integer::New(isolate, 1)); |
22763 } | 22763 } |
| 22764 |
| 22765 |
| 22766 void SourceURLHelper(const char* source, const char* expected_source_url, |
| 22767 const char* expected_source_mapping_url) { |
| 22768 Local<Script> script = v8_compile(source); |
| 22769 if (expected_source_url != NULL) { |
| 22770 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); |
| 22771 CHECK_EQ(expected_source_url, *url); |
| 22772 } else { |
| 22773 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); |
| 22774 } |
| 22775 if (expected_source_mapping_url != NULL) { |
| 22776 v8::String::Utf8Value url( |
| 22777 script->GetUnboundScript()->GetSourceMappingURL()); |
| 22778 CHECK_EQ(expected_source_mapping_url, *url); |
| 22779 } else { |
| 22780 CHECK(script->GetUnboundScript()->GetSourceMappingURL()->IsUndefined()); |
| 22781 } |
| 22782 } |
| 22783 |
| 22784 |
| 22785 TEST(ScriptSourceURLAndSourceMappingURL) { |
| 22786 LocalContext env; |
| 22787 v8::Isolate* isolate = env->GetIsolate(); |
| 22788 v8::HandleScope scope(isolate); |
| 22789 SourceURLHelper("function foo() {}\n" |
| 22790 "//# sourceURL=bar1.js\n", "bar1.js", NULL); |
| 22791 SourceURLHelper("function foo() {}\n" |
| 22792 "//# sourceMappingURL=bar2.js\n", NULL, "bar2.js"); |
| 22793 |
| 22794 // Both sourceURL and sourceMappingURL. |
| 22795 SourceURLHelper("function foo() {}\n" |
| 22796 "//# sourceURL=bar3.js\n" |
| 22797 "//# sourceMappingURL=bar4.js\n", "bar3.js", "bar4.js"); |
| 22798 |
| 22799 // Two source URLs; the first one is ignored. |
| 22800 SourceURLHelper("function foo() {}\n" |
| 22801 "//# sourceURL=ignoreme.js\n" |
| 22802 "//# sourceURL=bar5.js\n", "bar5.js", NULL); |
| 22803 SourceURLHelper("function foo() {}\n" |
| 22804 "//# sourceMappingURL=ignoreme.js\n" |
| 22805 "//# sourceMappingURL=bar6.js\n", NULL, "bar6.js"); |
| 22806 |
| 22807 // SourceURL or sourceMappingURL in the middle of the script. |
| 22808 SourceURLHelper("function foo() {}\n" |
| 22809 "//# sourceURL=bar7.js\n" |
| 22810 "function baz() {}\n", "bar7.js", NULL); |
| 22811 SourceURLHelper("function foo() {}\n" |
| 22812 "//# sourceMappingURL=bar8.js\n" |
| 22813 "function baz() {}\n", NULL, "bar8.js"); |
| 22814 |
| 22815 // Too much whitespace. |
| 22816 SourceURLHelper("function foo() {}\n" |
| 22817 "//# sourceURL=bar9.js\n" |
| 22818 "//# sourceMappingURL=bar10.js\n", NULL, NULL); |
| 22819 SourceURLHelper("function foo() {}\n" |
| 22820 "//# sourceURL =bar11.js\n" |
| 22821 "//# sourceMappingURL =bar12.js\n", NULL, NULL); |
| 22822 |
| 22823 // Disallowed characters in value. |
| 22824 SourceURLHelper("function foo() {}\n" |
| 22825 "//# sourceURL=bar13 .js \n" |
| 22826 "//# sourceMappingURL=bar14 .js \n", |
| 22827 NULL, NULL); |
| 22828 SourceURLHelper("function foo() {}\n" |
| 22829 "//# sourceURL=bar15\t.js \n" |
| 22830 "//# sourceMappingURL=bar16\t.js \n", |
| 22831 NULL, NULL); |
| 22832 SourceURLHelper("function foo() {}\n" |
| 22833 "//# sourceURL=bar17'.js \n" |
| 22834 "//# sourceMappingURL=bar18'.js \n", |
| 22835 NULL, NULL); |
| 22836 SourceURLHelper("function foo() {}\n" |
| 22837 "//# sourceURL=bar19\".js \n" |
| 22838 "//# sourceMappingURL=bar20\".js \n", |
| 22839 NULL, NULL); |
| 22840 |
| 22841 // Not too much whitespace. |
| 22842 SourceURLHelper("function foo() {}\n" |
| 22843 "//# sourceURL= bar21.js \n" |
| 22844 "//# sourceMappingURL= bar22.js \n", "bar21.js", "bar22.js"); |
| 22845 } |
OLD | NEW |