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 5302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5313 "function f() {" | 5313 "function f() {" |
5314 " return f();" | 5314 " return f();" |
5315 "}" | 5315 "}" |
5316 "" | 5316 "" |
5317 "f();")); | 5317 "f();")); |
5318 v8::Handle<v8::Value> result = script->Run(); | 5318 v8::Handle<v8::Value> result = script->Run(); |
5319 CHECK(result.IsEmpty()); | 5319 CHECK(result.IsEmpty()); |
5320 } | 5320 } |
5321 | 5321 |
5322 | 5322 |
| 5323 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, |
| 5324 char* resource_name, |
| 5325 int line_offset) { |
| 5326 v8::HandleScope scope; |
| 5327 v8::TryCatch try_catch; |
| 5328 v8::Handle<v8::Value> result = script->Run(); |
| 5329 CHECK(result.IsEmpty()); |
| 5330 CHECK(try_catch.HasCaught()); |
| 5331 v8::Handle<v8::Message> message = try_catch.Message(); |
| 5332 CHECK(!message.IsEmpty()); |
| 5333 CHECK_EQ(10 + line_offset, message->GetLineNumber()); |
| 5334 CHECK_EQ(91, message->GetStartPosition()); |
| 5335 CHECK_EQ(92, message->GetEndPosition()); |
| 5336 CHECK_EQ(2, message->GetStartColumn()); |
| 5337 CHECK_EQ(3, message->GetEndColumn()); |
| 5338 v8::String::AsciiValue line(message->GetSourceLine()); |
| 5339 CHECK_EQ(" throw 'nirk';", *line); |
| 5340 v8::String::AsciiValue name(message->GetScriptResourceName()); |
| 5341 CHECK_EQ(resource_name, *name); |
| 5342 } |
| 5343 |
| 5344 |
5323 THREADED_TEST(TryCatchSourceInfo) { | 5345 THREADED_TEST(TryCatchSourceInfo) { |
5324 v8::HandleScope scope; | 5346 v8::HandleScope scope; |
5325 LocalContext context; | 5347 LocalContext context; |
5326 v8::Handle<v8::String> source = v8::String::New( | 5348 v8::Handle<v8::String> source = v8::String::New( |
5327 "function Foo() {\n" | 5349 "function Foo() {\n" |
5328 " return Bar();\n" | 5350 " return Bar();\n" |
5329 "}\n" | 5351 "}\n" |
5330 "\n" | 5352 "\n" |
5331 "function Bar() {\n" | 5353 "function Bar() {\n" |
5332 " return Baz();\n" | 5354 " return Baz();\n" |
5333 "}\n" | 5355 "}\n" |
5334 "\n" | 5356 "\n" |
5335 "function Baz() {\n" | 5357 "function Baz() {\n" |
5336 " throw 'nirk';\n" | 5358 " throw 'nirk';\n" |
5337 "}\n" | 5359 "}\n" |
5338 "\n" | 5360 "\n" |
5339 "Foo();\n"); | 5361 "Foo();\n"); |
5340 v8::Handle<v8::Script> script = | 5362 |
5341 v8::Script::Compile(source, v8::String::New("test.js")); | 5363 char* resource_name; |
5342 v8::TryCatch try_catch; | 5364 v8::Handle<v8::Script> script; |
5343 v8::Handle<v8::Value> result = script->Run(); | 5365 resource_name = "test.js"; |
5344 CHECK(result.IsEmpty()); | 5366 script = v8::Script::Compile(source, v8::String::New(resource_name)); |
5345 CHECK(try_catch.HasCaught()); | 5367 CheckTryCatchSourceInfo(script, resource_name, 0); |
5346 v8::Handle<v8::Message> message = try_catch.Message(); | 5368 |
5347 CHECK(!message.IsEmpty()); | 5369 resource_name = "test1.js"; |
5348 CHECK_EQ(10, message->GetLineNumber()); | 5370 v8::ScriptOrigin origin1(v8::String::New(resource_name)); |
5349 CHECK_EQ(91, message->GetStartPosition()); | 5371 script = v8::Script::Compile(source, &origin1); |
5350 CHECK_EQ(92, message->GetEndPosition()); | 5372 CheckTryCatchSourceInfo(script, resource_name, 0); |
5351 CHECK_EQ(2, message->GetStartColumn()); | 5373 |
5352 CHECK_EQ(3, message->GetEndColumn()); | 5374 resource_name = "test2.js"; |
5353 v8::String::AsciiValue line(message->GetSourceLine()); | 5375 v8::ScriptOrigin origin2(v8::String::New(resource_name), v8::Integer::New(7)); |
5354 CHECK_EQ(" throw 'nirk';", *line); | 5376 script = v8::Script::Compile(source, &origin2); |
5355 v8::String::AsciiValue name(message->GetScriptResourceName()); | 5377 CheckTryCatchSourceInfo(script, resource_name, 7); |
5356 CHECK_EQ("test.js", *name); | |
5357 } | 5378 } |
5358 | 5379 |
5359 | 5380 |
5360 THREADED_TEST(CompilationCache) { | 5381 THREADED_TEST(CompilationCache) { |
5361 v8::HandleScope scope; | 5382 v8::HandleScope scope; |
5362 LocalContext context; | 5383 LocalContext context; |
5363 v8::Handle<v8::String> source0 = v8::String::New("1234"); | 5384 v8::Handle<v8::String> source0 = v8::String::New("1234"); |
5364 v8::Handle<v8::String> source1 = v8::String::New("1234"); | 5385 v8::Handle<v8::String> source1 = v8::String::New("1234"); |
5365 v8::Handle<v8::Script> script0 = | 5386 v8::Handle<v8::Script> script0 = |
5366 v8::Script::Compile(source0, v8::String::New("test.js")); | 5387 v8::Script::Compile(source0, v8::String::New("test.js")); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5771 | 5792 |
5772 // Local context should still be live. | 5793 // Local context should still be live. |
5773 CHECK(!local_env.IsEmpty()); | 5794 CHECK(!local_env.IsEmpty()); |
5774 local_env->Enter(); | 5795 local_env->Enter(); |
5775 | 5796 |
5776 // Should complete without problems. | 5797 // Should complete without problems. |
5777 RegExpInterruptTest().RunTest(); | 5798 RegExpInterruptTest().RunTest(); |
5778 | 5799 |
5779 local_env->Exit(); | 5800 local_env->Exit(); |
5780 } | 5801 } |
OLD | NEW |