| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 19 matching lines...) Expand all Loading... |
| 30 #include "api.h" | 30 #include "api.h" |
| 31 #include "bootstrapper.h" | 31 #include "bootstrapper.h" |
| 32 #include "debug.h" | 32 #include "debug.h" |
| 33 #include "execution.h" | 33 #include "execution.h" |
| 34 #include "messages.h" | 34 #include "messages.h" |
| 35 #include "platform.h" | 35 #include "platform.h" |
| 36 #include "simulator.h" | 36 #include "simulator.h" |
| 37 #include "string-stream.h" | 37 #include "string-stream.h" |
| 38 #include "vm-state-inl.h" | 38 #include "vm-state-inl.h" |
| 39 | 39 |
| 40 // TODO(isolates): move to isolate.cc. This stuff is kept here to |
| 41 // simplify merging. |
| 42 |
| 40 namespace v8 { | 43 namespace v8 { |
| 41 namespace internal { | 44 namespace internal { |
| 42 | 45 |
| 43 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 44 Semaphore* Top::runtime_profiler_semaphore_ = NULL; | |
| 45 #endif | |
| 46 ThreadLocalTop Top::thread_local_; | |
| 47 Mutex* Top::break_access_ = OS::CreateMutex(); | |
| 48 | |
| 49 NoAllocationStringAllocator* preallocated_message_space = NULL; | |
| 50 | |
| 51 bool capture_stack_trace_for_uncaught_exceptions = false; | |
| 52 int stack_trace_for_uncaught_exceptions_frame_limit = 0; | |
| 53 StackTrace::StackTraceOptions stack_trace_for_uncaught_exceptions_options = | |
| 54 StackTrace::kOverview; | |
| 55 | |
| 56 Address top_addresses[] = { | |
| 57 #define C(name) reinterpret_cast<Address>(Top::name()), | |
| 58 TOP_ADDRESS_LIST(C) | |
| 59 TOP_ADDRESS_LIST_PROF(C) | |
| 60 #undef C | |
| 61 NULL | |
| 62 }; | |
| 63 | |
| 64 | |
| 65 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { | 46 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { |
| 66 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); | 47 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); |
| 67 } | 48 } |
| 68 | 49 |
| 69 | 50 |
| 70 void ThreadLocalTop::Initialize() { | 51 void ThreadLocalTop::Initialize() { |
| 71 c_entry_fp_ = 0; | 52 c_entry_fp_ = 0; |
| 72 handler_ = 0; | 53 handler_ = 0; |
| 73 #ifdef USE_SIMULATOR | 54 #ifdef USE_SIMULATOR |
| 74 #ifdef V8_TARGET_ARCH_ARM | 55 #ifdef V8_TARGET_ARCH_ARM |
| 75 simulator_ = Simulator::current(); | 56 simulator_ = Simulator::current(Isolate::Current()); |
| 76 #elif V8_TARGET_ARCH_MIPS | 57 #elif V8_TARGET_ARCH_MIPS |
| 77 simulator_ = assembler::mips::Simulator::current(); | 58 simulator_ = Simulator::current(Isolate::Current()); |
| 78 #endif | 59 #endif |
| 79 #endif | 60 #endif |
| 80 #ifdef ENABLE_LOGGING_AND_PROFILING | 61 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 81 js_entry_sp_ = NULL; | 62 js_entry_sp_ = NULL; |
| 82 external_callback_ = NULL; | 63 external_callback_ = NULL; |
| 83 #endif | 64 #endif |
| 84 #ifdef ENABLE_VMSTATE_TRACKING | 65 #ifdef ENABLE_VMSTATE_TRACKING |
| 85 current_vm_state_ = EXTERNAL; | 66 current_vm_state_ = EXTERNAL; |
| 86 runtime_profiler_state_ = Top::PROF_NOT_IN_JS; | |
| 87 #endif | 67 #endif |
| 88 try_catch_handler_address_ = NULL; | 68 try_catch_handler_address_ = NULL; |
| 89 context_ = NULL; | 69 context_ = NULL; |
| 90 int id = ThreadManager::CurrentId(); | 70 int id = Isolate::Current()->thread_manager()->CurrentId(); |
| 91 thread_id_ = (id == 0) ? ThreadManager::kInvalidId : id; | 71 thread_id_ = (id == 0) ? ThreadManager::kInvalidId : id; |
| 92 external_caught_exception_ = false; | 72 external_caught_exception_ = false; |
| 93 failed_access_check_callback_ = NULL; | 73 failed_access_check_callback_ = NULL; |
| 94 save_context_ = NULL; | 74 save_context_ = NULL; |
| 95 catcher_ = NULL; | 75 catcher_ = NULL; |
| 96 } | 76 } |
| 97 | 77 |
| 98 | 78 |
| 99 Address Top::get_address_from_id(Top::AddressId id) { | 79 Address Isolate::get_address_from_id(Isolate::AddressId id) { |
| 100 return top_addresses[id]; | 80 return isolate_addresses_[id]; |
| 101 } | 81 } |
| 102 | 82 |
| 103 | 83 |
| 104 char* Top::Iterate(ObjectVisitor* v, char* thread_storage) { | 84 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { |
| 105 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); | 85 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); |
| 106 Iterate(v, thread); | 86 Iterate(v, thread); |
| 107 return thread_storage + sizeof(ThreadLocalTop); | 87 return thread_storage + sizeof(ThreadLocalTop); |
| 108 } | 88 } |
| 109 | 89 |
| 110 | 90 |
| 111 void Top::IterateThread(ThreadVisitor* v) { | 91 void Isolate::IterateThread(ThreadVisitor* v) { |
| 112 v->VisitThread(&thread_local_); | 92 v->VisitThread(thread_local_top()); |
| 113 } | 93 } |
| 114 | 94 |
| 115 | 95 |
| 116 void Top::IterateThread(ThreadVisitor* v, char* t) { | 96 void Isolate::IterateThread(ThreadVisitor* v, char* t) { |
| 117 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t); | 97 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t); |
| 118 v->VisitThread(thread); | 98 v->VisitThread(thread); |
| 119 } | 99 } |
| 120 | 100 |
| 121 | 101 |
| 122 void Top::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { | 102 void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { |
| 123 // Visit the roots from the top for a given thread. | 103 // Visit the roots from the top for a given thread. |
| 124 Object *pending; | 104 Object* pending; |
| 125 // The pending exception can sometimes be a failure. We can't show | 105 // The pending exception can sometimes be a failure. We can't show |
| 126 // that to the GC, which only understands objects. | 106 // that to the GC, which only understands objects. |
| 127 if (thread->pending_exception_->ToObject(&pending)) { | 107 if (thread->pending_exception_->ToObject(&pending)) { |
| 128 v->VisitPointer(&pending); | 108 v->VisitPointer(&pending); |
| 129 thread->pending_exception_ = pending; // In case GC updated it. | 109 thread->pending_exception_ = pending; // In case GC updated it. |
| 130 } | 110 } |
| 131 v->VisitPointer(&(thread->pending_message_obj_)); | 111 v->VisitPointer(&(thread->pending_message_obj_)); |
| 132 v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); | 112 v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); |
| 133 v->VisitPointer(BitCast<Object**>(&(thread->context_))); | 113 v->VisitPointer(BitCast<Object**>(&(thread->context_))); |
| 134 Object* scheduled; | 114 Object* scheduled; |
| 135 if (thread->scheduled_exception_->ToObject(&scheduled)) { | 115 if (thread->scheduled_exception_->ToObject(&scheduled)) { |
| 136 v->VisitPointer(&scheduled); | 116 v->VisitPointer(&scheduled); |
| 137 thread->scheduled_exception_ = scheduled; | 117 thread->scheduled_exception_ = scheduled; |
| 138 } | 118 } |
| 139 | 119 |
| 140 for (v8::TryCatch* block = thread->TryCatchHandler(); | 120 for (v8::TryCatch* block = thread->TryCatchHandler(); |
| 141 block != NULL; | 121 block != NULL; |
| 142 block = TRY_CATCH_FROM_ADDRESS(block->next_)) { | 122 block = TRY_CATCH_FROM_ADDRESS(block->next_)) { |
| 143 v->VisitPointer(BitCast<Object**>(&(block->exception_))); | 123 v->VisitPointer(BitCast<Object**>(&(block->exception_))); |
| 144 v->VisitPointer(BitCast<Object**>(&(block->message_))); | 124 v->VisitPointer(BitCast<Object**>(&(block->message_))); |
| 145 } | 125 } |
| 146 | 126 |
| 147 // Iterate over pointers on native execution stack. | 127 // Iterate over pointers on native execution stack. |
| 148 for (StackFrameIterator it(thread); !it.done(); it.Advance()) { | 128 for (StackFrameIterator it(thread); !it.done(); it.Advance()) { |
| 149 it.frame()->Iterate(v); | 129 it.frame()->Iterate(v); |
| 150 } | 130 } |
| 151 } | 131 } |
| 152 | 132 |
| 153 | 133 |
| 154 void Top::Iterate(ObjectVisitor* v) { | 134 void Isolate::Iterate(ObjectVisitor* v) { |
| 155 ThreadLocalTop* current_t = &thread_local_; | 135 ThreadLocalTop* current_t = thread_local_top(); |
| 156 Iterate(v, current_t); | 136 Iterate(v, current_t); |
| 157 } | 137 } |
| 158 | 138 |
| 159 | 139 |
| 160 void Top::InitializeThreadLocal() { | 140 void Isolate::RegisterTryCatchHandler(v8::TryCatch* that) { |
| 161 thread_local_.Initialize(); | |
| 162 clear_pending_exception(); | |
| 163 clear_pending_message(); | |
| 164 clear_scheduled_exception(); | |
| 165 } | |
| 166 | |
| 167 | |
| 168 // Create a dummy thread that will wait forever on a semaphore. The only | |
| 169 // purpose for this thread is to have some stack area to save essential data | |
| 170 // into for use by a stacks only core dump (aka minidump). | |
| 171 class PreallocatedMemoryThread: public Thread { | |
| 172 public: | |
| 173 PreallocatedMemoryThread() | |
| 174 : Thread("v8:PreallocMem"), | |
| 175 keep_running_(true) { | |
| 176 wait_for_ever_semaphore_ = OS::CreateSemaphore(0); | |
| 177 data_ready_semaphore_ = OS::CreateSemaphore(0); | |
| 178 } | |
| 179 | |
| 180 // When the thread starts running it will allocate a fixed number of bytes | |
| 181 // on the stack and publish the location of this memory for others to use. | |
| 182 void Run() { | |
| 183 EmbeddedVector<char, 15 * 1024> local_buffer; | |
| 184 | |
| 185 // Initialize the buffer with a known good value. | |
| 186 OS::StrNCpy(local_buffer, "Trace data was not generated.\n", | |
| 187 local_buffer.length()); | |
| 188 | |
| 189 // Publish the local buffer and signal its availability. | |
| 190 data_ = local_buffer.start(); | |
| 191 length_ = local_buffer.length(); | |
| 192 data_ready_semaphore_->Signal(); | |
| 193 | |
| 194 while (keep_running_) { | |
| 195 // This thread will wait here until the end of time. | |
| 196 wait_for_ever_semaphore_->Wait(); | |
| 197 } | |
| 198 | |
| 199 // Make sure we access the buffer after the wait to remove all possibility | |
| 200 // of it being optimized away. | |
| 201 OS::StrNCpy(local_buffer, "PreallocatedMemoryThread shutting down.\n", | |
| 202 local_buffer.length()); | |
| 203 } | |
| 204 | |
| 205 static char* data() { | |
| 206 if (data_ready_semaphore_ != NULL) { | |
| 207 // Initial access is guarded until the data has been published. | |
| 208 data_ready_semaphore_->Wait(); | |
| 209 delete data_ready_semaphore_; | |
| 210 data_ready_semaphore_ = NULL; | |
| 211 } | |
| 212 return data_; | |
| 213 } | |
| 214 | |
| 215 static unsigned length() { | |
| 216 if (data_ready_semaphore_ != NULL) { | |
| 217 // Initial access is guarded until the data has been published. | |
| 218 data_ready_semaphore_->Wait(); | |
| 219 delete data_ready_semaphore_; | |
| 220 data_ready_semaphore_ = NULL; | |
| 221 } | |
| 222 return length_; | |
| 223 } | |
| 224 | |
| 225 static void StartThread() { | |
| 226 if (the_thread_ != NULL) return; | |
| 227 | |
| 228 the_thread_ = new PreallocatedMemoryThread(); | |
| 229 the_thread_->Start(); | |
| 230 } | |
| 231 | |
| 232 // Stop the PreallocatedMemoryThread and release its resources. | |
| 233 static void StopThread() { | |
| 234 if (the_thread_ == NULL) return; | |
| 235 | |
| 236 the_thread_->keep_running_ = false; | |
| 237 wait_for_ever_semaphore_->Signal(); | |
| 238 | |
| 239 // Wait for the thread to terminate. | |
| 240 the_thread_->Join(); | |
| 241 | |
| 242 if (data_ready_semaphore_ != NULL) { | |
| 243 delete data_ready_semaphore_; | |
| 244 data_ready_semaphore_ = NULL; | |
| 245 } | |
| 246 | |
| 247 delete wait_for_ever_semaphore_; | |
| 248 wait_for_ever_semaphore_ = NULL; | |
| 249 | |
| 250 // Done with the thread entirely. | |
| 251 delete the_thread_; | |
| 252 the_thread_ = NULL; | |
| 253 } | |
| 254 | |
| 255 private: | |
| 256 // Used to make sure that the thread keeps looping even for spurious wakeups. | |
| 257 bool keep_running_; | |
| 258 | |
| 259 // The preallocated memory thread singleton. | |
| 260 static PreallocatedMemoryThread* the_thread_; | |
| 261 // This semaphore is used by the PreallocatedMemoryThread to wait for ever. | |
| 262 static Semaphore* wait_for_ever_semaphore_; | |
| 263 // Semaphore to signal that the data has been initialized. | |
| 264 static Semaphore* data_ready_semaphore_; | |
| 265 | |
| 266 // Location and size of the preallocated memory block. | |
| 267 static char* data_; | |
| 268 static unsigned length_; | |
| 269 | |
| 270 DISALLOW_COPY_AND_ASSIGN(PreallocatedMemoryThread); | |
| 271 }; | |
| 272 | |
| 273 PreallocatedMemoryThread* PreallocatedMemoryThread::the_thread_ = NULL; | |
| 274 Semaphore* PreallocatedMemoryThread::wait_for_ever_semaphore_ = NULL; | |
| 275 Semaphore* PreallocatedMemoryThread::data_ready_semaphore_ = NULL; | |
| 276 char* PreallocatedMemoryThread::data_ = NULL; | |
| 277 unsigned PreallocatedMemoryThread::length_ = 0; | |
| 278 | |
| 279 static bool initialized = false; | |
| 280 | |
| 281 void Top::Initialize() { | |
| 282 CHECK(!initialized); | |
| 283 | |
| 284 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 285 ASSERT(runtime_profiler_semaphore_ == NULL); | |
| 286 runtime_profiler_semaphore_ = OS::CreateSemaphore(0); | |
| 287 #endif | |
| 288 | |
| 289 InitializeThreadLocal(); | |
| 290 | |
| 291 // Only preallocate on the first initialization. | |
| 292 if (FLAG_preallocate_message_memory && (preallocated_message_space == NULL)) { | |
| 293 // Start the thread which will set aside some memory. | |
| 294 PreallocatedMemoryThread::StartThread(); | |
| 295 preallocated_message_space = | |
| 296 new NoAllocationStringAllocator(PreallocatedMemoryThread::data(), | |
| 297 PreallocatedMemoryThread::length()); | |
| 298 PreallocatedStorage::Init(PreallocatedMemoryThread::length() / 4); | |
| 299 } | |
| 300 initialized = true; | |
| 301 } | |
| 302 | |
| 303 | |
| 304 void Top::TearDown() { | |
| 305 if (initialized) { | |
| 306 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 307 delete runtime_profiler_semaphore_; | |
| 308 runtime_profiler_semaphore_ = NULL; | |
| 309 #endif | |
| 310 | |
| 311 // Remove the external reference to the preallocated stack memory. | |
| 312 if (preallocated_message_space != NULL) { | |
| 313 delete preallocated_message_space; | |
| 314 preallocated_message_space = NULL; | |
| 315 } | |
| 316 | |
| 317 PreallocatedMemoryThread::StopThread(); | |
| 318 initialized = false; | |
| 319 } | |
| 320 } | |
| 321 | |
| 322 | |
| 323 void Top::RegisterTryCatchHandler(v8::TryCatch* that) { | |
| 324 // The ARM simulator has a separate JS stack. We therefore register | 141 // The ARM simulator has a separate JS stack. We therefore register |
| 325 // the C++ try catch handler with the simulator and get back an | 142 // the C++ try catch handler with the simulator and get back an |
| 326 // address that can be used for comparisons with addresses into the | 143 // address that can be used for comparisons with addresses into the |
| 327 // JS stack. When running without the simulator, the address | 144 // JS stack. When running without the simulator, the address |
| 328 // returned will be the address of the C++ try catch handler itself. | 145 // returned will be the address of the C++ try catch handler itself. |
| 329 Address address = reinterpret_cast<Address>( | 146 Address address = reinterpret_cast<Address>( |
| 330 SimulatorStack::RegisterCTryCatch(reinterpret_cast<uintptr_t>(that))); | 147 SimulatorStack::RegisterCTryCatch(reinterpret_cast<uintptr_t>(that))); |
| 331 thread_local_.set_try_catch_handler_address(address); | 148 thread_local_top()->set_try_catch_handler_address(address); |
| 332 } | 149 } |
| 333 | 150 |
| 334 | 151 |
| 335 void Top::UnregisterTryCatchHandler(v8::TryCatch* that) { | 152 void Isolate::UnregisterTryCatchHandler(v8::TryCatch* that) { |
| 336 ASSERT(try_catch_handler() == that); | 153 ASSERT(thread_local_top()->TryCatchHandler() == that); |
| 337 thread_local_.set_try_catch_handler_address( | 154 thread_local_top()->set_try_catch_handler_address( |
| 338 reinterpret_cast<Address>(that->next_)); | 155 reinterpret_cast<Address>(that->next_)); |
| 339 thread_local_.catcher_ = NULL; | 156 thread_local_top()->catcher_ = NULL; |
| 340 SimulatorStack::UnregisterCTryCatch(); | 157 SimulatorStack::UnregisterCTryCatch(); |
| 341 } | 158 } |
| 342 | 159 |
| 343 | 160 |
| 344 | 161 Handle<String> Isolate::StackTraceString() { |
| 345 static int stack_trace_nesting_level = 0; | 162 if (stack_trace_nesting_level_ == 0) { |
| 346 static StringStream* incomplete_message = NULL; | 163 stack_trace_nesting_level_++; |
| 347 | |
| 348 | |
| 349 Handle<String> Top::StackTraceString() { | |
| 350 if (stack_trace_nesting_level == 0) { | |
| 351 stack_trace_nesting_level++; | |
| 352 HeapStringAllocator allocator; | 164 HeapStringAllocator allocator; |
| 353 StringStream::ClearMentionedObjectCache(); | 165 StringStream::ClearMentionedObjectCache(); |
| 354 StringStream accumulator(&allocator); | 166 StringStream accumulator(&allocator); |
| 355 incomplete_message = &accumulator; | 167 incomplete_message_ = &accumulator; |
| 356 PrintStack(&accumulator); | 168 PrintStack(&accumulator); |
| 357 Handle<String> stack_trace = accumulator.ToString(); | 169 Handle<String> stack_trace = accumulator.ToString(); |
| 358 incomplete_message = NULL; | 170 incomplete_message_ = NULL; |
| 359 stack_trace_nesting_level = 0; | 171 stack_trace_nesting_level_ = 0; |
| 360 return stack_trace; | 172 return stack_trace; |
| 361 } else if (stack_trace_nesting_level == 1) { | 173 } else if (stack_trace_nesting_level_ == 1) { |
| 362 stack_trace_nesting_level++; | 174 stack_trace_nesting_level_++; |
| 363 OS::PrintError( | 175 OS::PrintError( |
| 364 "\n\nAttempt to print stack while printing stack (double fault)\n"); | 176 "\n\nAttempt to print stack while printing stack (double fault)\n"); |
| 365 OS::PrintError( | 177 OS::PrintError( |
| 366 "If you are lucky you may find a partial stack dump on stdout.\n\n"); | 178 "If you are lucky you may find a partial stack dump on stdout.\n\n"); |
| 367 incomplete_message->OutputToStdOut(); | 179 incomplete_message_->OutputToStdOut(); |
| 368 return Factory::empty_symbol(); | 180 return factory()->empty_symbol(); |
| 369 } else { | 181 } else { |
| 370 OS::Abort(); | 182 OS::Abort(); |
| 371 // Unreachable | 183 // Unreachable |
| 372 return Factory::empty_symbol(); | 184 return factory()->empty_symbol(); |
| 373 } | 185 } |
| 374 } | 186 } |
| 375 | 187 |
| 376 | 188 |
| 377 Handle<JSArray> Top::CaptureCurrentStackTrace( | 189 Handle<JSArray> Isolate::CaptureCurrentStackTrace( |
| 378 int frame_limit, StackTrace::StackTraceOptions options) { | 190 int frame_limit, StackTrace::StackTraceOptions options) { |
| 379 // Ensure no negative values. | 191 // Ensure no negative values. |
| 380 int limit = Max(frame_limit, 0); | 192 int limit = Max(frame_limit, 0); |
| 381 Handle<JSArray> stack_trace = Factory::NewJSArray(frame_limit); | 193 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit); |
| 382 | 194 |
| 383 Handle<String> column_key = Factory::LookupAsciiSymbol("column"); | 195 Handle<String> column_key = factory()->LookupAsciiSymbol("column"); |
| 384 Handle<String> line_key = Factory::LookupAsciiSymbol("lineNumber"); | 196 Handle<String> line_key = factory()->LookupAsciiSymbol("lineNumber"); |
| 385 Handle<String> script_key = Factory::LookupAsciiSymbol("scriptName"); | 197 Handle<String> script_key = factory()->LookupAsciiSymbol("scriptName"); |
| 386 Handle<String> name_or_source_url_key = | 198 Handle<String> name_or_source_url_key = |
| 387 Factory::LookupAsciiSymbol("nameOrSourceURL"); | 199 factory()->LookupAsciiSymbol("nameOrSourceURL"); |
| 388 Handle<String> script_name_or_source_url_key = | 200 Handle<String> script_name_or_source_url_key = |
| 389 Factory::LookupAsciiSymbol("scriptNameOrSourceURL"); | 201 factory()->LookupAsciiSymbol("scriptNameOrSourceURL"); |
| 390 Handle<String> function_key = Factory::LookupAsciiSymbol("functionName"); | 202 Handle<String> function_key = factory()->LookupAsciiSymbol("functionName"); |
| 391 Handle<String> eval_key = Factory::LookupAsciiSymbol("isEval"); | 203 Handle<String> eval_key = factory()->LookupAsciiSymbol("isEval"); |
| 392 Handle<String> constructor_key = Factory::LookupAsciiSymbol("isConstructor"); | 204 Handle<String> constructor_key = |
| 205 factory()->LookupAsciiSymbol("isConstructor"); |
| 393 | 206 |
| 394 StackTraceFrameIterator it; | 207 StackTraceFrameIterator it; |
| 395 int frames_seen = 0; | 208 int frames_seen = 0; |
| 396 while (!it.done() && (frames_seen < limit)) { | 209 while (!it.done() && (frames_seen < limit)) { |
| 397 JavaScriptFrame* frame = it.frame(); | 210 JavaScriptFrame* frame = it.frame(); |
| 398 | 211 |
| 399 List<FrameSummary> frames(3); // Max 2 levels of inlining. | 212 List<FrameSummary> frames(3); // Max 2 levels of inlining. |
| 400 frame->Summarize(&frames); | 213 frame->Summarize(&frames); |
| 401 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { | 214 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { |
| 402 // Create a JSObject to hold the information for the StackFrame. | 215 // Create a JSObject to hold the information for the StackFrame. |
| 403 Handle<JSObject> stackFrame = Factory::NewJSObject(object_function()); | 216 Handle<JSObject> stackFrame = factory()->NewJSObject(object_function()); |
| 404 | 217 |
| 405 Handle<JSFunction> fun = frames[i].function(); | 218 Handle<JSFunction> fun = frames[i].function(); |
| 406 Handle<Script> script(Script::cast(fun->shared()->script())); | 219 Handle<Script> script(Script::cast(fun->shared()->script())); |
| 407 | 220 |
| 408 if (options & StackTrace::kLineNumber) { | 221 if (options & StackTrace::kLineNumber) { |
| 409 int script_line_offset = script->line_offset()->value(); | 222 int script_line_offset = script->line_offset()->value(); |
| 410 int position = frames[i].code()->SourcePosition(frames[i].pc()); | 223 int position = frames[i].code()->SourcePosition(frames[i].pc()); |
| 411 int line_number = GetScriptLineNumber(script, position); | 224 int line_number = GetScriptLineNumber(script, position); |
| 412 // line_number is already shifted by the script_line_offset. | 225 // line_number is already shifted by the script_line_offset. |
| 413 int relative_line_number = line_number - script_line_offset; | 226 int relative_line_number = line_number - script_line_offset; |
| 414 if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { | 227 if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { |
| 415 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); | 228 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
| 416 int start = (relative_line_number == 0) ? 0 : | 229 int start = (relative_line_number == 0) ? 0 : |
| 417 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; | 230 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; |
| 418 int column_offset = position - start; | 231 int column_offset = position - start; |
| 419 if (relative_line_number == 0) { | 232 if (relative_line_number == 0) { |
| 420 // For the case where the code is on the same line as the script | 233 // For the case where the code is on the same line as the script |
| 421 // tag. | 234 // tag. |
| 422 column_offset += script->column_offset()->value(); | 235 column_offset += script->column_offset()->value(); |
| 423 } | 236 } |
| 424 SetLocalPropertyNoThrow(stackFrame, column_key, | 237 SetLocalPropertyNoThrow(stackFrame, column_key, |
| 425 Handle<Smi>(Smi::FromInt(column_offset + 1))); | 238 Handle<Smi>(Smi::FromInt(column_offset + 1))); |
| 426 } | 239 } |
| 427 SetLocalPropertyNoThrow(stackFrame, line_key, | 240 SetLocalPropertyNoThrow(stackFrame, line_key, |
| 428 Handle<Smi>(Smi::FromInt(line_number + 1))); | 241 Handle<Smi>(Smi::FromInt(line_number + 1))); |
| 429 } | 242 } |
| 430 | 243 |
| 431 if (options & StackTrace::kScriptName) { | 244 if (options & StackTrace::kScriptName) { |
| 432 Handle<Object> script_name(script->name()); | 245 Handle<Object> script_name(script->name(), this); |
| 433 SetLocalPropertyNoThrow(stackFrame, script_key, script_name); | 246 SetLocalPropertyNoThrow(stackFrame, script_key, script_name); |
| 434 } | 247 } |
| 435 | 248 |
| 436 if (options & StackTrace::kScriptNameOrSourceURL) { | 249 if (options & StackTrace::kScriptNameOrSourceURL) { |
| 437 Handle<Object> script_name(script->name()); | 250 Handle<Object> script_name(script->name(), this); |
| 438 Handle<JSValue> script_wrapper = GetScriptWrapper(script); | 251 Handle<JSValue> script_wrapper = GetScriptWrapper(script); |
| 439 Handle<Object> property = GetProperty(script_wrapper, | 252 Handle<Object> property = GetProperty(script_wrapper, |
| 440 name_or_source_url_key); | 253 name_or_source_url_key); |
| 441 ASSERT(property->IsJSFunction()); | 254 ASSERT(property->IsJSFunction()); |
| 442 Handle<JSFunction> method = Handle<JSFunction>::cast(property); | 255 Handle<JSFunction> method = Handle<JSFunction>::cast(property); |
| 443 bool caught_exception; | 256 bool caught_exception; |
| 444 Handle<Object> result = Execution::TryCall(method, script_wrapper, 0, | 257 Handle<Object> result = Execution::TryCall(method, script_wrapper, 0, |
| 445 NULL, &caught_exception); | 258 NULL, &caught_exception); |
| 446 if (caught_exception) { | 259 if (caught_exception) { |
| 447 result = Factory::undefined_value(); | 260 result = factory()->undefined_value(); |
| 448 } | 261 } |
| 449 SetLocalPropertyNoThrow(stackFrame, script_name_or_source_url_key, | 262 SetLocalPropertyNoThrow(stackFrame, script_name_or_source_url_key, |
| 450 result); | 263 result); |
| 451 } | 264 } |
| 452 | 265 |
| 453 if (options & StackTrace::kFunctionName) { | 266 if (options & StackTrace::kFunctionName) { |
| 454 Handle<Object> fun_name(fun->shared()->name()); | 267 Handle<Object> fun_name(fun->shared()->name(), this); |
| 455 if (fun_name->ToBoolean()->IsFalse()) { | 268 if (fun_name->ToBoolean()->IsFalse()) { |
| 456 fun_name = Handle<Object>(fun->shared()->inferred_name()); | 269 fun_name = Handle<Object>(fun->shared()->inferred_name(), this); |
| 457 } | 270 } |
| 458 SetLocalPropertyNoThrow(stackFrame, function_key, fun_name); | 271 SetLocalPropertyNoThrow(stackFrame, function_key, fun_name); |
| 459 } | 272 } |
| 460 | 273 |
| 461 if (options & StackTrace::kIsEval) { | 274 if (options & StackTrace::kIsEval) { |
| 462 int type = Smi::cast(script->compilation_type())->value(); | 275 int type = Smi::cast(script->compilation_type())->value(); |
| 463 Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ? | 276 Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ? |
| 464 Factory::true_value() : Factory::false_value(); | 277 factory()->true_value() : factory()->false_value(); |
| 465 SetLocalPropertyNoThrow(stackFrame, eval_key, is_eval); | 278 SetLocalPropertyNoThrow(stackFrame, eval_key, is_eval); |
| 466 } | 279 } |
| 467 | 280 |
| 468 if (options & StackTrace::kIsConstructor) { | 281 if (options & StackTrace::kIsConstructor) { |
| 469 Handle<Object> is_constructor = (frames[i].is_constructor()) ? | 282 Handle<Object> is_constructor = (frames[i].is_constructor()) ? |
| 470 Factory::true_value() : Factory::false_value(); | 283 factory()->true_value() : factory()->false_value(); |
| 471 SetLocalPropertyNoThrow(stackFrame, constructor_key, is_constructor); | 284 SetLocalPropertyNoThrow(stackFrame, constructor_key, is_constructor); |
| 472 } | 285 } |
| 473 | 286 |
| 474 FixedArray::cast(stack_trace->elements())->set(frames_seen, *stackFrame); | 287 FixedArray::cast(stack_trace->elements())->set(frames_seen, *stackFrame); |
| 475 frames_seen++; | 288 frames_seen++; |
| 476 } | 289 } |
| 477 it.Advance(); | 290 it.Advance(); |
| 478 } | 291 } |
| 479 | 292 |
| 480 stack_trace->set_length(Smi::FromInt(frames_seen)); | 293 stack_trace->set_length(Smi::FromInt(frames_seen)); |
| 481 return stack_trace; | 294 return stack_trace; |
| 482 } | 295 } |
| 483 | 296 |
| 484 | 297 |
| 485 void Top::PrintStack() { | 298 void Isolate::PrintStack() { |
| 486 if (stack_trace_nesting_level == 0) { | 299 if (stack_trace_nesting_level_ == 0) { |
| 487 stack_trace_nesting_level++; | 300 stack_trace_nesting_level_++; |
| 488 | 301 |
| 489 StringAllocator* allocator; | 302 StringAllocator* allocator; |
| 490 if (preallocated_message_space == NULL) { | 303 if (preallocated_message_space_ == NULL) { |
| 491 allocator = new HeapStringAllocator(); | 304 allocator = new HeapStringAllocator(); |
| 492 } else { | 305 } else { |
| 493 allocator = preallocated_message_space; | 306 allocator = preallocated_message_space_; |
| 494 } | 307 } |
| 495 | 308 |
| 496 NativeAllocationChecker allocation_checker( | 309 NativeAllocationChecker allocation_checker( |
| 497 !FLAG_preallocate_message_memory ? | 310 !FLAG_preallocate_message_memory ? |
| 498 NativeAllocationChecker::ALLOW : | 311 NativeAllocationChecker::ALLOW : |
| 499 NativeAllocationChecker::DISALLOW); | 312 NativeAllocationChecker::DISALLOW); |
| 500 | 313 |
| 501 StringStream::ClearMentionedObjectCache(); | 314 StringStream::ClearMentionedObjectCache(); |
| 502 StringStream accumulator(allocator); | 315 StringStream accumulator(allocator); |
| 503 incomplete_message = &accumulator; | 316 incomplete_message_ = &accumulator; |
| 504 PrintStack(&accumulator); | 317 PrintStack(&accumulator); |
| 505 accumulator.OutputToStdOut(); | 318 accumulator.OutputToStdOut(); |
| 506 accumulator.Log(); | 319 accumulator.Log(); |
| 507 incomplete_message = NULL; | 320 incomplete_message_ = NULL; |
| 508 stack_trace_nesting_level = 0; | 321 stack_trace_nesting_level_ = 0; |
| 509 if (preallocated_message_space == NULL) { | 322 if (preallocated_message_space_ == NULL) { |
| 510 // Remove the HeapStringAllocator created above. | 323 // Remove the HeapStringAllocator created above. |
| 511 delete allocator; | 324 delete allocator; |
| 512 } | 325 } |
| 513 } else if (stack_trace_nesting_level == 1) { | 326 } else if (stack_trace_nesting_level_ == 1) { |
| 514 stack_trace_nesting_level++; | 327 stack_trace_nesting_level_++; |
| 515 OS::PrintError( | 328 OS::PrintError( |
| 516 "\n\nAttempt to print stack while printing stack (double fault)\n"); | 329 "\n\nAttempt to print stack while printing stack (double fault)\n"); |
| 517 OS::PrintError( | 330 OS::PrintError( |
| 518 "If you are lucky you may find a partial stack dump on stdout.\n\n"); | 331 "If you are lucky you may find a partial stack dump on stdout.\n\n"); |
| 519 incomplete_message->OutputToStdOut(); | 332 incomplete_message_->OutputToStdOut(); |
| 520 } | 333 } |
| 521 } | 334 } |
| 522 | 335 |
| 523 | 336 |
| 524 static void PrintFrames(StringStream* accumulator, | 337 static void PrintFrames(StringStream* accumulator, |
| 525 StackFrame::PrintMode mode) { | 338 StackFrame::PrintMode mode) { |
| 526 StackFrameIterator it; | 339 StackFrameIterator it; |
| 527 for (int i = 0; !it.done(); it.Advance()) { | 340 for (int i = 0; !it.done(); it.Advance()) { |
| 528 it.frame()->Print(accumulator, mode, i++); | 341 it.frame()->Print(accumulator, mode, i++); |
| 529 } | 342 } |
| 530 } | 343 } |
| 531 | 344 |
| 532 | 345 |
| 533 void Top::PrintStack(StringStream* accumulator) { | 346 void Isolate::PrintStack(StringStream* accumulator) { |
| 347 if (!IsInitialized()) { |
| 348 accumulator->Add( |
| 349 "\n==== Stack trace is not available ==========================\n\n"); |
| 350 accumulator->Add( |
| 351 "\n==== Isolate for the thread is not initialized =============\n\n"); |
| 352 return; |
| 353 } |
| 534 // The MentionedObjectCache is not GC-proof at the moment. | 354 // The MentionedObjectCache is not GC-proof at the moment. |
| 535 AssertNoAllocation nogc; | 355 AssertNoAllocation nogc; |
| 536 ASSERT(StringStream::IsMentionedObjectCacheClear()); | 356 ASSERT(StringStream::IsMentionedObjectCacheClear()); |
| 537 | 357 |
| 538 // Avoid printing anything if there are no frames. | 358 // Avoid printing anything if there are no frames. |
| 539 if (c_entry_fp(GetCurrentThread()) == 0) return; | 359 if (c_entry_fp(thread_local_top()) == 0) return; |
| 540 | 360 |
| 541 accumulator->Add( | 361 accumulator->Add( |
| 542 "\n==== Stack trace ============================================\n\n"); | 362 "\n==== Stack trace ============================================\n\n"); |
| 543 PrintFrames(accumulator, StackFrame::OVERVIEW); | 363 PrintFrames(accumulator, StackFrame::OVERVIEW); |
| 544 | 364 |
| 545 accumulator->Add( | 365 accumulator->Add( |
| 546 "\n==== Details ================================================\n\n"); | 366 "\n==== Details ================================================\n\n"); |
| 547 PrintFrames(accumulator, StackFrame::DETAILS); | 367 PrintFrames(accumulator, StackFrame::DETAILS); |
| 548 | 368 |
| 549 accumulator->PrintMentionedObjectCache(); | 369 accumulator->PrintMentionedObjectCache(); |
| 550 accumulator->Add("=====================\n\n"); | 370 accumulator->Add("=====================\n\n"); |
| 551 } | 371 } |
| 552 | 372 |
| 553 | 373 |
| 554 void Top::SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback) { | 374 void Isolate::SetFailedAccessCheckCallback( |
| 555 thread_local_.failed_access_check_callback_ = callback; | 375 v8::FailedAccessCheckCallback callback) { |
| 376 thread_local_top()->failed_access_check_callback_ = callback; |
| 556 } | 377 } |
| 557 | 378 |
| 558 | 379 |
| 559 void Top::ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type) { | 380 void Isolate::ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type) { |
| 560 if (!thread_local_.failed_access_check_callback_) return; | 381 if (!thread_local_top()->failed_access_check_callback_) return; |
| 561 | 382 |
| 562 ASSERT(receiver->IsAccessCheckNeeded()); | 383 ASSERT(receiver->IsAccessCheckNeeded()); |
| 563 ASSERT(Top::context()); | 384 ASSERT(context()); |
| 564 | 385 |
| 565 // Get the data object from access check info. | 386 // Get the data object from access check info. |
| 566 JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); | 387 JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); |
| 567 if (!constructor->shared()->IsApiFunction()) return; | 388 if (!constructor->shared()->IsApiFunction()) return; |
| 568 Object* data_obj = | 389 Object* data_obj = |
| 569 constructor->shared()->get_api_func_data()->access_check_info(); | 390 constructor->shared()->get_api_func_data()->access_check_info(); |
| 570 if (data_obj == Heap::undefined_value()) return; | 391 if (data_obj == heap_.undefined_value()) return; |
| 571 | 392 |
| 572 HandleScope scope; | 393 HandleScope scope; |
| 573 Handle<JSObject> receiver_handle(receiver); | 394 Handle<JSObject> receiver_handle(receiver); |
| 574 Handle<Object> data(AccessCheckInfo::cast(data_obj)->data()); | 395 Handle<Object> data(AccessCheckInfo::cast(data_obj)->data()); |
| 575 thread_local_.failed_access_check_callback_( | 396 thread_local_top()->failed_access_check_callback_( |
| 576 v8::Utils::ToLocal(receiver_handle), | 397 v8::Utils::ToLocal(receiver_handle), |
| 577 type, | 398 type, |
| 578 v8::Utils::ToLocal(data)); | 399 v8::Utils::ToLocal(data)); |
| 579 } | 400 } |
| 580 | 401 |
| 581 | 402 |
| 582 enum MayAccessDecision { | 403 enum MayAccessDecision { |
| 583 YES, NO, UNKNOWN | 404 YES, NO, UNKNOWN |
| 584 }; | 405 }; |
| 585 | 406 |
| 586 | 407 |
| 587 static MayAccessDecision MayAccessPreCheck(JSObject* receiver, | 408 static MayAccessDecision MayAccessPreCheck(Isolate* isolate, |
| 409 JSObject* receiver, |
| 588 v8::AccessType type) { | 410 v8::AccessType type) { |
| 589 // During bootstrapping, callback functions are not enabled yet. | 411 // During bootstrapping, callback functions are not enabled yet. |
| 590 if (Bootstrapper::IsActive()) return YES; | 412 if (isolate->bootstrapper()->IsActive()) return YES; |
| 591 | 413 |
| 592 if (receiver->IsJSGlobalProxy()) { | 414 if (receiver->IsJSGlobalProxy()) { |
| 593 Object* receiver_context = JSGlobalProxy::cast(receiver)->context(); | 415 Object* receiver_context = JSGlobalProxy::cast(receiver)->context(); |
| 594 if (!receiver_context->IsContext()) return NO; | 416 if (!receiver_context->IsContext()) return NO; |
| 595 | 417 |
| 596 // Get the global context of current top context. | 418 // Get the global context of current top context. |
| 597 // avoid using Top::global_context() because it uses Handle. | 419 // avoid using Isolate::global_context() because it uses Handle. |
| 598 Context* global_context = Top::context()->global()->global_context(); | 420 Context* global_context = isolate->context()->global()->global_context(); |
| 599 if (receiver_context == global_context) return YES; | 421 if (receiver_context == global_context) return YES; |
| 600 | 422 |
| 601 if (Context::cast(receiver_context)->security_token() == | 423 if (Context::cast(receiver_context)->security_token() == |
| 602 global_context->security_token()) | 424 global_context->security_token()) |
| 603 return YES; | 425 return YES; |
| 604 } | 426 } |
| 605 | 427 |
| 606 return UNKNOWN; | 428 return UNKNOWN; |
| 607 } | 429 } |
| 608 | 430 |
| 609 | 431 |
| 610 bool Top::MayNamedAccess(JSObject* receiver, Object* key, v8::AccessType type) { | 432 bool Isolate::MayNamedAccess(JSObject* receiver, Object* key, |
| 433 v8::AccessType type) { |
| 611 ASSERT(receiver->IsAccessCheckNeeded()); | 434 ASSERT(receiver->IsAccessCheckNeeded()); |
| 612 | 435 |
| 613 // The callers of this method are not expecting a GC. | 436 // The callers of this method are not expecting a GC. |
| 614 AssertNoAllocation no_gc; | 437 AssertNoAllocation no_gc; |
| 615 | 438 |
| 616 // Skip checks for hidden properties access. Note, we do not | 439 // Skip checks for hidden properties access. Note, we do not |
| 617 // require existence of a context in this case. | 440 // require existence of a context in this case. |
| 618 if (key == Heap::hidden_symbol()) return true; | 441 if (key == heap_.hidden_symbol()) return true; |
| 619 | 442 |
| 620 // Check for compatibility between the security tokens in the | 443 // Check for compatibility between the security tokens in the |
| 621 // current lexical context and the accessed object. | 444 // current lexical context and the accessed object. |
| 622 ASSERT(Top::context()); | 445 ASSERT(context()); |
| 623 | 446 |
| 624 MayAccessDecision decision = MayAccessPreCheck(receiver, type); | 447 MayAccessDecision decision = MayAccessPreCheck(this, receiver, type); |
| 625 if (decision != UNKNOWN) return decision == YES; | 448 if (decision != UNKNOWN) return decision == YES; |
| 626 | 449 |
| 627 // Get named access check callback | 450 // Get named access check callback |
| 628 JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); | 451 JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); |
| 629 if (!constructor->shared()->IsApiFunction()) return false; | 452 if (!constructor->shared()->IsApiFunction()) return false; |
| 630 | 453 |
| 631 Object* data_obj = | 454 Object* data_obj = |
| 632 constructor->shared()->get_api_func_data()->access_check_info(); | 455 constructor->shared()->get_api_func_data()->access_check_info(); |
| 633 if (data_obj == Heap::undefined_value()) return false; | 456 if (data_obj == heap_.undefined_value()) return false; |
| 634 | 457 |
| 635 Object* fun_obj = AccessCheckInfo::cast(data_obj)->named_callback(); | 458 Object* fun_obj = AccessCheckInfo::cast(data_obj)->named_callback(); |
| 636 v8::NamedSecurityCallback callback = | 459 v8::NamedSecurityCallback callback = |
| 637 v8::ToCData<v8::NamedSecurityCallback>(fun_obj); | 460 v8::ToCData<v8::NamedSecurityCallback>(fun_obj); |
| 638 | 461 |
| 639 if (!callback) return false; | 462 if (!callback) return false; |
| 640 | 463 |
| 641 HandleScope scope; | 464 HandleScope scope(this); |
| 642 Handle<JSObject> receiver_handle(receiver); | 465 Handle<JSObject> receiver_handle(receiver, this); |
| 643 Handle<Object> key_handle(key); | 466 Handle<Object> key_handle(key, this); |
| 644 Handle<Object> data(AccessCheckInfo::cast(data_obj)->data()); | 467 Handle<Object> data(AccessCheckInfo::cast(data_obj)->data(), this); |
| 645 LOG(ApiNamedSecurityCheck(key)); | 468 LOG(this, ApiNamedSecurityCheck(key)); |
| 646 bool result = false; | 469 bool result = false; |
| 647 { | 470 { |
| 648 // Leaving JavaScript. | 471 // Leaving JavaScript. |
| 649 VMState state(EXTERNAL); | 472 VMState state(this, EXTERNAL); |
| 650 result = callback(v8::Utils::ToLocal(receiver_handle), | 473 result = callback(v8::Utils::ToLocal(receiver_handle), |
| 651 v8::Utils::ToLocal(key_handle), | 474 v8::Utils::ToLocal(key_handle), |
| 652 type, | 475 type, |
| 653 v8::Utils::ToLocal(data)); | 476 v8::Utils::ToLocal(data)); |
| 654 } | 477 } |
| 655 return result; | 478 return result; |
| 656 } | 479 } |
| 657 | 480 |
| 658 | 481 |
| 659 bool Top::MayIndexedAccess(JSObject* receiver, | 482 bool Isolate::MayIndexedAccess(JSObject* receiver, |
| 660 uint32_t index, | 483 uint32_t index, |
| 661 v8::AccessType type) { | 484 v8::AccessType type) { |
| 662 ASSERT(receiver->IsAccessCheckNeeded()); | 485 ASSERT(receiver->IsAccessCheckNeeded()); |
| 663 // Check for compatibility between the security tokens in the | 486 // Check for compatibility between the security tokens in the |
| 664 // current lexical context and the accessed object. | 487 // current lexical context and the accessed object. |
| 665 ASSERT(Top::context()); | 488 ASSERT(context()); |
| 666 // The callers of this method are not expecting a GC. | |
| 667 AssertNoAllocation no_gc; | |
| 668 | 489 |
| 669 MayAccessDecision decision = MayAccessPreCheck(receiver, type); | 490 MayAccessDecision decision = MayAccessPreCheck(this, receiver, type); |
| 670 if (decision != UNKNOWN) return decision == YES; | 491 if (decision != UNKNOWN) return decision == YES; |
| 671 | 492 |
| 672 // Get indexed access check callback | 493 // Get indexed access check callback |
| 673 JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); | 494 JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); |
| 674 if (!constructor->shared()->IsApiFunction()) return false; | 495 if (!constructor->shared()->IsApiFunction()) return false; |
| 675 | 496 |
| 676 Object* data_obj = | 497 Object* data_obj = |
| 677 constructor->shared()->get_api_func_data()->access_check_info(); | 498 constructor->shared()->get_api_func_data()->access_check_info(); |
| 678 if (data_obj == Heap::undefined_value()) return false; | 499 if (data_obj == heap_.undefined_value()) return false; |
| 679 | 500 |
| 680 Object* fun_obj = AccessCheckInfo::cast(data_obj)->indexed_callback(); | 501 Object* fun_obj = AccessCheckInfo::cast(data_obj)->indexed_callback(); |
| 681 v8::IndexedSecurityCallback callback = | 502 v8::IndexedSecurityCallback callback = |
| 682 v8::ToCData<v8::IndexedSecurityCallback>(fun_obj); | 503 v8::ToCData<v8::IndexedSecurityCallback>(fun_obj); |
| 683 | 504 |
| 684 if (!callback) return false; | 505 if (!callback) return false; |
| 685 | 506 |
| 686 HandleScope scope; | 507 HandleScope scope(this); |
| 687 Handle<JSObject> receiver_handle(receiver); | 508 Handle<JSObject> receiver_handle(receiver, this); |
| 688 Handle<Object> data(AccessCheckInfo::cast(data_obj)->data()); | 509 Handle<Object> data(AccessCheckInfo::cast(data_obj)->data(), this); |
| 689 LOG(ApiIndexedSecurityCheck(index)); | 510 LOG(this, ApiIndexedSecurityCheck(index)); |
| 690 bool result = false; | 511 bool result = false; |
| 691 { | 512 { |
| 692 // Leaving JavaScript. | 513 // Leaving JavaScript. |
| 693 VMState state(EXTERNAL); | 514 VMState state(this, EXTERNAL); |
| 694 result = callback(v8::Utils::ToLocal(receiver_handle), | 515 result = callback(v8::Utils::ToLocal(receiver_handle), |
| 695 index, | 516 index, |
| 696 type, | 517 type, |
| 697 v8::Utils::ToLocal(data)); | 518 v8::Utils::ToLocal(data)); |
| 698 } | 519 } |
| 699 return result; | 520 return result; |
| 700 } | 521 } |
| 701 | 522 |
| 702 | 523 |
| 703 const char* Top::kStackOverflowMessage = | 524 const char* const Isolate::kStackOverflowMessage = |
| 704 "Uncaught RangeError: Maximum call stack size exceeded"; | 525 "Uncaught RangeError: Maximum call stack size exceeded"; |
| 705 | 526 |
| 706 | 527 |
| 707 Failure* Top::StackOverflow() { | 528 Failure* Isolate::StackOverflow() { |
| 708 HandleScope scope; | 529 HandleScope scope; |
| 709 Handle<String> key = Factory::stack_overflow_symbol(); | 530 Handle<String> key = factory()->stack_overflow_symbol(); |
| 710 Handle<JSObject> boilerplate = | 531 Handle<JSObject> boilerplate = |
| 711 Handle<JSObject>::cast(GetProperty(Top::builtins(), key)); | 532 Handle<JSObject>::cast(GetProperty(js_builtins_object(), key)); |
| 712 Handle<Object> exception = Copy(boilerplate); | 533 Handle<Object> exception = Copy(boilerplate); |
| 713 // TODO(1240995): To avoid having to call JavaScript code to compute | 534 // TODO(1240995): To avoid having to call JavaScript code to compute |
| 714 // the message for stack overflow exceptions which is very likely to | 535 // the message for stack overflow exceptions which is very likely to |
| 715 // double fault with another stack overflow exception, we use a | 536 // double fault with another stack overflow exception, we use a |
| 716 // precomputed message. | 537 // precomputed message. |
| 717 DoThrow(*exception, NULL, kStackOverflowMessage); | 538 DoThrow(*exception, NULL, kStackOverflowMessage); |
| 718 return Failure::Exception(); | 539 return Failure::Exception(); |
| 719 } | 540 } |
| 720 | 541 |
| 721 | 542 |
| 722 Failure* Top::TerminateExecution() { | 543 Failure* Isolate::TerminateExecution() { |
| 723 DoThrow(Heap::termination_exception(), NULL, NULL); | 544 DoThrow(heap_.termination_exception(), NULL, NULL); |
| 724 return Failure::Exception(); | 545 return Failure::Exception(); |
| 725 } | 546 } |
| 726 | 547 |
| 727 | 548 |
| 728 Failure* Top::Throw(Object* exception, MessageLocation* location) { | 549 Failure* Isolate::Throw(Object* exception, MessageLocation* location) { |
| 729 DoThrow(exception, location, NULL); | 550 DoThrow(exception, location, NULL); |
| 730 return Failure::Exception(); | 551 return Failure::Exception(); |
| 731 } | 552 } |
| 732 | 553 |
| 733 | 554 |
| 734 Failure* Top::ReThrow(MaybeObject* exception, MessageLocation* location) { | 555 Failure* Isolate::ReThrow(MaybeObject* exception, MessageLocation* location) { |
| 735 bool can_be_caught_externally = false; | 556 bool can_be_caught_externally = false; |
| 736 ShouldReportException(&can_be_caught_externally, | 557 ShouldReportException(&can_be_caught_externally, |
| 737 is_catchable_by_javascript(exception)); | 558 is_catchable_by_javascript(exception)); |
| 738 thread_local_.catcher_ = can_be_caught_externally ? | 559 thread_local_top()->catcher_ = can_be_caught_externally ? |
| 739 try_catch_handler() : NULL; | 560 try_catch_handler() : NULL; |
| 740 | 561 |
| 741 // Set the exception being re-thrown. | 562 // Set the exception being re-thrown. |
| 742 set_pending_exception(exception); | 563 set_pending_exception(exception); |
| 743 return Failure::Exception(); | 564 return Failure::Exception(); |
| 744 } | 565 } |
| 745 | 566 |
| 746 | 567 |
| 747 Failure* Top::ThrowIllegalOperation() { | 568 Failure* Isolate::ThrowIllegalOperation() { |
| 748 return Throw(Heap::illegal_access_symbol()); | 569 return Throw(heap_.illegal_access_symbol()); |
| 749 } | 570 } |
| 750 | 571 |
| 751 | 572 |
| 752 void Top::ScheduleThrow(Object* exception) { | 573 void Isolate::ScheduleThrow(Object* exception) { |
| 753 // When scheduling a throw we first throw the exception to get the | 574 // When scheduling a throw we first throw the exception to get the |
| 754 // error reporting if it is uncaught before rescheduling it. | 575 // error reporting if it is uncaught before rescheduling it. |
| 755 Throw(exception); | 576 Throw(exception); |
| 756 thread_local_.scheduled_exception_ = pending_exception(); | 577 thread_local_top()->scheduled_exception_ = pending_exception(); |
| 757 thread_local_.external_caught_exception_ = false; | 578 thread_local_top()->external_caught_exception_ = false; |
| 758 clear_pending_exception(); | 579 clear_pending_exception(); |
| 759 } | 580 } |
| 760 | 581 |
| 761 | 582 |
| 762 Failure* Top::PromoteScheduledException() { | 583 Failure* Isolate::PromoteScheduledException() { |
| 763 MaybeObject* thrown = scheduled_exception(); | 584 MaybeObject* thrown = scheduled_exception(); |
| 764 clear_scheduled_exception(); | 585 clear_scheduled_exception(); |
| 765 // Re-throw the exception to avoid getting repeated error reporting. | 586 // Re-throw the exception to avoid getting repeated error reporting. |
| 766 return ReThrow(thrown); | 587 return ReThrow(thrown); |
| 767 } | 588 } |
| 768 | 589 |
| 769 | 590 |
| 770 void Top::PrintCurrentStackTrace(FILE* out) { | 591 void Isolate::PrintCurrentStackTrace(FILE* out) { |
| 771 StackTraceFrameIterator it; | 592 StackTraceFrameIterator it; |
| 772 while (!it.done()) { | 593 while (!it.done()) { |
| 773 HandleScope scope; | 594 HandleScope scope; |
| 774 // Find code position if recorded in relocation info. | 595 // Find code position if recorded in relocation info. |
| 775 JavaScriptFrame* frame = it.frame(); | 596 JavaScriptFrame* frame = it.frame(); |
| 776 int pos = frame->code()->SourcePosition(frame->pc()); | 597 int pos = frame->LookupCode(this)->SourcePosition(frame->pc()); |
| 777 Handle<Object> pos_obj(Smi::FromInt(pos)); | 598 Handle<Object> pos_obj(Smi::FromInt(pos)); |
| 778 // Fetch function and receiver. | 599 // Fetch function and receiver. |
| 779 Handle<JSFunction> fun(JSFunction::cast(frame->function())); | 600 Handle<JSFunction> fun(JSFunction::cast(frame->function())); |
| 780 Handle<Object> recv(frame->receiver()); | 601 Handle<Object> recv(frame->receiver()); |
| 781 // Advance to the next JavaScript frame and determine if the | 602 // Advance to the next JavaScript frame and determine if the |
| 782 // current frame is the top-level frame. | 603 // current frame is the top-level frame. |
| 783 it.Advance(); | 604 it.Advance(); |
| 784 Handle<Object> is_top_level = it.done() | 605 Handle<Object> is_top_level = it.done() |
| 785 ? Factory::true_value() | 606 ? factory()->true_value() |
| 786 : Factory::false_value(); | 607 : factory()->false_value(); |
| 787 // Generate and print stack trace line. | 608 // Generate and print stack trace line. |
| 788 Handle<String> line = | 609 Handle<String> line = |
| 789 Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); | 610 Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); |
| 790 if (line->length() > 0) { | 611 if (line->length() > 0) { |
| 791 line->PrintOn(out); | 612 line->PrintOn(out); |
| 792 fprintf(out, "\n"); | 613 fprintf(out, "\n"); |
| 793 } | 614 } |
| 794 } | 615 } |
| 795 } | 616 } |
| 796 | 617 |
| 797 | 618 |
| 798 void Top::ComputeLocation(MessageLocation* target) { | 619 void Isolate::ComputeLocation(MessageLocation* target) { |
| 799 *target = MessageLocation(Handle<Script>(Heap::empty_script()), -1, -1); | 620 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1); |
| 800 StackTraceFrameIterator it; | 621 StackTraceFrameIterator it; |
| 801 if (!it.done()) { | 622 if (!it.done()) { |
| 802 JavaScriptFrame* frame = it.frame(); | 623 JavaScriptFrame* frame = it.frame(); |
| 803 JSFunction* fun = JSFunction::cast(frame->function()); | 624 JSFunction* fun = JSFunction::cast(frame->function()); |
| 804 Object* script = fun->shared()->script(); | 625 Object* script = fun->shared()->script(); |
| 805 if (script->IsScript() && | 626 if (script->IsScript() && |
| 806 !(Script::cast(script)->source()->IsUndefined())) { | 627 !(Script::cast(script)->source()->IsUndefined())) { |
| 807 int pos = frame->code()->SourcePosition(frame->pc()); | 628 int pos = frame->LookupCode(this)->SourcePosition(frame->pc()); |
| 808 // Compute the location from the function and the reloc info. | 629 // Compute the location from the function and the reloc info. |
| 809 Handle<Script> casted_script(Script::cast(script)); | 630 Handle<Script> casted_script(Script::cast(script)); |
| 810 *target = MessageLocation(casted_script, pos, pos + 1); | 631 *target = MessageLocation(casted_script, pos, pos + 1); |
| 811 } | 632 } |
| 812 } | 633 } |
| 813 } | 634 } |
| 814 | 635 |
| 815 | 636 |
| 816 bool Top::ShouldReportException(bool* can_be_caught_externally, | 637 bool Isolate::ShouldReportException(bool* can_be_caught_externally, |
| 817 bool catchable_by_javascript) { | 638 bool catchable_by_javascript) { |
| 818 // Find the top-most try-catch handler. | 639 // Find the top-most try-catch handler. |
| 819 StackHandler* handler = | 640 StackHandler* handler = |
| 820 StackHandler::FromAddress(Top::handler(Top::GetCurrentThread())); | 641 StackHandler::FromAddress(Isolate::handler(thread_local_top())); |
| 821 while (handler != NULL && !handler->is_try_catch()) { | 642 while (handler != NULL && !handler->is_try_catch()) { |
| 822 handler = handler->next(); | 643 handler = handler->next(); |
| 823 } | 644 } |
| 824 | 645 |
| 825 // Get the address of the external handler so we can compare the address to | 646 // Get the address of the external handler so we can compare the address to |
| 826 // determine which one is closer to the top of the stack. | 647 // determine which one is closer to the top of the stack. |
| 827 Address external_handler_address = thread_local_.try_catch_handler_address(); | 648 Address external_handler_address = |
| 649 thread_local_top()->try_catch_handler_address(); |
| 828 | 650 |
| 829 // The exception has been externally caught if and only if there is | 651 // The exception has been externally caught if and only if there is |
| 830 // an external handler which is on top of the top-most try-catch | 652 // an external handler which is on top of the top-most try-catch |
| 831 // handler. | 653 // handler. |
| 832 *can_be_caught_externally = external_handler_address != NULL && | 654 *can_be_caught_externally = external_handler_address != NULL && |
| 833 (handler == NULL || handler->address() > external_handler_address || | 655 (handler == NULL || handler->address() > external_handler_address || |
| 834 !catchable_by_javascript); | 656 !catchable_by_javascript); |
| 835 | 657 |
| 836 if (*can_be_caught_externally) { | 658 if (*can_be_caught_externally) { |
| 837 // Only report the exception if the external handler is verbose. | 659 // Only report the exception if the external handler is verbose. |
| 838 return try_catch_handler()->is_verbose_; | 660 return try_catch_handler()->is_verbose_; |
| 839 } else { | 661 } else { |
| 840 // Report the exception if it isn't caught by JavaScript code. | 662 // Report the exception if it isn't caught by JavaScript code. |
| 841 return handler == NULL; | 663 return handler == NULL; |
| 842 } | 664 } |
| 843 } | 665 } |
| 844 | 666 |
| 845 | 667 |
| 846 void Top::DoThrow(MaybeObject* exception, | 668 void Isolate::DoThrow(MaybeObject* exception, |
| 847 MessageLocation* location, | 669 MessageLocation* location, |
| 848 const char* message) { | 670 const char* message) { |
| 849 ASSERT(!has_pending_exception()); | 671 ASSERT(!has_pending_exception()); |
| 850 | 672 |
| 851 HandleScope scope; | 673 HandleScope scope; |
| 852 Object* exception_object = Smi::FromInt(0); | 674 Object* exception_object = Smi::FromInt(0); |
| 853 bool is_object = exception->ToObject(&exception_object); | 675 bool is_object = exception->ToObject(&exception_object); |
| 854 Handle<Object> exception_handle(exception_object); | 676 Handle<Object> exception_handle(exception_object); |
| 855 | 677 |
| 856 // Determine reporting and whether the exception is caught externally. | 678 // Determine reporting and whether the exception is caught externally. |
| 857 bool catchable_by_javascript = is_catchable_by_javascript(exception); | 679 bool catchable_by_javascript = is_catchable_by_javascript(exception); |
| 858 // Only real objects can be caught by JS. | 680 // Only real objects can be caught by JS. |
| 859 ASSERT(!catchable_by_javascript || is_object); | 681 ASSERT(!catchable_by_javascript || is_object); |
| 860 bool can_be_caught_externally = false; | 682 bool can_be_caught_externally = false; |
| 861 bool should_report_exception = | 683 bool should_report_exception = |
| 862 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); | 684 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); |
| 863 bool report_exception = catchable_by_javascript && should_report_exception; | 685 bool report_exception = catchable_by_javascript && should_report_exception; |
| 864 | 686 |
| 865 #ifdef ENABLE_DEBUGGER_SUPPORT | 687 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 866 // Notify debugger of exception. | 688 // Notify debugger of exception. |
| 867 if (catchable_by_javascript) { | 689 if (catchable_by_javascript) { |
| 868 Debugger::OnException(exception_handle, report_exception); | 690 debugger_->OnException(exception_handle, report_exception); |
| 869 } | 691 } |
| 870 #endif | 692 #endif |
| 871 | 693 |
| 872 // Generate the message. | 694 // Generate the message. |
| 873 Handle<Object> message_obj; | 695 Handle<Object> message_obj; |
| 874 MessageLocation potential_computed_location; | 696 MessageLocation potential_computed_location; |
| 875 bool try_catch_needs_message = | 697 bool try_catch_needs_message = |
| 876 can_be_caught_externally && | 698 can_be_caught_externally && |
| 877 try_catch_handler()->capture_message_; | 699 try_catch_handler()->capture_message_; |
| 878 if (report_exception || try_catch_needs_message) { | 700 if (report_exception || try_catch_needs_message) { |
| 879 if (location == NULL) { | 701 if (location == NULL) { |
| 880 // If no location was specified we use a computed one instead | 702 // If no location was specified we use a computed one instead |
| 881 ComputeLocation(&potential_computed_location); | 703 ComputeLocation(&potential_computed_location); |
| 882 location = &potential_computed_location; | 704 location = &potential_computed_location; |
| 883 } | 705 } |
| 884 if (!Bootstrapper::IsActive()) { | 706 if (!bootstrapper()->IsActive()) { |
| 885 // It's not safe to try to make message objects or collect stack | 707 // It's not safe to try to make message objects or collect stack |
| 886 // traces while the bootstrapper is active since the infrastructure | 708 // traces while the bootstrapper is active since the infrastructure |
| 887 // may not have been properly initialized. | 709 // may not have been properly initialized. |
| 888 Handle<String> stack_trace; | 710 Handle<String> stack_trace; |
| 889 if (FLAG_trace_exception) stack_trace = StackTraceString(); | 711 if (FLAG_trace_exception) stack_trace = StackTraceString(); |
| 890 Handle<JSArray> stack_trace_object; | 712 Handle<JSArray> stack_trace_object; |
| 891 if (report_exception && capture_stack_trace_for_uncaught_exceptions) { | 713 if (report_exception && capture_stack_trace_for_uncaught_exceptions_) { |
| 892 stack_trace_object = Top::CaptureCurrentStackTrace( | 714 stack_trace_object = CaptureCurrentStackTrace( |
| 893 stack_trace_for_uncaught_exceptions_frame_limit, | 715 stack_trace_for_uncaught_exceptions_frame_limit_, |
| 894 stack_trace_for_uncaught_exceptions_options); | 716 stack_trace_for_uncaught_exceptions_options_); |
| 895 } | 717 } |
| 896 ASSERT(is_object); // Can't use the handle unless there's a real object. | 718 ASSERT(is_object); // Can't use the handle unless there's a real object. |
| 897 message_obj = MessageHandler::MakeMessageObject("uncaught_exception", | 719 message_obj = MessageHandler::MakeMessageObject("uncaught_exception", |
| 898 location, HandleVector<Object>(&exception_handle, 1), stack_trace, | 720 location, HandleVector<Object>(&exception_handle, 1), stack_trace, |
| 899 stack_trace_object); | 721 stack_trace_object); |
| 900 } | 722 } |
| 901 } | 723 } |
| 902 | 724 |
| 903 // Save the message for reporting if the the exception remains uncaught. | 725 // Save the message for reporting if the the exception remains uncaught. |
| 904 thread_local_.has_pending_message_ = report_exception; | 726 thread_local_top()->has_pending_message_ = report_exception; |
| 905 thread_local_.pending_message_ = message; | 727 thread_local_top()->pending_message_ = message; |
| 906 if (!message_obj.is_null()) { | 728 if (!message_obj.is_null()) { |
| 907 thread_local_.pending_message_obj_ = *message_obj; | 729 thread_local_top()->pending_message_obj_ = *message_obj; |
| 908 if (location != NULL) { | 730 if (location != NULL) { |
| 909 thread_local_.pending_message_script_ = *location->script(); | 731 thread_local_top()->pending_message_script_ = *location->script(); |
| 910 thread_local_.pending_message_start_pos_ = location->start_pos(); | 732 thread_local_top()->pending_message_start_pos_ = location->start_pos(); |
| 911 thread_local_.pending_message_end_pos_ = location->end_pos(); | 733 thread_local_top()->pending_message_end_pos_ = location->end_pos(); |
| 912 } | 734 } |
| 913 } | 735 } |
| 914 | 736 |
| 915 // Do not forget to clean catcher_ if currently thrown exception cannot | 737 // Do not forget to clean catcher_ if currently thrown exception cannot |
| 916 // be caught. If necessary, ReThrow will update the catcher. | 738 // be caught. If necessary, ReThrow will update the catcher. |
| 917 thread_local_.catcher_ = can_be_caught_externally ? | 739 thread_local_top()->catcher_ = can_be_caught_externally ? |
| 918 try_catch_handler() : NULL; | 740 try_catch_handler() : NULL; |
| 919 | 741 |
| 920 // NOTE: Notifying the debugger or generating the message | 742 // NOTE: Notifying the debugger or generating the message |
| 921 // may have caused new exceptions. For now, we just ignore | 743 // may have caused new exceptions. For now, we just ignore |
| 922 // that and set the pending exception to the original one. | 744 // that and set the pending exception to the original one. |
| 923 if (is_object) { | 745 if (is_object) { |
| 924 set_pending_exception(*exception_handle); | 746 set_pending_exception(*exception_handle); |
| 925 } else { | 747 } else { |
| 926 // Failures are not on the heap so they neither need nor work with handles. | 748 // Failures are not on the heap so they neither need nor work with handles. |
| 927 ASSERT(exception_handle->IsFailure()); | 749 ASSERT(exception_handle->IsFailure()); |
| 928 set_pending_exception(exception); | 750 set_pending_exception(exception); |
| 929 } | 751 } |
| 930 } | 752 } |
| 931 | 753 |
| 932 | 754 |
| 933 bool Top::IsExternallyCaught() { | 755 bool Isolate::IsExternallyCaught() { |
| 934 ASSERT(has_pending_exception()); | 756 ASSERT(has_pending_exception()); |
| 935 | 757 |
| 936 if ((thread_local_.catcher_ == NULL) || | 758 if ((thread_local_top()->catcher_ == NULL) || |
| 937 (try_catch_handler() != thread_local_.catcher_)) { | 759 (try_catch_handler() != thread_local_top()->catcher_)) { |
| 938 // When throwing the exception, we found no v8::TryCatch | 760 // When throwing the exception, we found no v8::TryCatch |
| 939 // which should care about this exception. | 761 // which should care about this exception. |
| 940 return false; | 762 return false; |
| 941 } | 763 } |
| 942 | 764 |
| 943 if (!is_catchable_by_javascript(pending_exception())) { | 765 if (!is_catchable_by_javascript(pending_exception())) { |
| 944 return true; | 766 return true; |
| 945 } | 767 } |
| 946 | 768 |
| 947 // Get the address of the external handler so we can compare the address to | 769 // Get the address of the external handler so we can compare the address to |
| 948 // determine which one is closer to the top of the stack. | 770 // determine which one is closer to the top of the stack. |
| 949 Address external_handler_address = thread_local_.try_catch_handler_address(); | 771 Address external_handler_address = |
| 772 thread_local_top()->try_catch_handler_address(); |
| 950 ASSERT(external_handler_address != NULL); | 773 ASSERT(external_handler_address != NULL); |
| 951 | 774 |
| 952 // The exception has been externally caught if and only if there is | 775 // The exception has been externally caught if and only if there is |
| 953 // an external handler which is on top of the top-most try-finally | 776 // an external handler which is on top of the top-most try-finally |
| 954 // handler. | 777 // handler. |
| 955 // There should be no try-catch blocks as they would prohibit us from | 778 // There should be no try-catch blocks as they would prohibit us from |
| 956 // finding external catcher in the first place (see catcher_ check above). | 779 // finding external catcher in the first place (see catcher_ check above). |
| 957 // | 780 // |
| 958 // Note, that finally clause would rethrow an exception unless it's | 781 // Note, that finally clause would rethrow an exception unless it's |
| 959 // aborted by jumps in control flow like return, break, etc. and we'll | 782 // aborted by jumps in control flow like return, break, etc. and we'll |
| 960 // have another chances to set proper v8::TryCatch. | 783 // have another chances to set proper v8::TryCatch. |
| 961 StackHandler* handler = | 784 StackHandler* handler = |
| 962 StackHandler::FromAddress(Top::handler(Top::GetCurrentThread())); | 785 StackHandler::FromAddress(Isolate::handler(thread_local_top())); |
| 963 while (handler != NULL && handler->address() < external_handler_address) { | 786 while (handler != NULL && handler->address() < external_handler_address) { |
| 964 ASSERT(!handler->is_try_catch()); | 787 ASSERT(!handler->is_try_catch()); |
| 965 if (handler->is_try_finally()) return false; | 788 if (handler->is_try_finally()) return false; |
| 966 | 789 |
| 967 handler = handler->next(); | 790 handler = handler->next(); |
| 968 } | 791 } |
| 969 | 792 |
| 970 return true; | 793 return true; |
| 971 } | 794 } |
| 972 | 795 |
| 973 | 796 |
| 974 void Top::ReportPendingMessages() { | 797 void Isolate::ReportPendingMessages() { |
| 975 ASSERT(has_pending_exception()); | 798 ASSERT(has_pending_exception()); |
| 976 // If the pending exception is OutOfMemoryException set out_of_memory in | 799 // If the pending exception is OutOfMemoryException set out_of_memory in |
| 977 // the global context. Note: We have to mark the global context here | 800 // the global context. Note: We have to mark the global context here |
| 978 // since the GenerateThrowOutOfMemory stub cannot make a RuntimeCall to | 801 // since the GenerateThrowOutOfMemory stub cannot make a RuntimeCall to |
| 979 // set it. | 802 // set it. |
| 980 bool external_caught = IsExternallyCaught(); | 803 bool external_caught = IsExternallyCaught(); |
| 981 thread_local_.external_caught_exception_ = external_caught; | 804 thread_local_top()->external_caught_exception_ = external_caught; |
| 982 HandleScope scope; | 805 HandleScope scope(this); |
| 983 if (thread_local_.pending_exception_ == Failure::OutOfMemoryException()) { | 806 if (thread_local_top()->pending_exception_ == |
| 807 Failure::OutOfMemoryException()) { |
| 984 context()->mark_out_of_memory(); | 808 context()->mark_out_of_memory(); |
| 985 } else if (thread_local_.pending_exception_ == | 809 } else if (thread_local_top()->pending_exception_ == |
| 986 Heap::termination_exception()) { | 810 heap_.termination_exception()) { |
| 987 if (external_caught) { | 811 if (external_caught) { |
| 988 try_catch_handler()->can_continue_ = false; | 812 try_catch_handler()->can_continue_ = false; |
| 989 try_catch_handler()->exception_ = Heap::null_value(); | 813 try_catch_handler()->exception_ = heap_.null_value(); |
| 990 } | 814 } |
| 991 } else { | 815 } else { |
| 992 // At this point all non-object (failure) exceptions have | 816 // At this point all non-object (failure) exceptions have |
| 993 // been dealt with so this shouldn't fail. | 817 // been dealt with so this shouldn't fail. |
| 994 Object* pending_exception_object = pending_exception()->ToObjectUnchecked(); | 818 Object* pending_exception_object = pending_exception()->ToObjectUnchecked(); |
| 995 Handle<Object> exception(pending_exception_object); | 819 Handle<Object> exception(pending_exception_object); |
| 996 thread_local_.external_caught_exception_ = false; | 820 thread_local_top()->external_caught_exception_ = false; |
| 997 if (external_caught) { | 821 if (external_caught) { |
| 998 try_catch_handler()->can_continue_ = true; | 822 try_catch_handler()->can_continue_ = true; |
| 999 try_catch_handler()->exception_ = thread_local_.pending_exception_; | 823 try_catch_handler()->exception_ = thread_local_top()->pending_exception_; |
| 1000 if (!thread_local_.pending_message_obj_->IsTheHole()) { | 824 if (!thread_local_top()->pending_message_obj_->IsTheHole()) { |
| 1001 try_catch_handler()->message_ = thread_local_.pending_message_obj_; | 825 try_catch_handler()->message_ = |
| 826 thread_local_top()->pending_message_obj_; |
| 1002 } | 827 } |
| 1003 } | 828 } |
| 1004 if (thread_local_.has_pending_message_) { | 829 if (thread_local_top()->has_pending_message_) { |
| 1005 thread_local_.has_pending_message_ = false; | 830 thread_local_top()->has_pending_message_ = false; |
| 1006 if (thread_local_.pending_message_ != NULL) { | 831 if (thread_local_top()->pending_message_ != NULL) { |
| 1007 MessageHandler::ReportMessage(thread_local_.pending_message_); | 832 MessageHandler::ReportMessage(thread_local_top()->pending_message_); |
| 1008 } else if (!thread_local_.pending_message_obj_->IsTheHole()) { | 833 } else if (!thread_local_top()->pending_message_obj_->IsTheHole()) { |
| 1009 Handle<Object> message_obj(thread_local_.pending_message_obj_); | 834 Handle<Object> message_obj(thread_local_top()->pending_message_obj_); |
| 1010 if (thread_local_.pending_message_script_ != NULL) { | 835 if (thread_local_top()->pending_message_script_ != NULL) { |
| 1011 Handle<Script> script(thread_local_.pending_message_script_); | 836 Handle<Script> script(thread_local_top()->pending_message_script_); |
| 1012 int start_pos = thread_local_.pending_message_start_pos_; | 837 int start_pos = thread_local_top()->pending_message_start_pos_; |
| 1013 int end_pos = thread_local_.pending_message_end_pos_; | 838 int end_pos = thread_local_top()->pending_message_end_pos_; |
| 1014 MessageLocation location(script, start_pos, end_pos); | 839 MessageLocation location(script, start_pos, end_pos); |
| 1015 MessageHandler::ReportMessage(&location, message_obj); | 840 MessageHandler::ReportMessage(&location, message_obj); |
| 1016 } else { | 841 } else { |
| 1017 MessageHandler::ReportMessage(NULL, message_obj); | 842 MessageHandler::ReportMessage(NULL, message_obj); |
| 1018 } | 843 } |
| 1019 } | 844 } |
| 1020 } | 845 } |
| 1021 thread_local_.external_caught_exception_ = external_caught; | 846 thread_local_top()->external_caught_exception_ = external_caught; |
| 1022 set_pending_exception(*exception); | 847 set_pending_exception(*exception); |
| 1023 } | 848 } |
| 1024 clear_pending_message(); | 849 clear_pending_message(); |
| 1025 } | 850 } |
| 1026 | 851 |
| 1027 | 852 |
| 1028 void Top::TraceException(bool flag) { | 853 void Isolate::TraceException(bool flag) { |
| 1029 FLAG_trace_exception = flag; | 854 FLAG_trace_exception = flag; // TODO(isolates): This is an unfortunate use. |
| 1030 } | 855 } |
| 1031 | 856 |
| 1032 | 857 |
| 1033 bool Top::OptionalRescheduleException(bool is_bottom_call) { | 858 bool Isolate::OptionalRescheduleException(bool is_bottom_call) { |
| 1034 // Allways reschedule out of memory exceptions. | 859 // Allways reschedule out of memory exceptions. |
| 1035 if (!is_out_of_memory()) { | 860 if (!is_out_of_memory()) { |
| 1036 bool is_termination_exception = | 861 bool is_termination_exception = |
| 1037 pending_exception() == Heap::termination_exception(); | 862 pending_exception() == heap_.termination_exception(); |
| 1038 | 863 |
| 1039 // Do not reschedule the exception if this is the bottom call. | 864 // Do not reschedule the exception if this is the bottom call. |
| 1040 bool clear_exception = is_bottom_call; | 865 bool clear_exception = is_bottom_call; |
| 1041 | 866 |
| 1042 if (is_termination_exception) { | 867 if (is_termination_exception) { |
| 1043 if (is_bottom_call) { | 868 if (is_bottom_call) { |
| 1044 thread_local_.external_caught_exception_ = false; | 869 thread_local_top()->external_caught_exception_ = false; |
| 1045 clear_pending_exception(); | 870 clear_pending_exception(); |
| 1046 return false; | 871 return false; |
| 1047 } | 872 } |
| 1048 } else if (thread_local_.external_caught_exception_) { | 873 } else if (thread_local_top()->external_caught_exception_) { |
| 1049 // If the exception is externally caught, clear it if there are no | 874 // If the exception is externally caught, clear it if there are no |
| 1050 // JavaScript frames on the way to the C++ frame that has the | 875 // JavaScript frames on the way to the C++ frame that has the |
| 1051 // external handler. | 876 // external handler. |
| 1052 ASSERT(thread_local_.try_catch_handler_address() != NULL); | 877 ASSERT(thread_local_top()->try_catch_handler_address() != NULL); |
| 1053 Address external_handler_address = | 878 Address external_handler_address = |
| 1054 thread_local_.try_catch_handler_address(); | 879 thread_local_top()->try_catch_handler_address(); |
| 1055 JavaScriptFrameIterator it; | 880 JavaScriptFrameIterator it; |
| 1056 if (it.done() || (it.frame()->sp() > external_handler_address)) { | 881 if (it.done() || (it.frame()->sp() > external_handler_address)) { |
| 1057 clear_exception = true; | 882 clear_exception = true; |
| 1058 } | 883 } |
| 1059 } | 884 } |
| 1060 | 885 |
| 1061 // Clear the exception if needed. | 886 // Clear the exception if needed. |
| 1062 if (clear_exception) { | 887 if (clear_exception) { |
| 1063 thread_local_.external_caught_exception_ = false; | 888 thread_local_top()->external_caught_exception_ = false; |
| 1064 clear_pending_exception(); | 889 clear_pending_exception(); |
| 1065 return false; | 890 return false; |
| 1066 } | 891 } |
| 1067 } | 892 } |
| 1068 | 893 |
| 1069 // Reschedule the exception. | 894 // Reschedule the exception. |
| 1070 thread_local_.scheduled_exception_ = pending_exception(); | 895 thread_local_top()->scheduled_exception_ = pending_exception(); |
| 1071 clear_pending_exception(); | 896 clear_pending_exception(); |
| 1072 return true; | 897 return true; |
| 1073 } | 898 } |
| 1074 | 899 |
| 1075 | 900 |
| 1076 void Top::SetCaptureStackTraceForUncaughtExceptions( | 901 void Isolate::SetCaptureStackTraceForUncaughtExceptions( |
| 1077 bool capture, | 902 bool capture, |
| 1078 int frame_limit, | 903 int frame_limit, |
| 1079 StackTrace::StackTraceOptions options) { | 904 StackTrace::StackTraceOptions options) { |
| 1080 capture_stack_trace_for_uncaught_exceptions = capture; | 905 capture_stack_trace_for_uncaught_exceptions_ = capture; |
| 1081 stack_trace_for_uncaught_exceptions_frame_limit = frame_limit; | 906 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit; |
| 1082 stack_trace_for_uncaught_exceptions_options = options; | 907 stack_trace_for_uncaught_exceptions_options_ = options; |
| 1083 } | 908 } |
| 1084 | 909 |
| 1085 | 910 |
| 1086 bool Top::is_out_of_memory() { | 911 bool Isolate::is_out_of_memory() { |
| 1087 if (has_pending_exception()) { | 912 if (has_pending_exception()) { |
| 1088 MaybeObject* e = pending_exception(); | 913 MaybeObject* e = pending_exception(); |
| 1089 if (e->IsFailure() && Failure::cast(e)->IsOutOfMemoryException()) { | 914 if (e->IsFailure() && Failure::cast(e)->IsOutOfMemoryException()) { |
| 1090 return true; | 915 return true; |
| 1091 } | 916 } |
| 1092 } | 917 } |
| 1093 if (has_scheduled_exception()) { | 918 if (has_scheduled_exception()) { |
| 1094 MaybeObject* e = scheduled_exception(); | 919 MaybeObject* e = scheduled_exception(); |
| 1095 if (e->IsFailure() && Failure::cast(e)->IsOutOfMemoryException()) { | 920 if (e->IsFailure() && Failure::cast(e)->IsOutOfMemoryException()) { |
| 1096 return true; | 921 return true; |
| 1097 } | 922 } |
| 1098 } | 923 } |
| 1099 return false; | 924 return false; |
| 1100 } | 925 } |
| 1101 | 926 |
| 1102 | 927 |
| 1103 Handle<Context> Top::global_context() { | 928 Handle<Context> Isolate::global_context() { |
| 1104 GlobalObject* global = thread_local_.context_->global(); | 929 GlobalObject* global = thread_local_top()->context_->global(); |
| 1105 return Handle<Context>(global->global_context()); | 930 return Handle<Context>(global->global_context()); |
| 1106 } | 931 } |
| 1107 | 932 |
| 1108 | 933 |
| 1109 Handle<Context> Top::GetCallingGlobalContext() { | 934 Handle<Context> Isolate::GetCallingGlobalContext() { |
| 1110 JavaScriptFrameIterator it; | 935 JavaScriptFrameIterator it; |
| 1111 #ifdef ENABLE_DEBUGGER_SUPPORT | 936 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1112 if (Debug::InDebugger()) { | 937 if (debug_->InDebugger()) { |
| 1113 while (!it.done()) { | 938 while (!it.done()) { |
| 1114 JavaScriptFrame* frame = it.frame(); | 939 JavaScriptFrame* frame = it.frame(); |
| 1115 Context* context = Context::cast(frame->context()); | 940 Context* context = Context::cast(frame->context()); |
| 1116 if (context->global_context() == *Debug::debug_context()) { | 941 if (context->global_context() == *debug_->debug_context()) { |
| 1117 it.Advance(); | 942 it.Advance(); |
| 1118 } else { | 943 } else { |
| 1119 break; | 944 break; |
| 1120 } | 945 } |
| 1121 } | 946 } |
| 1122 } | 947 } |
| 1123 #endif // ENABLE_DEBUGGER_SUPPORT | 948 #endif // ENABLE_DEBUGGER_SUPPORT |
| 1124 if (it.done()) return Handle<Context>::null(); | 949 if (it.done()) return Handle<Context>::null(); |
| 1125 JavaScriptFrame* frame = it.frame(); | 950 JavaScriptFrame* frame = it.frame(); |
| 1126 Context* context = Context::cast(frame->context()); | 951 Context* context = Context::cast(frame->context()); |
| 1127 return Handle<Context>(context->global_context()); | 952 return Handle<Context>(context->global_context()); |
| 1128 } | 953 } |
| 1129 | 954 |
| 1130 | 955 |
| 1131 char* Top::ArchiveThread(char* to) { | 956 char* Isolate::ArchiveThread(char* to) { |
| 1132 memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(thread_local_)); | 957 if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) { |
| 958 RuntimeProfiler::IsolateExitedJS(this); |
| 959 } |
| 960 memcpy(to, reinterpret_cast<char*>(thread_local_top()), |
| 961 sizeof(ThreadLocalTop)); |
| 1133 InitializeThreadLocal(); | 962 InitializeThreadLocal(); |
| 1134 return to + sizeof(thread_local_); | 963 return to + sizeof(ThreadLocalTop); |
| 1135 } | 964 } |
| 1136 | 965 |
| 1137 | 966 |
| 1138 char* Top::RestoreThread(char* from) { | 967 char* Isolate::RestoreThread(char* from) { |
| 1139 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(thread_local_)); | 968 memcpy(reinterpret_cast<char*>(thread_local_top()), from, |
| 969 sizeof(ThreadLocalTop)); |
| 1140 // This might be just paranoia, but it seems to be needed in case a | 970 // This might be just paranoia, but it seems to be needed in case a |
| 1141 // thread_local_ is restored on a separate OS thread. | 971 // thread_local_ is restored on a separate OS thread. |
| 1142 #ifdef USE_SIMULATOR | 972 #ifdef USE_SIMULATOR |
| 1143 #ifdef V8_TARGET_ARCH_ARM | 973 #ifdef V8_TARGET_ARCH_ARM |
| 1144 thread_local_.simulator_ = Simulator::current(); | 974 thread_local_top()->simulator_ = Simulator::current(this); |
| 1145 #elif V8_TARGET_ARCH_MIPS | 975 #elif V8_TARGET_ARCH_MIPS |
| 1146 thread_local_.simulator_ = assembler::mips::Simulator::current(); | 976 thread_local_top()->simulator_ = Simulator::current(this); |
| 1147 #endif | 977 #endif |
| 1148 #endif | 978 #endif |
| 1149 return from + sizeof(thread_local_); | 979 if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) { |
| 980 RuntimeProfiler::IsolateEnteredJS(this); |
| 981 } |
| 982 return from + sizeof(ThreadLocalTop); |
| 1150 } | 983 } |
| 1151 | 984 |
| 1152 } } // namespace v8::internal | 985 } } // namespace v8::internal |
| OLD | NEW |