1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/builtins/builtins-utils-inl.h"
6#include "src/objects/module-inl.h"
7#include "src/objects/objects-inl.h"
8
9namespace v8 {
10namespace internal {
11
12BUILTIN(CallAsyncModuleFulfilled) {
13  HandleScope handle_scope(isolate);
14  Handle<SourceTextModule> module(args.at<SourceTextModule>(0));
15  if (SourceTextModule::AsyncModuleExecutionFulfilled(isolate, module)
16          .IsNothing()) {
17    // The evaluation of async module can not throwing a JavaScript observable
18    // exception.
19    DCHECK(isolate->has_pending_exception());
20    DCHECK_EQ(isolate->pending_exception(),
21              ReadOnlyRoots(isolate).termination_exception());
22    return ReadOnlyRoots(isolate).exception();
23  }
24  return ReadOnlyRoots(isolate).undefined_value();
25}
26
27BUILTIN(CallAsyncModuleRejected) {
28  HandleScope handle_scope(isolate);
29
30  // Arguments should be a SourceTextModule and an exception object.
31  DCHECK_EQ(args.length(), 2);
32  Handle<SourceTextModule> module(args.at<SourceTextModule>(0));
33  Handle<Object> exception(args.at(1));
34  SourceTextModule::AsyncModuleExecutionRejected(isolate, module, exception);
35  return ReadOnlyRoots(isolate).undefined_value();
36}
37
38}  // namespace internal
39}  // namespace v8
40