v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-promise.h
Go to the documentation of this file.
1// Copyright 2021 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 INCLUDE_V8_PROMISE_H_
6#define INCLUDE_V8_PROMISE_H_
7
8#include "v8-local-handle.h" // NOLINT(build/include_directory)
9#include "v8-object.h" // NOLINT(build/include_directory)
10#include "v8config.h" // NOLINT(build/include_directory)
11
12namespace v8 {
13
14class Context;
15
16#ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
17// Defined using gn arg `v8_promise_internal_field_count`.
18#define V8_PROMISE_INTERNAL_FIELD_COUNT 0
19#endif
20
24class V8_EXPORT Promise : public Object {
25 public:
30 enum PromiseState { kPending, kFulfilled, kRejected };
31
32 class V8_EXPORT Resolver : public Object {
33 public:
38 Local<Context> context);
39
43 Local<Promise> GetPromise();
44
50 Local<Value> value);
51
53 Local<Value> value);
54
55 V8_INLINE static Resolver* Cast(Value* value) {
56#ifdef V8_ENABLE_CHECKS
57 CheckCast(value);
58#endif
59 return static_cast<Promise::Resolver*>(value);
60 }
61
62 private:
64 static void CheckCast(Value* obj);
65 };
66
74 Local<Function> handler);
75
77 Local<Function> handler);
78
80 Local<Function> on_fulfilled,
81 Local<Function> on_rejected);
82
87 bool HasHandler() const;
88
93 Local<Value> Result();
94
98 PromiseState State();
99
103 void MarkAsHandled();
104
109 void MarkAsSilent();
110
111 V8_INLINE static Promise* Cast(Value* value) {
112#ifdef V8_ENABLE_CHECKS
113 CheckCast(value);
114#endif
115 return static_cast<Promise*>(value);
116 }
117
118 static constexpr int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
119
120 private:
122 static void CheckCast(Value* obj);
123};
124
142
144 Local<Value> parent);
145
146// --- Promise Reject Callback ---
153
169
171
172} // namespace v8
173
174#endif // INCLUDE_V8_PROMISE_H_
Local< Value > value_
Definition v8-promise.h:167
Local< Promise > promise_
Definition v8-promise.h:165
PromiseRejectEvent event_
Definition v8-promise.h:166
PromiseRejectMessage(Local< Promise > promise, PromiseRejectEvent event, Local< Value > value)
Definition v8-promise.h:156
V8_INLINE Local< Promise > GetPromise() const
Definition v8-promise.h:160
V8_INLINE PromiseRejectEvent GetEvent() const
Definition v8-promise.h:161
V8_INLINE Local< Value > GetValue() const
Definition v8-promise.h:162
static V8_INLINE Resolver * Cast(Value *value)
Definition v8-promise.h:55
static V8_INLINE Promise * Cast(Value *value)
Definition v8-promise.h:111
PromiseRejectEvent
Definition v8-promise.h:147
@ kPromiseHandlerAddedAfterReject
Definition v8-promise.h:149
@ kPromiseRejectWithNoHandler
Definition v8-promise.h:148
@ kPromiseRejectAfterResolved
Definition v8-promise.h:150
@ kPromiseResolveAfterResolved
Definition v8-promise.h:151
void(*)(PromiseRejectMessage message) PromiseRejectCallback
Definition v8-promise.h:170
void(*)(PromiseHookType type, Local< Promise > promise, Local< Value > parent) PromiseHook
Definition v8-promise.h:143
PromiseHookType
Definition v8-promise.h:141
#define V8_EXPORT
Definition v8config.h:800
#define V8_INLINE
Definition v8config.h:500
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671
std::unique_ptr< ValueMirror > value
wasm::ValueType type