| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) | 80 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) |
| 81 | 81 |
| 82 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, class_name, \ | 82 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, class_name, \ |
| 83 function_name, bailout_value, \ | 83 function_name, bailout_value, \ |
| 84 HandleScopeClass, do_callback) \ | 84 HandleScopeClass, do_callback) \ |
| 85 if (IsExecutionTerminatingCheck(isolate)) { \ | 85 if (IsExecutionTerminatingCheck(isolate)) { \ |
| 86 return bailout_value; \ | 86 return bailout_value; \ |
| 87 } \ | 87 } \ |
| 88 HandleScopeClass handle_scope(isolate); \ | 88 HandleScopeClass handle_scope(isolate); \ |
| 89 CallDepthScope<do_callback> call_depth_scope(isolate, context); \ | 89 CallDepthScope call_depth_scope(isolate, context, do_callback); \ |
| 90 LOG_API(isolate, class_name, function_name); \ | 90 LOG_API(isolate, class_name, function_name); \ |
| 91 ENTER_V8(isolate); \ | 91 ENTER_V8(isolate); \ |
| 92 bool has_pending_exception = false | 92 bool has_pending_exception = false |
| 93 | 93 |
| 94 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ | 94 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ |
| 95 bailout_value, HandleScopeClass, \ | 95 bailout_value, HandleScopeClass, \ |
| 96 do_callback) \ | 96 do_callback) \ |
| 97 auto isolate = context.IsEmpty() \ | 97 auto isolate = context.IsEmpty() \ |
| 98 ? i::Isolate::Current() \ | 98 ? i::Isolate::Current() \ |
| 99 : reinterpret_cast<i::Isolate*>(context->GetIsolate()); \ | 99 : reinterpret_cast<i::Isolate*>(context->GetIsolate()); \ |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void CheckMicrotasksScopesConsistency(i::Isolate* isolate) { | 163 void CheckMicrotasksScopesConsistency(i::Isolate* isolate) { |
| 164 auto handle_scope_implementer = isolate->handle_scope_implementer(); | 164 auto handle_scope_implementer = isolate->handle_scope_implementer(); |
| 165 if (handle_scope_implementer->microtasks_policy() == | 165 if (handle_scope_implementer->microtasks_policy() == |
| 166 v8::MicrotasksPolicy::kScoped) { | 166 v8::MicrotasksPolicy::kScoped) { |
| 167 DCHECK(handle_scope_implementer->GetMicrotasksScopeDepth() || | 167 DCHECK(handle_scope_implementer->GetMicrotasksScopeDepth() || |
| 168 !handle_scope_implementer->DebugMicrotasksScopeDepthIsZero()); | 168 !handle_scope_implementer->DebugMicrotasksScopeDepthIsZero()); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 #endif | 171 #endif |
| 172 | 172 |
| 173 template <bool do_callback> | 173 |
| 174 class CallDepthScope { | 174 class CallDepthScope { |
| 175 public: | 175 public: |
| 176 explicit CallDepthScope(i::Isolate* isolate, Local<Context> context) | 176 explicit CallDepthScope(i::Isolate* isolate, Local<Context> context, |
| 177 : isolate_(isolate), context_(context), escaped_(false) { | 177 bool do_callback) |
| 178 : isolate_(isolate), |
| 179 context_(context), |
| 180 escaped_(false), |
| 181 do_callback_(do_callback) { |
| 178 // TODO(dcarney): remove this when blink stops crashing. | 182 // TODO(dcarney): remove this when blink stops crashing. |
| 179 DCHECK(!isolate_->external_caught_exception()); | 183 DCHECK(!isolate_->external_caught_exception()); |
| 180 isolate_->IncrementJsCallsFromApiCounter(); | 184 isolate_->IncrementJsCallsFromApiCounter(); |
| 181 isolate_->handle_scope_implementer()->IncrementCallDepth(); | 185 isolate_->handle_scope_implementer()->IncrementCallDepth(); |
| 182 if (!context.IsEmpty()) { | 186 if (!context.IsEmpty()) { |
| 183 i::Handle<i::Context> env = Utils::OpenHandle(*context); | 187 i::Handle<i::Context> env = Utils::OpenHandle(*context); |
| 184 i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); | 188 i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); |
| 185 if (isolate->context() != nullptr && | 189 if (isolate->context() != nullptr && |
| 186 isolate->context()->native_context() == env->native_context() && | 190 isolate->context()->native_context() == env->native_context() && |
| 187 impl->LastEnteredContextWas(env)) { | 191 impl->LastEnteredContextWas(env)) { |
| 188 context_ = Local<Context>(); | 192 context_ = Local<Context>(); |
| 189 } else { | 193 } else { |
| 190 context_->Enter(); | 194 context_->Enter(); |
| 191 } | 195 } |
| 192 } | 196 } |
| 193 if (do_callback) isolate_->FireBeforeCallEnteredCallback(); | 197 if (do_callback_) isolate_->FireBeforeCallEnteredCallback(); |
| 194 } | 198 } |
| 195 ~CallDepthScope() { | 199 ~CallDepthScope() { |
| 196 if (!context_.IsEmpty()) context_->Exit(); | 200 if (!context_.IsEmpty()) context_->Exit(); |
| 197 if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth(); | 201 if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth(); |
| 198 if (do_callback) isolate_->FireCallCompletedCallback(); | 202 if (do_callback_) isolate_->FireCallCompletedCallback(); |
| 199 #ifdef DEBUG | 203 #ifdef DEBUG |
| 200 if (do_callback) CheckMicrotasksScopesConsistency(isolate_); | 204 if (do_callback_) CheckMicrotasksScopesConsistency(isolate_); |
| 201 #endif | 205 #endif |
| 202 } | 206 } |
| 203 | 207 |
| 204 void Escape() { | 208 void Escape() { |
| 205 DCHECK(!escaped_); | 209 DCHECK(!escaped_); |
| 206 escaped_ = true; | 210 escaped_ = true; |
| 207 auto handle_scope_implementer = isolate_->handle_scope_implementer(); | 211 auto handle_scope_implementer = isolate_->handle_scope_implementer(); |
| 208 handle_scope_implementer->DecrementCallDepth(); | 212 handle_scope_implementer->DecrementCallDepth(); |
| 209 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); | 213 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); |
| 210 isolate_->OptionalRescheduleException(call_depth_is_zero); | 214 isolate_->OptionalRescheduleException(call_depth_is_zero); |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 Utils::ApiCheck((*escape_slot_)->IsTheHole(heap->isolate()), | 902 Utils::ApiCheck((*escape_slot_)->IsTheHole(heap->isolate()), |
| 899 "EscapableHandleScope::Escape", "Escape value set twice"); | 903 "EscapableHandleScope::Escape", "Escape value set twice"); |
| 900 if (escape_value == NULL) { | 904 if (escape_value == NULL) { |
| 901 *escape_slot_ = heap->undefined_value(); | 905 *escape_slot_ = heap->undefined_value(); |
| 902 return NULL; | 906 return NULL; |
| 903 } | 907 } |
| 904 *escape_slot_ = *escape_value; | 908 *escape_slot_ = *escape_value; |
| 905 return escape_slot_; | 909 return escape_slot_; |
| 906 } | 910 } |
| 907 | 911 |
| 908 SealHandleScope::SealHandleScope(Isolate* isolate) | 912 |
| 909 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) { | 913 SealHandleScope::SealHandleScope(Isolate* isolate) { |
| 910 i::HandleScopeData* current = isolate_->handle_scope_data(); | 914 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 915 |
| 916 isolate_ = internal_isolate; |
| 917 i::HandleScopeData* current = internal_isolate->handle_scope_data(); |
| 911 prev_limit_ = current->limit; | 918 prev_limit_ = current->limit; |
| 912 current->limit = current->next; | 919 current->limit = current->next; |
| 913 prev_sealed_level_ = current->sealed_level; | 920 prev_sealed_level_ = current->sealed_level; |
| 914 current->sealed_level = current->level; | 921 current->sealed_level = current->level; |
| 915 } | 922 } |
| 916 | 923 |
| 917 | 924 |
| 918 SealHandleScope::~SealHandleScope() { | 925 SealHandleScope::~SealHandleScope() { |
| 919 i::HandleScopeData* current = isolate_->handle_scope_data(); | 926 i::HandleScopeData* current = isolate_->handle_scope_data(); |
| 920 DCHECK_EQ(current->next, current->limit); | 927 DCHECK_EQ(current->next, current->limit); |
| (...skipping 8063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8984 Address callback_address = | 8991 Address callback_address = |
| 8985 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8992 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8986 VMState<EXTERNAL> state(isolate); | 8993 VMState<EXTERNAL> state(isolate); |
| 8987 ExternalCallbackScope call_scope(isolate, callback_address); | 8994 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8988 callback(info); | 8995 callback(info); |
| 8989 } | 8996 } |
| 8990 | 8997 |
| 8991 | 8998 |
| 8992 } // namespace internal | 8999 } // namespace internal |
| 8993 } // namespace v8 | 9000 } // namespace v8 |
| OLD | NEW |