OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } // namespace | 300 } // namespace |
301 | 301 |
302 TEST(Issue23768) { | 302 TEST(Issue23768) { |
303 v8::HandleScope scope(CcTest::isolate()); | 303 v8::HandleScope scope(CcTest::isolate()); |
304 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); | 304 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); |
305 env->Enter(); | 305 env->Enter(); |
306 | 306 |
307 SimpleExternalString source_ext_str("(function ext() {})();"); | 307 SimpleExternalString source_ext_str("(function ext() {})();"); |
308 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); | 308 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); |
309 // Script needs to have a name in order to trigger InitLineEnds execution. | 309 // Script needs to have a name in order to trigger InitLineEnds execution. |
310 v8::Handle<v8::String> origin = v8::String::New("issue-23768-test"); | 310 v8::Handle<v8::String> origin = |
| 311 v8::String::NewFromUtf8(CcTest::isolate(), "issue-23768-test"); |
311 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin); | 312 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin); |
312 CHECK(!evil_script.IsEmpty()); | 313 CHECK(!evil_script.IsEmpty()); |
313 CHECK(!evil_script->Run().IsEmpty()); | 314 CHECK(!evil_script->Run().IsEmpty()); |
314 i::Handle<i::ExternalTwoByteString> i_source( | 315 i::Handle<i::ExternalTwoByteString> i_source( |
315 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); | 316 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); |
316 // This situation can happen if source was an external string disposed | 317 // This situation can happen if source was an external string disposed |
317 // by its owner. | 318 // by its owner. |
318 i_source->set_resource(NULL); | 319 i_source->set_resource(NULL); |
319 | 320 |
320 // Must not crash. | 321 // Must not crash. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 logger->StringEvent("test-logging-done", ""); | 445 logger->StringEvent("test-logging-done", ""); |
445 | 446 |
446 // Iterate heap to find compiled functions, will write to log. | 447 // Iterate heap to find compiled functions, will write to log. |
447 logger->LogCompiledFunctions(); | 448 logger->LogCompiledFunctions(); |
448 logger->StringEvent("test-traversal-done", ""); | 449 logger->StringEvent("test-traversal-done", ""); |
449 | 450 |
450 bool exists = false; | 451 bool exists = false; |
451 i::Vector<const char> log( | 452 i::Vector<const char> log( |
452 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); | 453 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); |
453 CHECK(exists); | 454 CHECK(exists); |
454 v8::Handle<v8::String> log_str = v8::String::New(log.start(), log.length()); | 455 v8::Handle<v8::String> log_str = v8::String::NewFromUtf8( |
| 456 CcTest::isolate(), log.start(), v8::String::kNormalString, log.length()); |
455 initialize_logger.env()->Global()->Set(v8_str("_log"), log_str); | 457 initialize_logger.env()->Global()->Set(v8_str("_log"), log_str); |
456 | 458 |
457 i::Vector<const unsigned char> source = TestSources::GetScriptsSource(); | 459 i::Vector<const unsigned char> source = TestSources::GetScriptsSource(); |
458 v8::Handle<v8::String> source_str = v8::String::New( | 460 v8::Handle<v8::String> source_str = v8::String::NewFromUtf8( |
459 reinterpret_cast<const char*>(source.start()), source.length()); | 461 CcTest::isolate(), reinterpret_cast<const char*>(source.start()), |
| 462 v8::String::kNormalString, source.length()); |
460 v8::TryCatch try_catch; | 463 v8::TryCatch try_catch; |
461 v8::Handle<v8::Script> script = v8::Script::Compile(source_str, v8_str("")); | 464 v8::Handle<v8::Script> script = v8::Script::Compile(source_str, v8_str("")); |
462 if (script.IsEmpty()) { | 465 if (script.IsEmpty()) { |
463 v8::String::Utf8Value exception(try_catch.Exception()); | 466 v8::String::Utf8Value exception(try_catch.Exception()); |
464 printf("compile: %s\n", *exception); | 467 printf("compile: %s\n", *exception); |
465 CHECK(false); | 468 CHECK(false); |
466 } | 469 } |
467 v8::Handle<v8::Value> result = script->Run(); | 470 v8::Handle<v8::Value> result = script->Run(); |
468 if (result.IsEmpty()) { | 471 if (result.IsEmpty()) { |
469 v8::String::Utf8Value exception(try_catch.Exception()); | 472 v8::String::Utf8Value exception(try_catch.Exception()); |
470 printf("run: %s\n", *exception); | 473 printf("run: %s\n", *exception); |
471 CHECK(false); | 474 CHECK(false); |
472 } | 475 } |
473 // The result either be a "true" literal or problem description. | 476 // The result either be a "true" literal or problem description. |
474 if (!result->IsTrue()) { | 477 if (!result->IsTrue()) { |
475 v8::Local<v8::String> s = result->ToString(); | 478 v8::Local<v8::String> s = result->ToString(); |
476 i::ScopedVector<char> data(s->Utf8Length() + 1); | 479 i::ScopedVector<char> data(s->Utf8Length() + 1); |
477 CHECK_NE(NULL, data.start()); | 480 CHECK_NE(NULL, data.start()); |
478 s->WriteUtf8(data.start()); | 481 s->WriteUtf8(data.start()); |
479 printf("%s\n", data.start()); | 482 printf("%s\n", data.start()); |
480 // Make sure that our output is written prior crash due to CHECK failure. | 483 // Make sure that our output is written prior crash due to CHECK failure. |
481 fflush(stdout); | 484 fflush(stdout); |
482 CHECK(false); | 485 CHECK(false); |
483 } | 486 } |
484 } | 487 } |
OLD | NEW |