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/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 3052 matching lines...) Loading... | |
3063 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); | 3063 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); |
3064 } | 3064 } |
3065 promise_reject_callback_(v8::PromiseRejectMessage( | 3065 promise_reject_callback_(v8::PromiseRejectMessage( |
3066 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), | 3066 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), |
3067 v8::Utils::StackTraceToLocal(stack_trace))); | 3067 v8::Utils::StackTraceToLocal(stack_trace))); |
3068 } | 3068 } |
3069 | 3069 |
3070 namespace { | 3070 namespace { |
3071 class PromiseDebugEventScope { | 3071 class PromiseDebugEventScope { |
3072 public: | 3072 public: |
3073 PromiseDebugEventScope(Isolate* isolate, Object* before, Object* after) | 3073 PromiseDebugEventScope(Isolate* isolate, Object* id, Object* name) |
3074 : isolate_(isolate), | 3074 : isolate_(isolate), |
3075 after_(after, isolate_), | 3075 id_(id, isolate_), |
3076 name_(name, isolate_), | |
3076 is_debug_active_(isolate_->debug()->is_active() && | 3077 is_debug_active_(isolate_->debug()->is_active() && |
3077 before->IsJSObject() && after->IsJSObject()) { | 3078 !id_->IsUndefined(isolate_) && |
3079 !name_->IsUndefined(isolate_)) { | |
3078 if (is_debug_active_) { | 3080 if (is_debug_active_) { |
3081 static const char will_handle[] = "willHandle"; | |
adamk
2016/10/13 15:59:10
Rather than recreating a string for this every tim
gsathya
2016/10/13 21:27:30
Done.
| |
3079 isolate_->debug()->OnAsyncTaskEvent( | 3082 isolate_->debug()->OnAsyncTaskEvent( |
3080 handle(JSObject::cast(before), isolate_)); | 3083 isolate_->factory()->NewStringFromAsciiChecked(will_handle), id_, |
3084 name_); | |
3081 } | 3085 } |
3082 } | 3086 } |
3083 | 3087 |
3084 ~PromiseDebugEventScope() { | 3088 ~PromiseDebugEventScope() { |
3085 if (is_debug_active_) { | 3089 if (is_debug_active_) { |
3086 isolate_->debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(after_)); | 3090 static const char did_handle[] = "didHandle"; |
3091 isolate_->debug()->OnAsyncTaskEvent( | |
3092 isolate_->factory()->NewStringFromAsciiChecked(did_handle), id_, | |
3093 name_); | |
3087 } | 3094 } |
3088 } | 3095 } |
3089 | 3096 |
3090 private: | 3097 private: |
3091 Isolate* isolate_; | 3098 Isolate* isolate_; |
3092 Handle<Object> after_; | 3099 Handle<Object> id_; |
3100 Handle<Object> name_; | |
3093 bool is_debug_active_; | 3101 bool is_debug_active_; |
3094 }; | 3102 }; |
3095 } // namespace | 3103 } // namespace |
3096 | 3104 |
3097 void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info, | 3105 void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info, |
3098 MaybeHandle<Object>* result, | 3106 MaybeHandle<Object>* result, |
3099 MaybeHandle<Object>* maybe_exception) { | 3107 MaybeHandle<Object>* maybe_exception) { |
3100 PromiseDebugEventScope helper(this, info->before_debug_event(), | 3108 PromiseDebugEventScope helper(this, info->id(), info->name()); |
3101 info->after_debug_event()); | |
3102 | 3109 |
3103 Handle<Object> value(info->value(), this); | 3110 Handle<Object> value(info->value(), this); |
3104 Handle<Object> tasks(info->tasks(), this); | 3111 Handle<Object> tasks(info->tasks(), this); |
3105 Handle<JSFunction> promise_handle_fn = promise_handle(); | 3112 Handle<JSFunction> promise_handle_fn = promise_handle(); |
3106 Handle<Object> undefined = factory()->undefined_value(); | 3113 Handle<Object> undefined = factory()->undefined_value(); |
3107 | 3114 |
3108 // If tasks is an array we have multiple onFulfilled/onRejected callbacks | 3115 // If tasks is an array we have multiple onFulfilled/onRejected callbacks |
3109 // associated with the promise. The deferred object for each callback | 3116 // associated with the promise. The deferred object for each callback |
3110 // is attached to this array as well. | 3117 // is attached to this array as well. |
3111 // Otherwise, there is a single callback and the deferred object is attached | 3118 // Otherwise, there is a single callback and the deferred object is attached |
(...skipping 20 matching lines...) Loading... | |
3132 Handle<Object> deferred(info->deferred(), this); | 3139 Handle<Object> deferred(info->deferred(), this); |
3133 Handle<Object> argv[] = {value, tasks, deferred}; | 3140 Handle<Object> argv[] = {value, tasks, deferred}; |
3134 *result = Execution::TryCall(this, promise_handle_fn, undefined, | 3141 *result = Execution::TryCall(this, promise_handle_fn, undefined, |
3135 arraysize(argv), argv, maybe_exception); | 3142 arraysize(argv), argv, maybe_exception); |
3136 } | 3143 } |
3137 } | 3144 } |
3138 | 3145 |
3139 void Isolate::PromiseResolveThenableJob( | 3146 void Isolate::PromiseResolveThenableJob( |
3140 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, | 3147 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, |
3141 MaybeHandle<Object>* maybe_exception) { | 3148 MaybeHandle<Object>* maybe_exception) { |
3142 PromiseDebugEventScope helper(this, info->before_debug_event(), | 3149 PromiseDebugEventScope helper(this, info->id(), info->name()); |
3143 info->after_debug_event()); | |
3144 | 3150 |
3145 Handle<JSReceiver> thenable(info->thenable(), this); | 3151 Handle<JSReceiver> thenable(info->thenable(), this); |
3146 Handle<JSFunction> resolve(info->resolve(), this); | 3152 Handle<JSFunction> resolve(info->resolve(), this); |
3147 Handle<JSFunction> reject(info->reject(), this); | 3153 Handle<JSFunction> reject(info->reject(), this); |
3148 Handle<JSReceiver> then(info->then(), this); | 3154 Handle<JSReceiver> then(info->then(), this); |
3149 Handle<Object> argv[] = {resolve, reject}; | 3155 Handle<Object> argv[] = {resolve, reject}; |
3150 *result = Execution::TryCall(this, then, thenable, arraysize(argv), argv, | 3156 *result = Execution::TryCall(this, then, thenable, arraysize(argv), argv, |
3151 maybe_exception); | 3157 maybe_exception); |
3152 | 3158 |
3153 Handle<Object> reason; | 3159 Handle<Object> reason; |
(...skipping 297 matching lines...) Loading... | |
3451 // Then check whether this scope intercepts. | 3457 // Then check whether this scope intercepts. |
3452 if ((flag & intercept_mask_)) { | 3458 if ((flag & intercept_mask_)) { |
3453 intercepted_flags_ |= flag; | 3459 intercepted_flags_ |= flag; |
3454 return true; | 3460 return true; |
3455 } | 3461 } |
3456 return false; | 3462 return false; |
3457 } | 3463 } |
3458 | 3464 |
3459 } // namespace internal | 3465 } // namespace internal |
3460 } // namespace v8 | 3466 } // namespace v8 |
OLD | NEW |