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