Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/api.cc

Issue 2220993003: [api] Templatize do_callback parameter in CallDepthScope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: formatting Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/v8.h ('k') | src/isolate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 call_depth_scope(isolate, context, do_callback); \ 89 CallDepthScope<do_callback> call_depth_scope(isolate, context); \
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
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 173 template <bool do_callback>
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 bool do_callback) 177 : isolate_(isolate), context_(context), escaped_(false) {
178 : isolate_(isolate),
179 context_(context),
180 escaped_(false),
181 do_callback_(do_callback) {
182 // TODO(dcarney): remove this when blink stops crashing. 178 // TODO(dcarney): remove this when blink stops crashing.
183 DCHECK(!isolate_->external_caught_exception()); 179 DCHECK(!isolate_->external_caught_exception());
184 isolate_->IncrementJsCallsFromApiCounter(); 180 isolate_->IncrementJsCallsFromApiCounter();
185 isolate_->handle_scope_implementer()->IncrementCallDepth(); 181 isolate_->handle_scope_implementer()->IncrementCallDepth();
186 if (!context.IsEmpty()) { 182 if (!context.IsEmpty()) {
187 i::Handle<i::Context> env = Utils::OpenHandle(*context); 183 i::Handle<i::Context> env = Utils::OpenHandle(*context);
188 i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); 184 i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
189 if (isolate->context() != nullptr && 185 if (isolate->context() != nullptr &&
190 isolate->context()->native_context() == env->native_context() && 186 isolate->context()->native_context() == env->native_context() &&
191 impl->LastEnteredContextWas(env)) { 187 impl->LastEnteredContextWas(env)) {
192 context_ = Local<Context>(); 188 context_ = Local<Context>();
193 } else { 189 } else {
194 context_->Enter(); 190 context_->Enter();
195 } 191 }
196 } 192 }
197 if (do_callback_) isolate_->FireBeforeCallEnteredCallback(); 193 if (do_callback) isolate_->FireBeforeCallEnteredCallback();
198 } 194 }
199 ~CallDepthScope() { 195 ~CallDepthScope() {
200 if (!context_.IsEmpty()) context_->Exit(); 196 if (!context_.IsEmpty()) context_->Exit();
201 if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth(); 197 if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth();
202 if (do_callback_) isolate_->FireCallCompletedCallback(); 198 if (do_callback) isolate_->FireCallCompletedCallback();
203 #ifdef DEBUG 199 #ifdef DEBUG
204 if (do_callback_) CheckMicrotasksScopesConsistency(isolate_); 200 if (do_callback) CheckMicrotasksScopesConsistency(isolate_);
205 #endif 201 #endif
206 } 202 }
207 203
208 void Escape() { 204 void Escape() {
209 DCHECK(!escaped_); 205 DCHECK(!escaped_);
210 escaped_ = true; 206 escaped_ = true;
211 auto handle_scope_implementer = isolate_->handle_scope_implementer(); 207 auto handle_scope_implementer = isolate_->handle_scope_implementer();
212 handle_scope_implementer->DecrementCallDepth(); 208 handle_scope_implementer->DecrementCallDepth();
213 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); 209 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero();
214 isolate_->OptionalRescheduleException(call_depth_is_zero); 210 isolate_->OptionalRescheduleException(call_depth_is_zero);
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 Utils::ApiCheck((*escape_slot_)->IsTheHole(heap->isolate()), 898 Utils::ApiCheck((*escape_slot_)->IsTheHole(heap->isolate()),
903 "EscapableHandleScope::Escape", "Escape value set twice"); 899 "EscapableHandleScope::Escape", "Escape value set twice");
904 if (escape_value == NULL) { 900 if (escape_value == NULL) {
905 *escape_slot_ = heap->undefined_value(); 901 *escape_slot_ = heap->undefined_value();
906 return NULL; 902 return NULL;
907 } 903 }
908 *escape_slot_ = *escape_value; 904 *escape_slot_ = *escape_value;
909 return escape_slot_; 905 return escape_slot_;
910 } 906 }
911 907
912 908 SealHandleScope::SealHandleScope(Isolate* isolate)
913 SealHandleScope::SealHandleScope(Isolate* isolate) { 909 : isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
914 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 910 i::HandleScopeData* current = isolate_->handle_scope_data();
915
916 isolate_ = internal_isolate;
917 i::HandleScopeData* current = internal_isolate->handle_scope_data();
918 prev_limit_ = current->limit; 911 prev_limit_ = current->limit;
919 current->limit = current->next; 912 current->limit = current->next;
920 prev_sealed_level_ = current->sealed_level; 913 prev_sealed_level_ = current->sealed_level;
921 current->sealed_level = current->level; 914 current->sealed_level = current->level;
922 } 915 }
923 916
924 917
925 SealHandleScope::~SealHandleScope() { 918 SealHandleScope::~SealHandleScope() {
926 i::HandleScopeData* current = isolate_->handle_scope_data(); 919 i::HandleScopeData* current = isolate_->handle_scope_data();
927 DCHECK_EQ(current->next, current->limit); 920 DCHECK_EQ(current->next, current->limit);
(...skipping 8063 matching lines...) Expand 10 before | Expand all | Expand 10 after
8991 Address callback_address = 8984 Address callback_address =
8992 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8985 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8993 VMState<EXTERNAL> state(isolate); 8986 VMState<EXTERNAL> state(isolate);
8994 ExternalCallbackScope call_scope(isolate, callback_address); 8987 ExternalCallbackScope call_scope(isolate, callback_address);
8995 callback(info); 8988 callback(info);
8996 } 8989 }
8997 8990
8998 8991
8999 } // namespace internal 8992 } // namespace internal
9000 } // namespace v8 8993 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698