v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
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_PROMISE_H_
6#define V8_OBJECTS_PROMISE_H_
7
9
10// Has to be the last include (doesn't have include guards):
12
13namespace v8 {
14namespace internal {
15
16class JSPromise;
17class StructBodyDescriptor;
18
19#include "torque-generated/src/objects/promise-tq.inc"
20
21// Struct to hold state required for PromiseReactionJob. See the comment on the
22// PromiseReaction below for details on how this is being managed to reduce the
23// memory and allocation overhead. This is the base class for the concrete
24//
25// - PromiseFulfillReactionJobTask
26// - PromiseRejectReactionJobTask
27//
28// classes, which are used to represent either reactions, and we distinguish
29// them by their instance types.
31 : public TorqueGeneratedPromiseReactionJobTask<PromiseReactionJobTask,
32 Microtask> {
33 public:
34 static const int kSizeOfAllPromiseReactionJobTasks = kHeaderSize;
35
37
39};
40
41// Struct to hold state required for a PromiseReactionJob of type "Fulfill".
43 : public TorqueGeneratedPromiseFulfillReactionJobTask<
44 PromiseFulfillReactionJobTask, PromiseReactionJobTask> {
45 public:
46 static_assert(kSize == kSizeOfAllPromiseReactionJobTasks);
47
49
51};
52
53// Struct to hold state required for a PromiseReactionJob of type "Reject".
55 : public TorqueGeneratedPromiseRejectReactionJobTask<
56 PromiseRejectReactionJobTask, PromiseReactionJobTask> {
57 public:
58 static_assert(kSize == kSizeOfAllPromiseReactionJobTasks);
59
61
63};
64
65// A container struct to hold state required for PromiseResolveThenableJob.
67 : public TorqueGeneratedPromiseResolveThenableJobTask<
68 PromiseResolveThenableJobTask, Microtask> {
69 public:
71
73};
74
75// Struct to hold the state of a PromiseCapability.
77 : public TorqueGeneratedPromiseCapability<PromiseCapability, Struct> {
78 public:
80
82};
83
84// A representation of promise reaction. This differs from the specification
85// in that the PromiseReaction here holds both handlers for the fulfill and
86// the reject case. When a JSPromise is eventually resolved (either via
87// fulfilling it or rejecting it), we morph this PromiseReaction object in
88// memory into a proper PromiseReactionJobTask and schedule it on the queue
89// of microtasks. So the size of PromiseReaction and the size of the
90// PromiseReactionJobTask has to be same for this to work.
91//
92// The PromiseReaction::promise_or_capability field can either hold a JSPromise
93// instance (in the fast case of a native promise) or a PromiseCapability in
94// case of a Promise subclass. In case of await it can also be undefined if
95// PromiseHooks are disabled (see https://github.com/tc39/ecma262/pull/1146).
96//
97// The PromiseReaction objects form a singly-linked list, terminated by
98// Smi 0. On the JSPromise instance they are linked in reverse order,
99// and are turned into the proper order again when scheduling them on
100// the microtask queue.
102 : public TorqueGeneratedPromiseReaction<PromiseReaction, Struct> {
103 public:
105
107
109};
110
111} // namespace internal
112} // namespace v8
113
115
116#endif // V8_OBJECTS_PROMISE_H_
static const int kSizeOfAllPromiseReactionJobTasks
Definition promise.h:34
#define TQ_OBJECT_CONSTRUCTORS(Type)