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> |
11 | |
12 #include "src/ast/context-slot-cache.h" | 11 #include "src/ast/context-slot-cache.h" |
13 #include "src/base/hashmap.h" | 12 #include "src/base/hashmap.h" |
14 #include "src/base/platform/platform.h" | 13 #include "src/base/platform/platform.h" |
15 #include "src/base/sys-info.h" | 14 #include "src/base/sys-info.h" |
16 #include "src/base/utils/random-number-generator.h" | 15 #include "src/base/utils/random-number-generator.h" |
17 #include "src/basic-block-profiler.h" | 16 #include "src/basic-block-profiler.h" |
18 #include "src/bootstrapper.h" | 17 #include "src/bootstrapper.h" |
19 #include "src/cancelable-task.h" | 18 #include "src/cancelable-task.h" |
20 #include "src/codegen.h" | 19 #include "src/codegen.h" |
21 #include "src/compilation-cache.h" | 20 #include "src/compilation-cache.h" |
22 #include "src/compilation-statistics.h" | 21 #include "src/compilation-statistics.h" |
23 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" | 22 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" |
24 #include "src/crankshaft/hydrogen.h" | 23 #include "src/crankshaft/hydrogen.h" |
25 #include "src/debug/debug.h" | 24 #include "src/debug/debug.h" |
26 #include "src/deoptimizer.h" | 25 #include "src/deoptimizer.h" |
| 26 #include "src/elements.h" |
27 #include "src/external-reference-table.h" | 27 #include "src/external-reference-table.h" |
28 #include "src/frames-inl.h" | 28 #include "src/frames-inl.h" |
29 #include "src/ic/access-compiler-data.h" | 29 #include "src/ic/access-compiler-data.h" |
30 #include "src/ic/stub-cache.h" | 30 #include "src/ic/stub-cache.h" |
31 #include "src/interface-descriptors.h" | 31 #include "src/interface-descriptors.h" |
32 #include "src/interpreter/interpreter.h" | 32 #include "src/interpreter/interpreter.h" |
33 #include "src/isolate-inl.h" | 33 #include "src/isolate-inl.h" |
34 #include "src/libsampler/sampler.h" | 34 #include "src/libsampler/sampler.h" |
35 #include "src/log.h" | 35 #include "src/log.h" |
36 #include "src/messages.h" | 36 #include "src/messages.h" |
(...skipping 2964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3001 if (promise_reject_callback_ == NULL) return; | 3001 if (promise_reject_callback_ == NULL) return; |
3002 Handle<JSArray> stack_trace; | 3002 Handle<JSArray> stack_trace; |
3003 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { | 3003 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { |
3004 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); | 3004 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); |
3005 } | 3005 } |
3006 promise_reject_callback_(v8::PromiseRejectMessage( | 3006 promise_reject_callback_(v8::PromiseRejectMessage( |
3007 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), | 3007 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), |
3008 v8::Utils::StackTraceToLocal(stack_trace))); | 3008 v8::Utils::StackTraceToLocal(stack_trace))); |
3009 } | 3009 } |
3010 | 3010 |
| 3011 void Isolate::PromiseReactionJob(Handle<PromiseHandleInfo> promise_handle_info, |
| 3012 MaybeHandle<Object>* result, |
| 3013 MaybeHandle<Object>* maybe_exception) { |
| 3014 if (debug()->is_active()) { |
| 3015 Handle<Object> before_debug_event(promise_handle_info->before_debug_event(), |
| 3016 this); |
| 3017 if (before_debug_event->IsJSObject()) { |
| 3018 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(before_debug_event)); |
| 3019 } |
| 3020 } |
| 3021 |
| 3022 Handle<Object> value(promise_handle_info->value(), this); |
| 3023 Handle<Object> tasks(promise_handle_info->tasks(), this); |
| 3024 |
| 3025 if (tasks->IsJSArray()) { |
| 3026 Handle<JSArray> array = Handle<JSArray>::cast(tasks); |
| 3027 DCHECK(array->length()->IsSmi()); |
| 3028 Handle<FixedArrayBase> elements(array->elements(), this); |
| 3029 // Safer way to get length? Check backing store? |
| 3030 int length = elements->length(); |
| 3031 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 3032 for (int i = 0; i < length; i += 2) { |
| 3033 // Do I need the check? |
| 3034 if (accessor->HasElement(array, i, elements) && |
| 3035 accessor->HasElement(array, i + 1, elements)) { |
| 3036 Handle<Object> argv[] = {value, accessor->Get(array, i), |
| 3037 accessor->Get(array, i + 1)}; |
| 3038 *result = Execution::TryCall(this, promise_handle(), |
| 3039 factory()->undefined_value(), |
| 3040 arraysize(argv), argv, maybe_exception); |
| 3041 } |
| 3042 } |
| 3043 } else { |
| 3044 Handle<Object> deferreds(promise_handle_info->deferreds(), this); |
| 3045 Handle<Object> argv[] = {value, tasks, deferreds}; |
| 3046 *result = |
| 3047 Execution::TryCall(this, promise_handle(), factory()->undefined_value(), |
| 3048 arraysize(argv), argv, maybe_exception); |
| 3049 } |
| 3050 |
| 3051 if (debug()->is_active()) { |
| 3052 Handle<Object> after_debug_event(promise_handle_info->after_debug_event(), |
| 3053 this); |
| 3054 if (after_debug_event->IsJSObject()) { |
| 3055 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(after_debug_event)); |
| 3056 } |
| 3057 } |
| 3058 } |
| 3059 |
3011 void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container, | 3060 void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container, |
3012 MaybeHandle<Object>* result, | 3061 MaybeHandle<Object>* result, |
3013 MaybeHandle<Object>* maybe_exception) { | 3062 MaybeHandle<Object>* maybe_exception) { |
3014 if (debug()->is_active()) { | 3063 if (debug()->is_active()) { |
3015 Handle<Object> before_debug_event(container->before_debug_event(), this); | 3064 Handle<Object> before_debug_event(container->before_debug_event(), this); |
3016 if (before_debug_event->IsJSObject()) { | 3065 if (before_debug_event->IsJSObject()) { |
3017 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(before_debug_event)); | 3066 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(before_debug_event)); |
3018 } | 3067 } |
3019 } | 3068 } |
3020 | 3069 |
(...skipping 16 matching lines...) Expand all Loading... |
3037 | 3086 |
3038 if (debug()->is_active()) { | 3087 if (debug()->is_active()) { |
3039 Handle<Object> after_debug_event(container->after_debug_event(), this); | 3088 Handle<Object> after_debug_event(container->after_debug_event(), this); |
3040 if (after_debug_event->IsJSObject()) { | 3089 if (after_debug_event->IsJSObject()) { |
3041 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(after_debug_event)); | 3090 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(after_debug_event)); |
3042 } | 3091 } |
3043 } | 3092 } |
3044 } | 3093 } |
3045 | 3094 |
3046 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { | 3095 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { |
| 3096 // TODO(gsathya): remove IsJSFunction? |
3047 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() || | 3097 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() || |
3048 microtask->IsPromiseContainer()); | 3098 microtask->IsPromiseContainer() || microtask->IsPromiseHandleInfo()); |
3049 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 3099 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
3050 int num_tasks = pending_microtask_count(); | 3100 int num_tasks = pending_microtask_count(); |
3051 DCHECK(num_tasks <= queue->length()); | 3101 DCHECK(num_tasks <= queue->length()); |
3052 if (num_tasks == 0) { | 3102 if (num_tasks == 0) { |
3053 queue = factory()->NewFixedArray(8); | 3103 queue = factory()->NewFixedArray(8); |
3054 heap()->set_microtask_queue(*queue); | 3104 heap()->set_microtask_queue(*queue); |
3055 } else if (num_tasks == queue->length()) { | 3105 } else if (num_tasks == queue->length()) { |
3056 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); | 3106 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); |
3057 heap()->set_microtask_queue(*queue); | 3107 heap()->set_microtask_queue(*queue); |
3058 } | 3108 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3090 | 3140 |
3091 if (microtask->IsCallHandlerInfo()) { | 3141 if (microtask->IsCallHandlerInfo()) { |
3092 Handle<CallHandlerInfo> callback_info = | 3142 Handle<CallHandlerInfo> callback_info = |
3093 Handle<CallHandlerInfo>::cast(microtask); | 3143 Handle<CallHandlerInfo>::cast(microtask); |
3094 v8::MicrotaskCallback callback = | 3144 v8::MicrotaskCallback callback = |
3095 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); | 3145 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); |
3096 void* data = v8::ToCData<void*>(callback_info->data()); | 3146 void* data = v8::ToCData<void*>(callback_info->data()); |
3097 callback(data); | 3147 callback(data); |
3098 } else { | 3148 } else { |
3099 SaveContext save(this); | 3149 SaveContext save(this); |
3100 Context* context = microtask->IsJSFunction() | 3150 Context* context; |
3101 ? Handle<JSFunction>::cast(microtask)->context() | 3151 if (microtask->IsJSFunction()) { |
3102 : Handle<PromiseContainer>::cast(microtask) | 3152 context = Handle<JSFunction>::cast(microtask)->context(); |
3103 ->resolve() | 3153 } else if (microtask->IsPromiseContainer()) { |
3104 ->context(); | 3154 context = |
| 3155 Handle<PromiseContainer>::cast(microtask)->resolve()->context(); |
| 3156 } else { |
| 3157 context = Handle<PromiseHandleInfo>::cast(microtask) |
| 3158 ->reaction_context() |
| 3159 ->context(); |
| 3160 } |
| 3161 |
3105 set_context(context->native_context()); | 3162 set_context(context->native_context()); |
3106 handle_scope_implementer_->EnterMicrotaskContext( | 3163 handle_scope_implementer_->EnterMicrotaskContext( |
3107 Handle<Context>(context, this)); | 3164 Handle<Context>(context, this)); |
3108 | 3165 |
3109 MaybeHandle<Object> result; | 3166 MaybeHandle<Object> result; |
3110 MaybeHandle<Object> maybe_exception; | 3167 MaybeHandle<Object> maybe_exception; |
3111 | 3168 |
3112 if (microtask->IsJSFunction()) { | 3169 if (microtask->IsJSFunction()) { |
3113 Handle<JSFunction> microtask_function = | 3170 Handle<JSFunction> microtask_function = |
3114 Handle<JSFunction>::cast(microtask); | 3171 Handle<JSFunction>::cast(microtask); |
3115 result = Execution::TryCall(this, microtask_function, | 3172 result = Execution::TryCall(this, microtask_function, |
3116 factory()->undefined_value(), 0, NULL, | 3173 factory()->undefined_value(), 0, NULL, |
3117 &maybe_exception); | 3174 &maybe_exception); |
3118 } else { | 3175 } else if (microtask->IsPromiseContainer()) { |
3119 PromiseResolveThenableJob(Handle<PromiseContainer>::cast(microtask), | 3176 PromiseResolveThenableJob(Handle<PromiseContainer>::cast(microtask), |
3120 &result, &maybe_exception); | 3177 &result, &maybe_exception); |
| 3178 } else if (microtask->IsPromiseHandleInfo()) { |
| 3179 PromiseReactionJob(Handle<PromiseHandleInfo>::cast(microtask), |
| 3180 &result, &maybe_exception); |
3121 } | 3181 } |
3122 | 3182 |
3123 handle_scope_implementer_->LeaveMicrotaskContext(); | 3183 handle_scope_implementer_->LeaveMicrotaskContext(); |
3124 | 3184 |
3125 // If execution is terminating, just bail out. | 3185 // If execution is terminating, just bail out. |
3126 if (result.is_null() && maybe_exception.is_null()) { | 3186 if (result.is_null() && maybe_exception.is_null()) { |
3127 // Clear out any remaining callbacks in the queue. | 3187 // Clear out any remaining callbacks in the queue. |
3128 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 3188 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
3129 set_pending_microtask_count(0); | 3189 set_pending_microtask_count(0); |
3130 return; | 3190 return; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3323 // Then check whether this scope intercepts. | 3383 // Then check whether this scope intercepts. |
3324 if ((flag & intercept_mask_)) { | 3384 if ((flag & intercept_mask_)) { |
3325 intercepted_flags_ |= flag; | 3385 intercepted_flags_ |= flag; |
3326 return true; | 3386 return true; |
3327 } | 3387 } |
3328 return false; | 3388 return false; |
3329 } | 3389 } |
3330 | 3390 |
3331 } // namespace internal | 3391 } // namespace internal |
3332 } // namespace v8 | 3392 } // namespace v8 |
OLD | NEW |