v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-promise.h
Go to the documentation of this file.
1// Copyright 2018 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#ifndef V8_OBJECTS_JS_PROMISE_H_
6#define V8_OBJECTS_JS_PROMISE_H_
7
10#include "src/objects/promise.h"
11#include "torque-generated/bit-fields.h"
12
13// Has to be the last include (doesn't have include guards):
15
16namespace v8 {
17namespace internal {
18
19#include "torque-generated/src/objects/js-promise-tq.inc"
20
21// Representation of promise objects in the specification. Our layout of
22// JSPromise differs a bit from the layout in the specification, for example
23// there's only a single list of PromiseReaction objects, instead of separate
24// lists for fulfill and reject reactions. The PromiseReaction carries both
25// callbacks from the start, and is eventually morphed into the proper kind of
26// PromiseReactionJobTask when the JSPromise is settled.
27//
28// We also overlay the result and reactions fields on the JSPromise, since
29// the reactions are only necessary for pending promises, whereas the result
30// is only meaningful for settled promises.
32 : public TorqueGeneratedJSPromise<JSPromise, JSObjectWithEmbedderSlots> {
33 public:
34 static constexpr uint32_t kInvalidAsyncTaskId = 0;
35
36 // [result]: Checks that the promise is settled and returns the result.
37 inline Tagged<Object> result() const;
38
39 // [reactions]: Checks that the promise is pending and returns the reactions.
40 inline Tagged<Object> reactions() const;
41
42 // [has_handler]: Whether this promise has a reject handler or not.
43 DECL_BOOLEAN_ACCESSORS(has_handler)
44
45 // [is_silent]: Whether this promise should cause the debugger to pause when
46 // rejected.
47 DECL_BOOLEAN_ACCESSORS(is_silent)
48
49 inline bool has_async_task_id() const;
50 inline uint32_t async_task_id() const;
51 inline void set_async_task_id(uint32_t id);
52 // Computes next valid async task ID, silently wrapping around max
53 // value and skipping invalid (zero) ID.
54 static inline uint32_t GetNextAsyncTaskId(uint32_t current_async_task_id);
55
56 static const char* Status(Promise::PromiseState status);
59
60 // ES section #sec-fulfillpromise
63 // ES section #sec-rejectpromise
66 bool debug_event = true);
67 // ES section #sec-promise-resolve-functions
70
71 // Dispatched behavior.
74
75 static const int kSizeWithEmbedderFields =
76 kHeaderSize + v8::Promise::kEmbedderFieldCount * kEmbedderDataSlotSize;
77
78 // Flags layout.
79 DEFINE_TORQUE_GENERATED_JS_PROMISE_FLAGS()
80
81 static_assert(v8::Promise::kPending == 0);
82 static_assert(v8::Promise::kFulfilled == 1);
83 static_assert(v8::Promise::kRejected == 2);
84
85 private:
86 // ES section #sec-triggerpromisereactions
89 DirectHandle<Object> argument,
90 PromiseReaction::Type type);
91
93};
94
95} // namespace internal
96} // namespace v8
97
98#include "src/objects/object-macros-undef.h"
99
100#endif // V8_OBJECTS_JS_PROMISE_H_
Tagged< Object > reactions() const
static const char * Status(Promise::PromiseState status)
Definition objects.cc:5005
uint32_t async_task_id() const
static const int kSizeWithEmbedderFields
Definition js-promise.h:75
static Handle< Object > Reject(DirectHandle< JSPromise > promise, DirectHandle< Object > reason, bool debug_event=true)
Definition objects.cc:5069
Tagged< Object > result() const
bool has_async_task_id() const
static constexpr uint32_t kInvalidAsyncTaskId
Definition js-promise.h:34
void set_status(Promise::PromiseState status)
Definition objects.cc:4999
static Handle< Object > TriggerPromiseReactions(Isolate *isolate, DirectHandle< Object > reactions, DirectHandle< Object > argument, PromiseReaction::Type type)
Definition objects.cc:5205
void set_async_task_id(uint32_t id)
static V8_WARN_UNUSED_RESULT MaybeHandle< Object > Resolve(DirectHandle< JSPromise > promise, DirectHandle< Object > resolution)
Definition objects.cc:5109
static V8_EXPORT_PRIVATE Handle< Object > Fulfill(DirectHandle< JSPromise > promise, DirectHandle< Object > value)
Definition objects.cc:5018
static uint32_t GetNextAsyncTaskId(uint32_t current_async_task_id)
V8_EXPORT_PRIVATE Promise::PromiseState status() const
Definition objects.cc:4993
constexpr int kEmbedderDataSlotSize
Definition globals.h:664
#define DECL_VERIFIER(Name)
#define DECL_BOOLEAN_ACCESSORS(name)
#define DECL_PRINTER(Name)
#define TQ_OBJECT_CONSTRUCTORS(Type)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671