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 22788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22799 call_eval_context = v8::Context::New(isolate); | 22799 call_eval_context = v8::Context::New(isolate); |
22800 v8::Context::Scope scope(call_eval_context); | 22800 v8::Context::Scope scope(call_eval_context); |
22801 call_eval_bound_function = | 22801 call_eval_bound_function = |
22802 Local<Function>::Cast(CompileRun("eval.bind(this, '1')")); | 22802 Local<Function>::Cast(CompileRun("eval.bind(this, '1')")); |
22803 } | 22803 } |
22804 env->Global()->Set(v8_str("CallEval"), | 22804 env->Global()->Set(v8_str("CallEval"), |
22805 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction()); | 22805 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction()); |
22806 Local<Value> result = CompileRun("CallEval();"); | 22806 Local<Value> result = CompileRun("CallEval();"); |
22807 CHECK_EQ(result, v8::Integer::New(isolate, 1)); | 22807 CHECK_EQ(result, v8::Integer::New(isolate, 1)); |
22808 } | 22808 } |
| 22809 |
| 22810 |
| 22811 void SourceURLHelper(const char* source, const char* expected_source_url, |
| 22812 const char* expected_source_mapping_url) { |
| 22813 Local<Script> script = v8_compile(source); |
| 22814 if (expected_source_url != NULL) { |
| 22815 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); |
| 22816 CHECK_EQ(expected_source_url, *url); |
| 22817 } else { |
| 22818 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); |
| 22819 } |
| 22820 if (expected_source_mapping_url != NULL) { |
| 22821 v8::String::Utf8Value url( |
| 22822 script->GetUnboundScript()->GetSourceMappingURL()); |
| 22823 CHECK_EQ(expected_source_mapping_url, *url); |
| 22824 } else { |
| 22825 CHECK(script->GetUnboundScript()->GetSourceMappingURL()->IsUndefined()); |
| 22826 } |
| 22827 } |
| 22828 |
| 22829 |
| 22830 TEST(ScriptSourceURLAndSourceMappingURL) { |
| 22831 LocalContext env; |
| 22832 v8::Isolate* isolate = env->GetIsolate(); |
| 22833 v8::HandleScope scope(isolate); |
| 22834 SourceURLHelper("function foo() {}\n" |
| 22835 "//# sourceURL=bar1.js\n", "bar1.js", NULL); |
| 22836 SourceURLHelper("function foo() {}\n" |
| 22837 "//# sourceMappingURL=bar2.js\n", NULL, "bar2.js"); |
| 22838 |
| 22839 // Both sourceURL and sourceMappingURL. |
| 22840 SourceURLHelper("function foo() {}\n" |
| 22841 "//# sourceURL=bar3.js\n" |
| 22842 "//# sourceMappingURL=bar4.js\n", "bar3.js", "bar4.js"); |
| 22843 |
| 22844 // Two source URLs; the first one is ignored. |
| 22845 SourceURLHelper("function foo() {}\n" |
| 22846 "//# sourceURL=ignoreme.js\n" |
| 22847 "//# sourceURL=bar5.js\n", "bar5.js", NULL); |
| 22848 SourceURLHelper("function foo() {}\n" |
| 22849 "//# sourceMappingURL=ignoreme.js\n" |
| 22850 "//# sourceMappingURL=bar6.js\n", NULL, "bar6.js"); |
| 22851 |
| 22852 // SourceURL or sourceMappingURL in the middle of the script. |
| 22853 SourceURLHelper("function foo() {}\n" |
| 22854 "//# sourceURL=bar7.js\n" |
| 22855 "function baz() {}\n", "bar7.js", NULL); |
| 22856 SourceURLHelper("function foo() {}\n" |
| 22857 "//# sourceMappingURL=bar8.js\n" |
| 22858 "function baz() {}\n", NULL, "bar8.js"); |
| 22859 |
| 22860 // Too much whitespace. |
| 22861 SourceURLHelper("function foo() {}\n" |
| 22862 "//# sourceURL=bar9.js\n" |
| 22863 "//# sourceMappingURL=bar10.js\n", NULL, NULL); |
| 22864 SourceURLHelper("function foo() {}\n" |
| 22865 "//# sourceURL =bar11.js\n" |
| 22866 "//# sourceMappingURL =bar12.js\n", NULL, NULL); |
| 22867 |
| 22868 // Disallowed characters in value. |
| 22869 SourceURLHelper("function foo() {}\n" |
| 22870 "//# sourceURL=bar13 .js \n" |
| 22871 "//# sourceMappingURL=bar14 .js \n", |
| 22872 NULL, NULL); |
| 22873 SourceURLHelper("function foo() {}\n" |
| 22874 "//# sourceURL=bar15\t.js \n" |
| 22875 "//# sourceMappingURL=bar16\t.js \n", |
| 22876 NULL, NULL); |
| 22877 SourceURLHelper("function foo() {}\n" |
| 22878 "//# sourceURL=bar17'.js \n" |
| 22879 "//# sourceMappingURL=bar18'.js \n", |
| 22880 NULL, NULL); |
| 22881 SourceURLHelper("function foo() {}\n" |
| 22882 "//# sourceURL=bar19\".js \n" |
| 22883 "//# sourceMappingURL=bar20\".js \n", |
| 22884 NULL, NULL); |
| 22885 |
| 22886 // Not too much whitespace. |
| 22887 SourceURLHelper("function foo() {}\n" |
| 22888 "//# sourceURL= bar21.js \n" |
| 22889 "//# sourceMappingURL= bar22.js \n", "bar21.js", "bar22.js"); |
| 22890 } |
OLD | NEW |