Chromium Code Reviews| Index: src/builtins/builtins-promise.cc |
| diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc |
| index 987604930d8c91868eb26bcbd601f13bc3ba6aa0..4f3c30e26242e9ffa2bbd7f9e1493305665df34b 100644 |
| --- a/src/builtins/builtins-promise.cc |
| +++ b/src/builtins/builtins-promise.cc |
| @@ -1,34 +1,30 @@ |
| // Copyright 2016 the V8 project authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| + |
| #include "src/builtins/builtins-utils.h" |
| #include "src/builtins/builtins.h" |
| +#include "src/promise-utils.h" |
| + |
| namespace v8 { |
| namespace internal { |
| -enum PromiseResolvingFunctionContextSlot { |
| - kAlreadyVisitedSlot = Context::MIN_CONTEXT_SLOTS, |
| - kPromiseSlot, |
| - kDebugEventSlot, |
| - kPromiseContextLength, |
| -}; |
| - |
| // ES#sec-promise-resolve-functions |
| // Promise Resolve Functions |
| BUILTIN(PromiseResolveClosure) { |
| HandleScope scope(isolate); |
| Handle<Context> context(isolate->context(), isolate); |
| - Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)), |
| - isolate); |
| + Handle<Smi> already_visited = |
| + PromiseUtils::GetAlreadyVisited(isolate, context); |
|
adamk
2016/11/10 18:10:54
How about making GetAlreadyVisited() return a bool
gsathya
2016/11/11 02:34:36
Done.
|
| if (already_visited->value() != 0) { |
| return isolate->heap()->undefined_value(); |
| } |
| - context->set(kAlreadyVisitedSlot, Smi::FromInt(1)); |
| - Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate); |
| + PromiseUtils::SetAlreadyVisitedToTrue(context); |
| + Handle<JSObject> promise = PromiseUtils::GetPromise(isolate, context); |
| Handle<Object> value = args.atOrUndefined(isolate, 1); |
| MaybeHandle<Object> maybe_result; |
| @@ -46,18 +42,17 @@ BUILTIN(PromiseRejectClosure) { |
| HandleScope scope(isolate); |
| Handle<Context> context(isolate->context(), isolate); |
| - Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)), |
| - isolate); |
| + Handle<Smi> already_visited = |
| + PromiseUtils::GetAlreadyVisited(isolate, context); |
| if (already_visited->value() != 0) { |
| return isolate->heap()->undefined_value(); |
| } |
| - context->set(kAlreadyVisitedSlot, Smi::FromInt(1)); |
| - |
| + PromiseUtils::SetAlreadyVisitedToTrue(context); |
| Handle<Object> value = args.atOrUndefined(isolate, 1); |
| - Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate); |
| - Handle<Object> debug_event(context->get(kDebugEventSlot), isolate); |
| + Handle<JSObject> promise = PromiseUtils::GetPromise(isolate, context); |
| + Handle<Object> debug_event = PromiseUtils::GetDebugEvent(isolate, context); |
| MaybeHandle<Object> maybe_result; |
| Handle<Object> argv[] = {promise, value, debug_event}; |
| RETURN_FAILURE_ON_EXCEPTION( |
| @@ -75,31 +70,10 @@ BUILTIN(CreateResolvingFunctions) { |
| Handle<JSObject> promise = args.at<JSObject>(1); |
| Handle<Object> debug_event = args.at<Object>(2); |
|
adamk
2016/11/10 18:10:54
Can you add a DCHECK(debug_event->IsTrue() || debu
gsathya
2016/11/11 02:34:36
Done.
|
| + Handle<JSFunction> resolve, reject; |
| - Handle<Context> context = |
| - isolate->factory()->NewPromiseResolvingFunctionContext( |
| - kPromiseContextLength); |
| - context->set_native_context(*isolate->native_context()); |
| - context->set(kAlreadyVisitedSlot, Smi::kZero); |
| - context->set(kPromiseSlot, *promise); |
| - context->set(kDebugEventSlot, *debug_event); |
| - |
| - Handle<SharedFunctionInfo> resolve_shared_fun( |
| - isolate->native_context()->promise_resolve_shared_fun(), isolate); |
| - Handle<JSFunction> resolve = |
| - isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| - isolate->sloppy_function_without_prototype_map(), resolve_shared_fun, |
| - isolate->native_context(), TENURED); |
| - |
| - Handle<SharedFunctionInfo> reject_shared_fun( |
| - isolate->native_context()->promise_reject_shared_fun(), isolate); |
| - Handle<JSFunction> reject = |
| - isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| - isolate->sloppy_function_without_prototype_map(), reject_shared_fun, |
| - isolate->native_context(), TENURED); |
| - |
| - resolve->set_context(*context); |
| - reject->set_context(*context); |
| + PromiseUtils::CreateResolvingFunctions(isolate, promise, debug_event, |
| + &resolve, &reject); |
| Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); |
| result->set(0, *resolve); |