v8/src/builtins/builtins-async-module.cc
Joshua Litt 798cb9045c Reland "[top-level-await] Implement top-level-await in V8"
The first land did not correctly handle exceptions for already evaluated
modules.

Original description:
Implements AsyncModules in SourceTextModule. However, there is no
support in the parser or D8 for actually creating / resolving
AsyncModules. Also adds a flag '--top-level-await,' but the only
external facing change with the flag enabled is that Module::Evaluate
returns a promise.

Bug: v8:9344
Change-Id: I24725816ee4a6c3616c3c8b08a75a60ca9f27727
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1797658
Commit-Queue: Joshua Litt <joshualitt@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63803}
2019-09-16 15:29:17 +00:00

34 lines
1.1 KiB
C++

// Copyright 2019 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-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/objects-inl.h"
namespace v8 {
namespace internal {
BUILTIN(CallAsyncModuleFulfilled) {
HandleScope handle_scope(isolate);
Handle<SourceTextModule> module(
isolate->global_handles()->Create(*args.at<SourceTextModule>(0)));
SourceTextModule::AsyncModuleExecutionFulfilled(isolate, module);
return ReadOnlyRoots(isolate).undefined_value();
}
BUILTIN(CallAsyncModuleRejected) {
HandleScope handle_scope(isolate);
// Arguments should be a SourceTextModule and an exception object.
DCHECK_EQ(args.length(), 2);
Handle<SourceTextModule> module(
isolate->global_handles()->Create(*args.at<SourceTextModule>(0)));
Handle<Object> exception(args.at(1));
SourceTextModule::AsyncModuleExecutionRejected(isolate, module, exception);
return ReadOnlyRoots(isolate).undefined_value();
}
} // namespace internal
} // namespace v8