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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 namespace { | 54 namespace { |
55 | 55 |
56 | 56 |
57 class ScopedLoggerInitializer { | 57 class ScopedLoggerInitializer { |
58 public: | 58 public: |
59 explicit ScopedLoggerInitializer(bool prof_lazy) | 59 explicit ScopedLoggerInitializer(bool prof_lazy) |
60 : saved_log_(i::FLAG_log), | 60 : saved_log_(i::FLAG_log), |
61 saved_prof_lazy_(i::FLAG_prof_lazy), | 61 saved_prof_lazy_(i::FLAG_prof_lazy), |
62 saved_prof_(i::FLAG_prof), | 62 saved_prof_(i::FLAG_prof), |
63 saved_prof_auto_(i::FLAG_prof_auto), | |
64 temp_file_(NULL), | 63 temp_file_(NULL), |
65 // Need to run this prior to creating the scope. | 64 // Need to run this prior to creating the scope. |
66 trick_to_run_init_flags_(init_flags_(prof_lazy)), | 65 trick_to_run_init_flags_(init_flags_(prof_lazy)), |
67 scope_(v8::Isolate::GetCurrent()), | 66 scope_(v8::Isolate::GetCurrent()), |
68 env_(v8::Context::New(v8::Isolate::GetCurrent())), | 67 env_(v8::Context::New(v8::Isolate::GetCurrent())), |
69 logger_(i::Isolate::Current()->logger()) { | 68 logger_(i::Isolate::Current()->logger()) { |
70 env_->Enter(); | 69 env_->Enter(); |
71 } | 70 } |
72 | 71 |
73 ~ScopedLoggerInitializer() { | 72 ~ScopedLoggerInitializer() { |
74 env_->Exit(); | 73 env_->Exit(); |
75 logger_->TearDown(); | 74 logger_->TearDown(); |
76 if (temp_file_ != NULL) fclose(temp_file_); | 75 if (temp_file_ != NULL) fclose(temp_file_); |
77 i::FLAG_prof_lazy = saved_prof_lazy_; | 76 i::FLAG_prof_lazy = saved_prof_lazy_; |
78 i::FLAG_prof = saved_prof_; | 77 i::FLAG_prof = saved_prof_; |
79 i::FLAG_prof_auto = saved_prof_auto_; | |
80 i::FLAG_log = saved_log_; | 78 i::FLAG_log = saved_log_; |
81 } | 79 } |
82 | 80 |
83 v8::Handle<v8::Context>& env() { return env_; } | 81 v8::Handle<v8::Context>& env() { return env_; } |
84 | 82 |
85 Logger* logger() { return logger_; } | 83 Logger* logger() { return logger_; } |
86 | 84 |
87 FILE* StopLoggingGetTempFile() { | 85 FILE* StopLoggingGetTempFile() { |
88 temp_file_ = logger_->TearDown(); | 86 temp_file_ = logger_->TearDown(); |
89 CHECK_NE(NULL, temp_file_); | 87 CHECK_NE(NULL, temp_file_); |
90 fflush(temp_file_); | 88 fflush(temp_file_); |
91 rewind(temp_file_); | 89 rewind(temp_file_); |
92 return temp_file_; | 90 return temp_file_; |
93 } | 91 } |
94 | 92 |
95 private: | 93 private: |
96 static bool init_flags_(bool prof_lazy) { | 94 static bool init_flags_(bool prof_lazy) { |
97 i::FLAG_log = true; | 95 i::FLAG_log = true; |
98 i::FLAG_prof = true; | 96 i::FLAG_prof = true; |
99 i::FLAG_prof_lazy = prof_lazy; | 97 i::FLAG_prof_lazy = prof_lazy; |
100 i::FLAG_prof_auto = false; | |
101 i::FLAG_logfile = i::Log::kLogToTemporaryFile; | 98 i::FLAG_logfile = i::Log::kLogToTemporaryFile; |
102 return prof_lazy; | 99 return prof_lazy; |
103 } | 100 } |
104 | 101 |
105 const bool saved_log_; | 102 const bool saved_log_; |
106 const bool saved_prof_lazy_; | 103 const bool saved_prof_lazy_; |
107 const bool saved_prof_; | 104 const bool saved_prof_; |
108 const bool saved_prof_auto_; | |
109 FILE* temp_file_; | 105 FILE* temp_file_; |
110 const bool trick_to_run_init_flags_; | 106 const bool trick_to_run_init_flags_; |
111 v8::HandleScope scope_; | 107 v8::HandleScope scope_; |
112 v8::Handle<v8::Context> env_; | 108 v8::Handle<v8::Context> env_; |
113 Logger* logger_; | 109 Logger* logger_; |
114 | 110 |
115 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); | 111 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); |
116 }; | 112 }; |
117 | 113 |
118 } // namespace | 114 } // namespace |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 v8::Local<v8::String> s = result->ToString(); | 559 v8::Local<v8::String> s = result->ToString(); |
564 i::ScopedVector<char> data(s->Utf8Length() + 1); | 560 i::ScopedVector<char> data(s->Utf8Length() + 1); |
565 CHECK_NE(NULL, data.start()); | 561 CHECK_NE(NULL, data.start()); |
566 s->WriteUtf8(data.start()); | 562 s->WriteUtf8(data.start()); |
567 printf("%s\n", data.start()); | 563 printf("%s\n", data.start()); |
568 // Make sure that our output is written prior crash due to CHECK failure. | 564 // Make sure that our output is written prior crash due to CHECK failure. |
569 fflush(stdout); | 565 fflush(stdout); |
570 CHECK(false); | 566 CHECK(false); |
571 } | 567 } |
572 } | 568 } |
OLD | NEW |