OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 external_callback_scope_ = NULL; | 72 external_callback_scope_ = NULL; |
73 current_vm_state_ = EXTERNAL; | 73 current_vm_state_ = EXTERNAL; |
74 try_catch_handler_ = NULL; | 74 try_catch_handler_ = NULL; |
75 context_ = NULL; | 75 context_ = NULL; |
76 thread_id_ = ThreadId::Invalid(); | 76 thread_id_ = ThreadId::Invalid(); |
77 external_caught_exception_ = false; | 77 external_caught_exception_ = false; |
78 failed_access_check_callback_ = NULL; | 78 failed_access_check_callback_ = NULL; |
79 save_context_ = NULL; | 79 save_context_ = NULL; |
80 catcher_ = NULL; | 80 catcher_ = NULL; |
81 top_lookup_result_ = NULL; | 81 top_lookup_result_ = NULL; |
| 82 promise_on_stack_ = NULL; |
82 | 83 |
83 // These members are re-initialized later after deserialization | 84 // These members are re-initialized later after deserialization |
84 // is complete. | 85 // is complete. |
85 pending_exception_ = NULL; | 86 pending_exception_ = NULL; |
86 has_pending_message_ = false; | 87 has_pending_message_ = false; |
87 rethrowing_message_ = false; | 88 rethrowing_message_ = false; |
88 pending_message_obj_ = NULL; | 89 pending_message_obj_ = NULL; |
89 pending_message_script_ = NULL; | 90 pending_message_script_ = NULL; |
90 scheduled_exception_ = NULL; | 91 scheduled_exception_ = NULL; |
91 } | 92 } |
92 | 93 |
93 | 94 |
94 void ThreadLocalTop::Initialize() { | 95 void ThreadLocalTop::Initialize() { |
95 InitializeInternal(); | 96 InitializeInternal(); |
96 #ifdef USE_SIMULATOR | 97 #ifdef USE_SIMULATOR |
97 simulator_ = Simulator::current(isolate_); | 98 simulator_ = Simulator::current(isolate_); |
98 #endif | 99 #endif |
99 thread_id_ = ThreadId::Current(); | 100 thread_id_ = ThreadId::Current(); |
100 } | 101 } |
101 | 102 |
102 | 103 |
| 104 void ThreadLocalTop::Free() { |
| 105 // Match unmatched PopPromise calls. |
| 106 while (promise_on_stack_) isolate_->PopPromise(); |
| 107 } |
| 108 |
| 109 |
103 base::Thread::LocalStorageKey Isolate::isolate_key_; | 110 base::Thread::LocalStorageKey Isolate::isolate_key_; |
104 base::Thread::LocalStorageKey Isolate::thread_id_key_; | 111 base::Thread::LocalStorageKey Isolate::thread_id_key_; |
105 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; | 112 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; |
106 #ifdef DEBUG | 113 #ifdef DEBUG |
107 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; | 114 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; |
108 #endif // DEBUG | 115 #endif // DEBUG |
109 base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER; | 116 base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER; |
110 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; | 117 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; |
111 base::Atomic32 Isolate::isolate_counter_ = 0; | 118 base::Atomic32 Isolate::isolate_counter_ = 0; |
112 | 119 |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 return false; | 1289 return false; |
1283 } | 1290 } |
1284 | 1291 |
1285 // Reschedule the exception. | 1292 // Reschedule the exception. |
1286 thread_local_top()->scheduled_exception_ = pending_exception(); | 1293 thread_local_top()->scheduled_exception_ = pending_exception(); |
1287 clear_pending_exception(); | 1294 clear_pending_exception(); |
1288 return true; | 1295 return true; |
1289 } | 1296 } |
1290 | 1297 |
1291 | 1298 |
| 1299 void Isolate::PushPromise(Handle<JSObject> promise) { |
| 1300 ThreadLocalTop* tltop = thread_local_top(); |
| 1301 PromiseOnStack* prev = tltop->promise_on_stack_; |
| 1302 StackHandler* handler = StackHandler::FromAddress(Isolate::handler(tltop)); |
| 1303 Handle<JSObject> global_handle = |
| 1304 Handle<JSObject>::cast(global_handles()->Create(*promise)); |
| 1305 tltop->promise_on_stack_ = new PromiseOnStack(handler, global_handle, prev); |
| 1306 } |
| 1307 |
| 1308 |
| 1309 void Isolate::PopPromise() { |
| 1310 ThreadLocalTop* tltop = thread_local_top(); |
| 1311 if (tltop->promise_on_stack_ == NULL) return; |
| 1312 PromiseOnStack* prev = tltop->promise_on_stack_->prev(); |
| 1313 Handle<Object> global_handle = tltop->promise_on_stack_->promise(); |
| 1314 delete tltop->promise_on_stack_; |
| 1315 tltop->promise_on_stack_ = prev; |
| 1316 global_handles()->Destroy(global_handle.location()); |
| 1317 } |
| 1318 |
| 1319 |
| 1320 Handle<Object> Isolate::GetPromiseOnStackOnThrow() { |
| 1321 Handle<Object> undefined = factory()->undefined_value(); |
| 1322 ThreadLocalTop* tltop = thread_local_top(); |
| 1323 if (tltop->promise_on_stack_ == NULL) return undefined; |
| 1324 StackHandler* promise_try = tltop->promise_on_stack_->handler(); |
| 1325 // Find the top-most try-catch handler. |
| 1326 StackHandler* handler = StackHandler::FromAddress(Isolate::handler(tltop)); |
| 1327 do { |
| 1328 if (handler == promise_try) { |
| 1329 // Mark the pushed try-catch handler to prevent a later duplicate event |
| 1330 // triggered with the following reject. |
| 1331 return tltop->promise_on_stack_->promise(); |
| 1332 } |
| 1333 handler = handler->next(); |
| 1334 // Throwing inside a Promise can be intercepted by an inner try-catch, so |
| 1335 // we stop at the first try-catch handler. |
| 1336 } while (handler != NULL && !handler->is_catch()); |
| 1337 return undefined; |
| 1338 } |
| 1339 |
| 1340 |
1292 void Isolate::SetCaptureStackTraceForUncaughtExceptions( | 1341 void Isolate::SetCaptureStackTraceForUncaughtExceptions( |
1293 bool capture, | 1342 bool capture, |
1294 int frame_limit, | 1343 int frame_limit, |
1295 StackTrace::StackTraceOptions options) { | 1344 StackTrace::StackTraceOptions options) { |
1296 capture_stack_trace_for_uncaught_exceptions_ = capture; | 1345 capture_stack_trace_for_uncaught_exceptions_ = capture; |
1297 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit; | 1346 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit; |
1298 stack_trace_for_uncaught_exceptions_options_ = options; | 1347 stack_trace_for_uncaught_exceptions_options_ = options; |
1299 } | 1348 } |
1300 | 1349 |
1301 | 1350 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 delete thread_data_table_; | 1594 delete thread_data_table_; |
1546 } | 1595 } |
1547 | 1596 |
1548 | 1597 |
1549 void Isolate::Deinit() { | 1598 void Isolate::Deinit() { |
1550 if (state_ == INITIALIZED) { | 1599 if (state_ == INITIALIZED) { |
1551 TRACE_ISOLATE(deinit); | 1600 TRACE_ISOLATE(deinit); |
1552 | 1601 |
1553 debug()->Unload(); | 1602 debug()->Unload(); |
1554 | 1603 |
| 1604 FreeThreadResources(); |
| 1605 |
1555 if (concurrent_recompilation_enabled()) { | 1606 if (concurrent_recompilation_enabled()) { |
1556 optimizing_compiler_thread_->Stop(); | 1607 optimizing_compiler_thread_->Stop(); |
1557 delete optimizing_compiler_thread_; | 1608 delete optimizing_compiler_thread_; |
1558 optimizing_compiler_thread_ = NULL; | 1609 optimizing_compiler_thread_ = NULL; |
1559 } | 1610 } |
1560 | 1611 |
1561 for (int i = 0; i < num_sweeper_threads_; i++) { | 1612 for (int i = 0; i < num_sweeper_threads_; i++) { |
1562 sweeper_thread_[i]->Stop(); | 1613 sweeper_thread_[i]->Stop(); |
1563 delete sweeper_thread_[i]; | 1614 delete sweeper_thread_[i]; |
1564 sweeper_thread_[i] = NULL; | 1615 sweeper_thread_[i] = NULL; |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2364 if (prev_ && prev_->Intercept(flag)) return true; | 2415 if (prev_ && prev_->Intercept(flag)) return true; |
2365 // Then check whether this scope intercepts. | 2416 // Then check whether this scope intercepts. |
2366 if ((flag & intercept_mask_)) { | 2417 if ((flag & intercept_mask_)) { |
2367 intercepted_flags_ |= flag; | 2418 intercepted_flags_ |= flag; |
2368 return true; | 2419 return true; |
2369 } | 2420 } |
2370 return false; | 2421 return false; |
2371 } | 2422 } |
2372 | 2423 |
2373 } } // namespace v8::internal | 2424 } } // namespace v8::internal |
OLD | NEW |