OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 4862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4873 "function Bar() {\n" | 4873 "function Bar() {\n" |
4874 " return Baz();\n" | 4874 " return Baz();\n" |
4875 "}\n" | 4875 "}\n" |
4876 "\n" | 4876 "\n" |
4877 "function Baz() {\n" | 4877 "function Baz() {\n" |
4878 " throw 'nirk';\n" | 4878 " throw 'nirk';\n" |
4879 "}\n" | 4879 "}\n" |
4880 "\n" | 4880 "\n" |
4881 "Foo();\n"); | 4881 "Foo();\n"); |
4882 v8::Handle<v8::Script> script = | 4882 v8::Handle<v8::Script> script = |
4883 v8::Script::Compile(source, v8::String::New("test.js")); | 4883 v8::Script::Compile(source, v8::String::New("test.js")); |
4884 v8::TryCatch try_catch; | 4884 v8::TryCatch try_catch; |
4885 v8::Handle<v8::Value> result = script->Run(); | 4885 v8::Handle<v8::Value> result = script->Run(); |
4886 CHECK(result.IsEmpty()); | 4886 CHECK(result.IsEmpty()); |
4887 CHECK(try_catch.HasCaught()); | 4887 CHECK(try_catch.HasCaught()); |
4888 v8::Handle<v8::Message> message = try_catch.Message(); | 4888 v8::Handle<v8::Message> message = try_catch.Message(); |
4889 CHECK(!message.IsEmpty()); | 4889 CHECK(!message.IsEmpty()); |
4890 CHECK_EQ(10, message->GetLineNumber()); | 4890 CHECK_EQ(10, message->GetLineNumber()); |
4891 CHECK_EQ(91, message->GetStartPosition()); | 4891 CHECK_EQ(91, message->GetStartPosition()); |
4892 CHECK_EQ(92, message->GetEndPosition()); | 4892 CHECK_EQ(92, message->GetEndPosition()); |
4893 CHECK_EQ(2, message->GetStartColumn()); | 4893 CHECK_EQ(2, message->GetStartColumn()); |
4894 CHECK_EQ(3, message->GetEndColumn()); | 4894 CHECK_EQ(3, message->GetEndColumn()); |
4895 v8::String::AsciiValue line(message->GetSourceLine()); | 4895 v8::String::AsciiValue line(message->GetSourceLine()); |
4896 CHECK_EQ(" throw 'nirk';", *line); | 4896 CHECK_EQ(" throw 'nirk';", *line); |
4897 v8::String::AsciiValue name(message->GetScriptResourceName()); | 4897 v8::String::AsciiValue name(message->GetScriptResourceName()); |
4898 CHECK_EQ("test.js", *name); | 4898 CHECK_EQ("test.js", *name); |
4899 } | 4899 } |
| 4900 |
| 4901 |
| 4902 THREADED_TEST(CompilationCache) { |
| 4903 v8::HandleScope scope; |
| 4904 LocalContext context; |
| 4905 v8::Handle<v8::String> source0 = v8::String::New("1234"); |
| 4906 v8::Handle<v8::String> source1 = v8::String::New("1234"); |
| 4907 v8::Handle<v8::Script> script0 = |
| 4908 v8::Script::Compile(source0, v8::String::New("test.js")); |
| 4909 v8::Handle<v8::Script> script1 = |
| 4910 v8::Script::Compile(source1, v8::String::New("test.js")); |
| 4911 v8::Handle<v8::Script> script2 = |
| 4912 v8::Script::Compile(source0); // different origin |
| 4913 CHECK_EQ(1234, script0->Run()->Int32Value()); |
| 4914 CHECK_EQ(1234, script1->Run()->Int32Value()); |
| 4915 CHECK_EQ(1234, script2->Run()->Int32Value()); |
| 4916 } |
OLD | NEW |