| Index: src/builtins/builtins-promise.cc
|
| diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc
|
| index 987604930d8c91868eb26bcbd601f13bc3ba6aa0..9f5d7c88d7885e8bfbcefe65fdc80c729301b305 100644
|
| --- a/src/builtins/builtins-promise.cc
|
| +++ b/src/builtins/builtins-promise.cc
|
| @@ -1,34 +1,28 @@
|
| // 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);
|
|
|
| - if (already_visited->value() != 0) {
|
| + if (PromiseUtils::HasAlreadyVisited(context)) {
|
| return isolate->heap()->undefined_value();
|
| }
|
|
|
| - context->set(kAlreadyVisitedSlot, Smi::FromInt(1));
|
| - Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate);
|
| + PromiseUtils::SetAlreadyVisited(context);
|
| + Handle<JSObject> promise = handle(PromiseUtils::GetPromise(context), isolate);
|
| Handle<Object> value = args.atOrUndefined(isolate, 1);
|
|
|
| MaybeHandle<Object> maybe_result;
|
| @@ -46,18 +40,16 @@ BUILTIN(PromiseRejectClosure) {
|
| HandleScope scope(isolate);
|
|
|
| Handle<Context> context(isolate->context(), isolate);
|
| - Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)),
|
| - isolate);
|
|
|
| - if (already_visited->value() != 0) {
|
| + if (PromiseUtils::HasAlreadyVisited(context)) {
|
| return isolate->heap()->undefined_value();
|
| }
|
|
|
| - context->set(kAlreadyVisitedSlot, Smi::FromInt(1));
|
| -
|
| + PromiseUtils::SetAlreadyVisited(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 = handle(PromiseUtils::GetPromise(context), isolate);
|
| + Handle<Object> debug_event =
|
| + handle(PromiseUtils::GetDebugEvent(context), isolate);
|
| MaybeHandle<Object> maybe_result;
|
| Handle<Object> argv[] = {promise, value, debug_event};
|
| RETURN_FAILURE_ON_EXCEPTION(
|
| @@ -75,31 +67,10 @@ BUILTIN(CreateResolvingFunctions) {
|
|
|
| Handle<JSObject> promise = args.at<JSObject>(1);
|
| Handle<Object> debug_event = args.at<Object>(2);
|
| + 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);
|
|
|