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