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

Side by Side Diff: src/isolate.cc

Issue 2575313002: [promisehook] Implement PromiseHook (Closed)
Patch Set: add tests Created 4 years 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
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/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 2133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 regexp_stack_(NULL), 2144 regexp_stack_(NULL),
2145 date_cache_(NULL), 2145 date_cache_(NULL),
2146 call_descriptor_data_(NULL), 2146 call_descriptor_data_(NULL),
2147 // TODO(bmeurer) Initialized lazily because it depends on flags; can 2147 // TODO(bmeurer) Initialized lazily because it depends on flags; can
2148 // be fixed once the default isolate cleanup is done. 2148 // be fixed once the default isolate cleanup is done.
2149 random_number_generator_(NULL), 2149 random_number_generator_(NULL),
2150 rail_mode_(PERFORMANCE_ANIMATION), 2150 rail_mode_(PERFORMANCE_ANIMATION),
2151 serializer_enabled_(enable_serializer), 2151 serializer_enabled_(enable_serializer),
2152 has_fatal_error_(false), 2152 has_fatal_error_(false),
2153 initialized_from_snapshot_(false), 2153 initialized_from_snapshot_(false),
2154 is_promisehook_enabled_(false), 2154 is_promise_hook_enabled_(false),
2155 is_tail_call_elimination_enabled_(true), 2155 is_tail_call_elimination_enabled_(true),
2156 is_isolate_in_background_(false), 2156 is_isolate_in_background_(false),
2157 cpu_profiler_(NULL), 2157 cpu_profiler_(NULL),
2158 heap_profiler_(NULL), 2158 heap_profiler_(NULL),
2159 code_event_dispatcher_(new CodeEventDispatcher()), 2159 code_event_dispatcher_(new CodeEventDispatcher()),
2160 function_entry_hook_(NULL), 2160 function_entry_hook_(NULL),
2161 deferred_handles_head_(NULL), 2161 deferred_handles_head_(NULL),
2162 optimizing_compile_dispatcher_(NULL), 2162 optimizing_compile_dispatcher_(NULL),
2163 stress_deopt_count_(0), 2163 stress_deopt_count_(0),
2164 next_optimization_id_(0), 2164 next_optimization_id_(0),
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
3161 3161
3162 if (call_completed_callbacks_.is_empty()) return; 3162 if (call_completed_callbacks_.is_empty()) return;
3163 // Fire callbacks. Increase call depth to prevent recursive callbacks. 3163 // Fire callbacks. Increase call depth to prevent recursive callbacks.
3164 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this); 3164 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this);
3165 v8::Isolate::SuppressMicrotaskExecutionScope suppress(isolate); 3165 v8::Isolate::SuppressMicrotaskExecutionScope suppress(isolate);
3166 for (int i = 0; i < call_completed_callbacks_.length(); i++) { 3166 for (int i = 0; i < call_completed_callbacks_.length(); i++) {
3167 call_completed_callbacks_.at(i)(isolate); 3167 call_completed_callbacks_.at(i)(isolate);
3168 } 3168 }
3169 } 3169 }
3170 3170
3171 void Isolate::EnablePromiseHook() { is_promisehook_enabled_ = true; } 3171 void Isolate::SetPromiseHook(PromiseHook hook) {
3172 is_promise_hook_enabled_ = hook != nullptr;
adamk 2016/12/15 08:46:09 Is there a reason we still need to track this sepa
gsathya 2016/12/15 15:35:33 I thought the boolean was cleaner. Changed.
adamk 2016/12/15 15:43:58 I prefer this way to avoid having to do extra book
3173 set_promise_hook(hook);
3174 }
3172 3175
3173 void Isolate::DisablePromiseHook() { is_promisehook_enabled_ = false; } 3176 void Isolate::RunPromiseHook(PromiseHookType type, Handle<JSObject> promise,
3177 Handle<Object> parent) {
3178 if (!is_promise_hook_enabled_) return;
3179 PromiseHook hook = promise_hook();
3180 HandleScope scope(this);
adamk 2016/12/15 08:46:09 Where is this called from where there isn't alread
gsathya 2016/12/15 15:35:33 I don't create handlescopes in the runtime functio
adamk 2016/12/15 15:43:58 Ah, you should create HandleScopes there :)
3181 hook(type, v8::Utils::PromiseToLocal(promise), v8::Utils::ToLocal(parent));
3182 }
3174 3183
3175 void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) { 3184 void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) {
3176 promise_reject_callback_ = callback; 3185 promise_reject_callback_ = callback;
3177 } 3186 }
3178 3187
3179 3188
3180 void Isolate::ReportPromiseReject(Handle<JSObject> promise, 3189 void Isolate::ReportPromiseReject(Handle<JSObject> promise,
3181 Handle<Object> value, 3190 Handle<Object> value,
3182 v8::PromiseRejectEvent event) { 3191 v8::PromiseRejectEvent event) {
3183 if (promise_reject_callback_ == NULL) return; 3192 if (promise_reject_callback_ == NULL) return;
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
3567 // Then check whether this scope intercepts. 3576 // Then check whether this scope intercepts.
3568 if ((flag & intercept_mask_)) { 3577 if ((flag & intercept_mask_)) {
3569 intercepted_flags_ |= flag; 3578 intercepted_flags_ |= flag;
3570 return true; 3579 return true;
3571 } 3580 }
3572 return false; 3581 return false;
3573 } 3582 }
3574 3583
3575 } // namespace internal 3584 } // namespace internal
3576 } // namespace v8 3585 } // namespace v8
OLDNEW
« src/builtins/builtins-promise.cc ('K') | « src/isolate.h ('k') | src/js/async-await.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698