| 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 "src/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 ->GetCurrentContext(); | 150 ->GetCurrentContext(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 class InternalEscapableScope : public v8::EscapableHandleScope { | 153 class InternalEscapableScope : public v8::EscapableHandleScope { |
| 154 public: | 154 public: |
| 155 explicit inline InternalEscapableScope(i::Isolate* isolate) | 155 explicit inline InternalEscapableScope(i::Isolate* isolate) |
| 156 : v8::EscapableHandleScope(reinterpret_cast<v8::Isolate*>(isolate)) {} | 156 : v8::EscapableHandleScope(reinterpret_cast<v8::Isolate*>(isolate)) {} |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 | 159 |
| 160 #ifdef V8_ENABLE_CHECKS | |
| 161 void CheckMicrotasksScopesConsistency(i::Isolate* isolate) { | |
| 162 auto handle_scope_implementer = isolate->handle_scope_implementer(); | |
| 163 if (handle_scope_implementer->microtasks_policy() == | |
| 164 v8::MicrotasksPolicy::kScoped) { | |
| 165 DCHECK(handle_scope_implementer->GetMicrotasksScopeDepth() || | |
| 166 !handle_scope_implementer->DebugMicrotasksScopeDepthIsZero()); | |
| 167 } | |
| 168 } | |
| 169 #endif | |
| 170 | |
| 171 | |
| 172 class CallDepthScope { | 160 class CallDepthScope { |
| 173 public: | 161 public: |
| 174 explicit CallDepthScope(i::Isolate* isolate, Local<Context> context, | 162 explicit CallDepthScope(i::Isolate* isolate, Local<Context> context, |
| 175 bool do_callback) | 163 bool do_callback) |
| 176 : isolate_(isolate), | 164 : isolate_(isolate), |
| 177 context_(context), | 165 context_(context), |
| 178 escaped_(false), | 166 escaped_(false), |
| 179 do_callback_(do_callback) { | 167 do_callback_(do_callback) { |
| 180 // TODO(dcarney): remove this when blink stops crashing. | 168 // TODO(dcarney): remove this when blink stops crashing. |
| 181 DCHECK(!isolate_->external_caught_exception()); | 169 DCHECK(!isolate_->external_caught_exception()); |
| 182 isolate_->IncrementJsCallsFromApiCounter(); | 170 isolate_->IncrementJsCallsFromApiCounter(); |
| 183 isolate_->handle_scope_implementer()->IncrementCallDepth(); | 171 isolate_->handle_scope_implementer()->IncrementCallDepth(); |
| 184 if (!context_.IsEmpty()) context_->Enter(); | 172 if (!context_.IsEmpty()) context_->Enter(); |
| 185 if (do_callback_) isolate_->FireBeforeCallEnteredCallback(); | 173 if (do_callback_) isolate_->FireBeforeCallEnteredCallback(); |
| 186 } | 174 } |
| 187 ~CallDepthScope() { | 175 ~CallDepthScope() { |
| 188 if (!context_.IsEmpty()) context_->Exit(); | 176 if (!context_.IsEmpty()) context_->Exit(); |
| 189 if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth(); | 177 if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth(); |
| 190 if (do_callback_) isolate_->FireCallCompletedCallback(); | 178 if (do_callback_) isolate_->FireCallCompletedCallback(); |
| 191 #ifdef V8_ENABLE_CHECKS | |
| 192 if (do_callback_) CheckMicrotasksScopesConsistency(isolate_); | |
| 193 #endif | |
| 194 } | 179 } |
| 195 | 180 |
| 196 void Escape() { | 181 void Escape() { |
| 197 DCHECK(!escaped_); | 182 DCHECK(!escaped_); |
| 198 escaped_ = true; | 183 escaped_ = true; |
| 199 auto handle_scope_implementer = isolate_->handle_scope_implementer(); | 184 auto handle_scope_implementer = isolate_->handle_scope_implementer(); |
| 200 handle_scope_implementer->DecrementCallDepth(); | 185 handle_scope_implementer->DecrementCallDepth(); |
| 201 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); | 186 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); |
| 202 isolate_->OptionalRescheduleException(call_depth_is_zero); | 187 isolate_->OptionalRescheduleException(call_depth_is_zero); |
| 203 } | 188 } |
| (...skipping 7102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7306 Isolate::AllowJavascriptExecutionScope::~AllowJavascriptExecutionScope() { | 7291 Isolate::AllowJavascriptExecutionScope::~AllowJavascriptExecutionScope() { |
| 7307 delete reinterpret_cast<i::AllowJavascriptExecution*>(internal_assert_); | 7292 delete reinterpret_cast<i::AllowJavascriptExecution*>(internal_assert_); |
| 7308 delete reinterpret_cast<i::NoThrowOnJavascriptExecution*>(internal_throws_); | 7293 delete reinterpret_cast<i::NoThrowOnJavascriptExecution*>(internal_throws_); |
| 7309 } | 7294 } |
| 7310 | 7295 |
| 7311 | 7296 |
| 7312 Isolate::SuppressMicrotaskExecutionScope::SuppressMicrotaskExecutionScope( | 7297 Isolate::SuppressMicrotaskExecutionScope::SuppressMicrotaskExecutionScope( |
| 7313 Isolate* isolate) | 7298 Isolate* isolate) |
| 7314 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) { | 7299 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) { |
| 7315 isolate_->handle_scope_implementer()->IncrementCallDepth(); | 7300 isolate_->handle_scope_implementer()->IncrementCallDepth(); |
| 7316 isolate_->handle_scope_implementer()->IncrementMicrotasksSuppressions(); | |
| 7317 } | 7301 } |
| 7318 | 7302 |
| 7319 | 7303 |
| 7320 Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() { | 7304 Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() { |
| 7321 isolate_->handle_scope_implementer()->DecrementMicrotasksSuppressions(); | |
| 7322 isolate_->handle_scope_implementer()->DecrementCallDepth(); | 7305 isolate_->handle_scope_implementer()->DecrementCallDepth(); |
| 7323 } | 7306 } |
| 7324 | 7307 |
| 7325 | 7308 |
| 7326 void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { | 7309 void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { |
| 7327 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7310 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7328 i::Heap* heap = isolate->heap(); | 7311 i::Heap* heap = isolate->heap(); |
| 7329 heap_statistics->total_heap_size_ = heap->CommittedMemory(); | 7312 heap_statistics->total_heap_size_ = heap->CommittedMemory(); |
| 7330 heap_statistics->total_heap_size_executable_ = | 7313 heap_statistics->total_heap_size_executable_ = |
| 7331 heap->CommittedMemoryExecutable(); | 7314 heap->CommittedMemoryExecutable(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7453 | 7436 |
| 7454 | 7437 |
| 7455 void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) { | 7438 void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) { |
| 7456 if (callback == NULL) return; | 7439 if (callback == NULL) return; |
| 7457 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7440 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7458 isolate->SetPromiseRejectCallback(callback); | 7441 isolate->SetPromiseRejectCallback(callback); |
| 7459 } | 7442 } |
| 7460 | 7443 |
| 7461 | 7444 |
| 7462 void Isolate::RunMicrotasks() { | 7445 void Isolate::RunMicrotasks() { |
| 7463 DCHECK(MicrotasksPolicy::kScoped != GetMicrotasksPolicy()); | |
| 7464 reinterpret_cast<i::Isolate*>(this)->RunMicrotasks(); | 7446 reinterpret_cast<i::Isolate*>(this)->RunMicrotasks(); |
| 7465 } | 7447 } |
| 7466 | 7448 |
| 7467 | 7449 |
| 7468 void Isolate::EnqueueMicrotask(Local<Function> microtask) { | 7450 void Isolate::EnqueueMicrotask(Local<Function> microtask) { |
| 7469 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7451 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7470 isolate->EnqueueMicrotask(Utils::OpenHandle(*microtask)); | 7452 isolate->EnqueueMicrotask(Utils::OpenHandle(*microtask)); |
| 7471 } | 7453 } |
| 7472 | 7454 |
| 7473 | 7455 |
| 7474 void Isolate::EnqueueMicrotask(MicrotaskCallback microtask, void* data) { | 7456 void Isolate::EnqueueMicrotask(MicrotaskCallback microtask, void* data) { |
| 7475 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7457 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7476 i::HandleScope scope(isolate); | 7458 i::HandleScope scope(isolate); |
| 7477 i::Handle<i::CallHandlerInfo> callback_info = | 7459 i::Handle<i::CallHandlerInfo> callback_info = |
| 7478 i::Handle<i::CallHandlerInfo>::cast( | 7460 i::Handle<i::CallHandlerInfo>::cast( |
| 7479 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE)); | 7461 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE)); |
| 7480 SET_FIELD_WRAPPED(callback_info, set_callback, microtask); | 7462 SET_FIELD_WRAPPED(callback_info, set_callback, microtask); |
| 7481 SET_FIELD_WRAPPED(callback_info, set_data, data); | 7463 SET_FIELD_WRAPPED(callback_info, set_data, data); |
| 7482 isolate->EnqueueMicrotask(callback_info); | 7464 isolate->EnqueueMicrotask(callback_info); |
| 7483 } | 7465 } |
| 7484 | 7466 |
| 7485 | 7467 |
| 7486 void Isolate::SetAutorunMicrotasks(bool autorun) { | 7468 void Isolate::SetAutorunMicrotasks(bool autorun) { |
| 7487 SetMicrotasksPolicy(MicrotasksPolicy::kAuto); | 7469 reinterpret_cast<i::Isolate*>(this)->set_autorun_microtasks(autorun); |
| 7488 } | 7470 } |
| 7489 | 7471 |
| 7490 | 7472 |
| 7491 bool Isolate::WillAutorunMicrotasks() const { | 7473 bool Isolate::WillAutorunMicrotasks() const { |
| 7492 return GetMicrotasksPolicy() == MicrotasksPolicy::kAuto; | 7474 return reinterpret_cast<const i::Isolate*>(this)->autorun_microtasks(); |
| 7493 } | 7475 } |
| 7494 | 7476 |
| 7495 | 7477 |
| 7496 void Isolate::SetMicrotasksPolicy(MicrotasksPolicy policy) { | |
| 7497 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | |
| 7498 isolate->handle_scope_implementer()->set_microtasks_policy(policy); | |
| 7499 } | |
| 7500 | |
| 7501 | |
| 7502 MicrotasksPolicy Isolate::GetMicrotasksPolicy() const { | |
| 7503 i::Isolate* isolate = | |
| 7504 reinterpret_cast<i::Isolate*>(const_cast<Isolate*>(this)); | |
| 7505 return isolate->handle_scope_implementer()->microtasks_policy(); | |
| 7506 } | |
| 7507 | |
| 7508 | |
| 7509 void Isolate::AddMicrotasksCompletedCallback( | 7478 void Isolate::AddMicrotasksCompletedCallback( |
| 7510 MicrotasksCompletedCallback callback) { | 7479 MicrotasksCompletedCallback callback) { |
| 7511 DCHECK(callback); | 7480 DCHECK(callback); |
| 7512 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7481 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7513 isolate->AddMicrotasksCompletedCallback(callback); | 7482 isolate->AddMicrotasksCompletedCallback(callback); |
| 7514 } | 7483 } |
| 7515 | 7484 |
| 7516 | 7485 |
| 7517 void Isolate::RemoveMicrotasksCompletedCallback( | 7486 void Isolate::RemoveMicrotasksCompletedCallback( |
| 7518 MicrotasksCompletedCallback callback) { | 7487 MicrotasksCompletedCallback callback) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7734 | 7703 |
| 7735 void Isolate::VisitWeakHandles(PersistentHandleVisitor* visitor) { | 7704 void Isolate::VisitWeakHandles(PersistentHandleVisitor* visitor) { |
| 7736 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7705 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7737 i::DisallowHeapAllocation no_allocation; | 7706 i::DisallowHeapAllocation no_allocation; |
| 7738 VisitorAdapter visitor_adapter(visitor); | 7707 VisitorAdapter visitor_adapter(visitor); |
| 7739 isolate->global_handles()->IterateWeakRootsInNewSpaceWithClassIds( | 7708 isolate->global_handles()->IterateWeakRootsInNewSpaceWithClassIds( |
| 7740 &visitor_adapter); | 7709 &visitor_adapter); |
| 7741 } | 7710 } |
| 7742 | 7711 |
| 7743 | 7712 |
| 7744 MicrotasksScope::MicrotasksScope(Isolate* isolate, MicrotasksScope::Type type) | |
| 7745 : isolate_(reinterpret_cast<i::Isolate*>(isolate)), | |
| 7746 run_(type == MicrotasksScope::kRunMicrotasks) { | |
| 7747 auto handle_scope_implementer = isolate_->handle_scope_implementer(); | |
| 7748 if (run_) handle_scope_implementer->IncrementMicrotasksScopeDepth(); | |
| 7749 #ifdef V8_ENABLE_CHECKS | |
| 7750 if (!run_) handle_scope_implementer->IncrementDebugMicrotasksScopeDepth(); | |
| 7751 #endif | |
| 7752 } | |
| 7753 | |
| 7754 | |
| 7755 MicrotasksScope::~MicrotasksScope() { | |
| 7756 auto handle_scope_implementer = isolate_->handle_scope_implementer(); | |
| 7757 if (run_) { | |
| 7758 handle_scope_implementer->DecrementMicrotasksScopeDepth(); | |
| 7759 if (MicrotasksPolicy::kScoped == | |
| 7760 handle_scope_implementer->microtasks_policy()) { | |
| 7761 PerformCheckpoint(reinterpret_cast<Isolate*>(isolate_)); | |
| 7762 } | |
| 7763 } | |
| 7764 #ifdef V8_ENABLE_CHECKS | |
| 7765 if (!run_) handle_scope_implementer->DecrementDebugMicrotasksScopeDepth(); | |
| 7766 #endif | |
| 7767 } | |
| 7768 | |
| 7769 | |
| 7770 void MicrotasksScope::PerformCheckpoint(Isolate* v8Isolate) { | |
| 7771 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8Isolate); | |
| 7772 if (IsExecutionTerminatingCheck(isolate)) return; | |
| 7773 auto handle_scope_implementer = isolate->handle_scope_implementer(); | |
| 7774 if (!handle_scope_implementer->GetMicrotasksScopeDepth() && | |
| 7775 !handle_scope_implementer->HasMicrotasksSuppressions()) { | |
| 7776 isolate->RunMicrotasks(); | |
| 7777 } | |
| 7778 } | |
| 7779 | |
| 7780 | |
| 7781 int MicrotasksScope::GetCurrentDepth(Isolate* v8Isolate) { | |
| 7782 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8Isolate); | |
| 7783 return isolate->handle_scope_implementer()->GetMicrotasksScopeDepth(); | |
| 7784 } | |
| 7785 | |
| 7786 | |
| 7787 String::Utf8Value::Utf8Value(v8::Local<v8::Value> obj) | 7713 String::Utf8Value::Utf8Value(v8::Local<v8::Value> obj) |
| 7788 : str_(NULL), length_(0) { | 7714 : str_(NULL), length_(0) { |
| 7789 if (obj.IsEmpty()) return; | 7715 if (obj.IsEmpty()) return; |
| 7790 i::Isolate* isolate = i::Isolate::Current(); | 7716 i::Isolate* isolate = i::Isolate::Current(); |
| 7791 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); | 7717 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); |
| 7792 ENTER_V8(isolate); | 7718 ENTER_V8(isolate); |
| 7793 i::HandleScope scope(isolate); | 7719 i::HandleScope scope(isolate); |
| 7794 Local<Context> context = v8_isolate->GetCurrentContext(); | 7720 Local<Context> context = v8_isolate->GetCurrentContext(); |
| 7795 TryCatch try_catch(v8_isolate); | 7721 TryCatch try_catch(v8_isolate); |
| 7796 Local<String> str; | 7722 Local<String> str; |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8695 Address callback_address = | 8621 Address callback_address = |
| 8696 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8622 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8697 VMState<EXTERNAL> state(isolate); | 8623 VMState<EXTERNAL> state(isolate); |
| 8698 ExternalCallbackScope call_scope(isolate, callback_address); | 8624 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8699 callback(info); | 8625 callback(info); |
| 8700 } | 8626 } |
| 8701 | 8627 |
| 8702 | 8628 |
| 8703 } // namespace internal | 8629 } // namespace internal |
| 8704 } // namespace v8 | 8630 } // namespace v8 |
| OLD | NEW |