Commit d37c407a authored by jgruber's avatar jgruber Committed by Commit bot

[async-await] Move PromiseCreate and PromiseRelease to TF

BUG=v8:5639

Review-Url: https://codereview.chromium.org/2638073002
Cr-Commit-Position: refs/heads/master@{#42508}
parent d22934bd
......@@ -969,6 +969,7 @@ v8_source_set("v8_base") {
"src/builtins/builtins-api.cc",
"src/builtins/builtins-array.cc",
"src/builtins/builtins-arraybuffer.cc",
"src/builtins/builtins-async-function.cc",
"src/builtins/builtins-async.cc",
"src/builtins/builtins-async.h",
"src/builtins/builtins-boolean.cc",
......
......@@ -3385,6 +3385,22 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
Builtins::kGeneratorPrototypeThrow, 1, true);
async_function_next->shared()->set_native(false);
async_function_throw->shared()->set_native(false);
{
Handle<JSFunction> function = SimpleCreateFunction(
isolate, factory->empty_string(),
Builtins::kAsyncFunctionPromiseCreate, 0, false);
InstallWithIntrinsicDefaultProto(
isolate, function, Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX);
}
{
Handle<JSFunction> function = SimpleCreateFunction(
isolate, factory->empty_string(),
Builtins::kAsyncFunctionPromiseRelease, 1, false);
InstallWithIntrinsicDefaultProto(
isolate, function, Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX);
}
}
}
......
// Copyright 2017 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-promise.h"
#include "src/builtins/builtins-utils.h"
#include "src/builtins/builtins.h"
#include "src/code-stub-assembler.h"
namespace v8 {
namespace internal {
typedef compiler::Node Node;
typedef CodeStubAssembler::ParameterMode ParameterMode;
typedef compiler::CodeAssemblerState CodeAssemblerState;
class AsyncFunctionBuiltinsAssembler : public PromiseBuiltinsAssembler {
public:
explicit AsyncFunctionBuiltinsAssembler(CodeAssemblerState* state)
: PromiseBuiltinsAssembler(state) {}
};
TF_BUILTIN(AsyncFunctionPromiseCreate, AsyncFunctionBuiltinsAssembler) {
CSA_ASSERT_JS_ARGC_EQ(this, 0);
Node* const context = Parameter(3);
Node* const promise = AllocateAndInitJSPromise(context);
Label if_is_debug_active(this, Label::kDeferred);
GotoIf(IsDebugActive(), &if_is_debug_active);
// Early exit if debug is not active.
Return(promise);
Bind(&if_is_debug_active);
{
// Push the Promise under construction in an async function on
// the catch prediction stack to handle exceptions thrown before
// the first await.
// Assign ID and create a recurring task to save stack for future
// resumptions from await.
CallRuntime(Runtime::kDebugAsyncFunctionPromiseCreated, context, promise);
Return(promise);
}
}
TF_BUILTIN(AsyncFunctionPromiseRelease, AsyncFunctionBuiltinsAssembler) {
CSA_ASSERT_JS_ARGC_EQ(this, 1);
Node* const promise = Parameter(1);
Node* const context = Parameter(4);
Label if_is_debug_active(this, Label::kDeferred);
GotoIf(IsDebugActive(), &if_is_debug_active);
// Early exit if debug is not active.
Return(UndefinedConstant());
Bind(&if_is_debug_active);
{
// Pop the Promise under construction in an async function on
// from catch prediction stack.
CallRuntime(Runtime::kDebugPopPromise, context);
Return(promise);
}
}
} // namespace internal
} // namespace v8
......@@ -274,6 +274,10 @@ namespace internal {
CPP(ArrayBufferPrototypeGetByteLength) \
CPP(ArrayBufferIsView) \
\
/* AsyncFunction */ \
TFJ(AsyncFunctionPromiseCreate, 0) \
TFJ(AsyncFunctionPromiseRelease, 1) \
\
/* Boolean */ \
CPP(BooleanConstructor) \
CPP(BooleanConstructor_ConstructStub) \
......
......@@ -106,32 +106,9 @@ function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) {
AsyncFunctionAwait(generator, awaited, outerPromise);
}
function AsyncFunctionPromiseCreate() {
var promise = %promise_internal_constructor(UNDEFINED);
if (DEBUG_IS_ACTIVE) {
// Push the Promise under construction in an async function on
// the catch prediction stack to handle exceptions thrown before
// the first await.
// Assign ID and create a recurring task to save stack for future
// resumptions from await.
%DebugAsyncFunctionPromiseCreated(promise);
}
return promise;
}
function AsyncFunctionPromiseRelease(promise) {
if (DEBUG_IS_ACTIVE) {
// Pop the Promise under construction in an async function on
// from catch prediction stack.
%DebugPopPromise();
}
}
%InstallToContext([
"async_function_await_caught", AsyncFunctionAwaitCaught,
"async_function_await_uncaught", AsyncFunctionAwaitUncaught,
"async_function_promise_create", AsyncFunctionPromiseCreate,
"async_function_promise_release", AsyncFunctionPromiseRelease,
]);
})
......@@ -480,6 +480,7 @@
'builtins/builtins-api.cc',
'builtins/builtins-arraybuffer.cc',
'builtins/builtins-array.cc',
'builtins/builtins-async-function.cc',
'builtins/builtins-async.cc',
'builtins/builtins-async.h',
'builtins/builtins-boolean.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment