Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: test/cctest/test-log.cc

Issue 269003: Fix a crash in Logger::LogCompiledFunctions due to a presence of scripts with disposed source. (Closed)
Patch Set: Fixed comments Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // 2 //
3 // Tests of logging functions from log.h 3 // Tests of logging functions from log.h
4 4
5 #ifdef ENABLE_LOGGING_AND_PROFILING 5 #ifdef ENABLE_LOGGING_AND_PROFILING
6 6
7 #ifdef __linux__ 7 #ifdef __linux__
8 #include <math.h> 8 #include <math.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <signal.h> 10 #include <signal.h>
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 423
424 jsThread.Stop(); 424 jsThread.Stop();
425 nonJsThread.Stop(); 425 nonJsThread.Stop();
426 jsThread.Join(); 426 jsThread.Join();
427 nonJsThread.Join(); 427 nonJsThread.Join();
428 } 428 }
429 429
430 #endif // __linux__ 430 #endif // __linux__
431 431
432 432
433 // Test for issue http://crbug.com/23768 in Chromium.
434 // Heap can contain scripts with already disposed external sources.
435 // We need to verify that LogCompiledFunctions doesn't crash on them.
436 namespace {
437
438 class SimpleExternalString : public v8::String::ExternalStringResource {
439 public:
440 explicit SimpleExternalString(const char* source)
441 : utf_source_(strlen(source)) {
442 for (int i = 0; i < utf_source_.length(); ++i)
443 utf_source_[i] = source[i];
444 }
445 virtual ~SimpleExternalString() {}
446 virtual size_t length() const { return utf_source_.length(); }
447 virtual const uint16_t* data() const { return utf_source_.start(); }
448 private:
449 i::ScopedVector<uint16_t> utf_source_;
450 };
451
452 } // namespace
453
454 TEST(Issue23768) {
455 v8::HandleScope scope;
456 v8::Handle<v8::Context> env = v8::Context::New();
457 env->Enter();
458
459 SimpleExternalString source_ext_str("(function ext() {})();");
460 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str);
461 // Script needs to have a name in order to trigger InitLineEnds execution.
462 v8::Handle<v8::String> origin = v8::String::New("issue-23768-test");
463 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin);
464 CHECK(!evil_script.IsEmpty());
465 CHECK(!evil_script->Run().IsEmpty());
466 i::Handle<i::ExternalTwoByteString> i_source(
467 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)));
468 // This situation can happen if source was an external string disposed
469 // by its owner.
470 i_source->set_resource(NULL);
471
472 // Must not crash.
473 i::Logger::LogCompiledFunctions();
474 }
475
476
433 static inline bool IsStringEqualTo(const char* r, const char* s) { 477 static inline bool IsStringEqualTo(const char* r, const char* s) {
434 return strncmp(r, s, strlen(r)) == 0; 478 return strncmp(r, s, strlen(r)) == 0;
435 } 479 }
436 480
437 481
438 static bool Consume(const char* str, char** buf) { 482 static bool Consume(const char* str, char** buf) {
439 if (IsStringEqualTo(str, *buf)) { 483 if (IsStringEqualTo(str, *buf)) {
440 *buf += strlen(str); 484 *buf += strlen(str);
441 return true; 485 return true;
442 } 486 }
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 // Make sure that all log data is written prior crash due to CHECK failure. 933 // Make sure that all log data is written prior crash due to CHECK failure.
890 fflush(stdout); 934 fflush(stdout);
891 CHECK(results_equal); 935 CHECK(results_equal);
892 936
893 env->Exit(); 937 env->Exit();
894 Logger::TearDown(); 938 Logger::TearDown();
895 i::FLAG_always_compact = saved_always_compact; 939 i::FLAG_always_compact = saved_always_compact;
896 } 940 }
897 941
898 #endif // ENABLE_LOGGING_AND_PROFILING 942 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698