Loading...
Searching...
No Matches
v8-exception.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_EXCEPTION_H_
6#define INCLUDE_V8_EXCEPTION_H_
7
8#include <stddef.h>
9
10#include "v8-local-handle.h" // NOLINT(build/include_directory)
11#include "v8-object.h" // NOLINT(build/include_directory)
12#include "v8config.h" // NOLINT(build/include_directory)
13
14namespace v8 {
15
16class Context;
17class Isolate;
18class Message;
19class StackTrace;
20class String;
21class Value;
22
23namespace internal {
24class Isolate;
25class ThreadLocalTop;
26} // namespace internal
27
33 public:
35 Local<Value> options = {});
37 Local<Value> options = {});
39 Local<Value> options = {});
41 Local<Value> options = {});
43 Local<Value> options = {});
45 Local<Value> options = {});
47 Local<Value> options = {});
48 static Local<Value> Error(Local<String> message, Local<Value> options = {});
49
55 static Local<Message> CreateMessage(Isolate* isolate, Local<Value> exception);
56
62
68 Local<Object> object);
69};
70
76enum class ExceptionContext : uint32_t {
95};
96
103 public:
105 Local<String> interface_name,
106 Local<String> property_name,
107 ExceptionContext exception_context)
108 : isolate_(isolate),
109 exception_(exception),
110 interface_name_(interface_name),
111 property_name_(property_name),
112 exception_context_(exception_context) {}
113
114 V8_INLINE Isolate* GetIsolate() const { return isolate_; }
115 V8_INLINE Local<Object> GetException() const { return exception_; }
116 V8_INLINE Local<String> GetInterfaceName() const { return interface_name_; }
117 V8_INLINE Local<String> GetPropertyName() const { return property_name_; }
119 return exception_context_;
120 }
121
122 private:
123 Isolate* isolate_;
124 Local<Object> exception_;
125 Local<String> interface_name_;
126 Local<String> property_name_;
127 ExceptionContext exception_context_;
128};
129
131 void (*)(ExceptionPropagationMessage message);
132
137 public:
143 explicit TryCatch(Isolate* isolate);
144
149
153 bool HasCaught() const;
154
163 bool CanContinue() const;
164
177 bool HasTerminated() const;
178
187
193
199 Local<Context> context, Local<Value> exception);
200
207 Local<Context> context) const;
208
214
225 void Reset();
226
235 void SetVerbose(bool value);
236
240 bool IsVerbose() const;
241
247 void SetCaptureMessage(bool value);
248
249 TryCatch(const TryCatch&) = delete;
250 void operator=(const TryCatch&) = delete;
251
252 private:
253 // Declaring operator new and delete as deleted is not spec compliant.
254 // Therefore declare them private instead to disable dynamic alloc
255 void* operator new(size_t size);
256 void* operator new[](size_t size);
257 void operator delete(void*, size_t);
258 void operator delete[](void*, size_t);
259
271 internal::Address JSStackComparableAddressPrivate() {
272 return js_stack_comparable_address_;
273 }
274
275 void ResetInternal();
276
277 internal::Isolate* i_isolate_;
278 TryCatch* next_;
279 void* exception_;
280 void* message_obj_;
281 internal::Address js_stack_comparable_address_;
282 bool is_verbose_ : 1;
283 bool can_continue_ : 1;
284 bool capture_message_ : 1;
285 bool rethrow_ : 1;
286
287 friend class internal::Isolate;
288 friend class internal::ThreadLocalTop;
289};
290
291} // namespace v8
292
293#endif // INCLUDE_V8_EXCEPTION_H_
Definition: v8-exception.h:102
Local< String > GetPropertyName() const
Definition: v8-exception.h:117
Isolate * GetIsolate() const
Definition: v8-exception.h:114
Local< Object > GetException() const
Definition: v8-exception.h:115
Local< String > GetInterfaceName() const
Definition: v8-exception.h:116
ExceptionContext GetExceptionContext() const
Definition: v8-exception.h:118
ExceptionPropagationMessage(v8::Isolate *isolate, Local< Object > exception, Local< String > interface_name, Local< String > property_name, ExceptionContext exception_context)
Definition: v8-exception.h:104
Definition: v8-exception.h:32
static Maybe< bool > CaptureStackTrace(Local< Context > context, Local< Object > object)
static Local< Message > CreateMessage(Isolate *isolate, Local< Value > exception)
static Local< StackTrace > GetStackTrace(Local< Value > exception)
static Local< Value > RangeError(Local< String > message, Local< Value > options={})
static Local< Value > TypeError(Local< String > message, Local< Value > options={})
static Local< Value > WasmRuntimeError(Local< String > message, Local< Value > options={})
static Local< Value > ReferenceError(Local< String > message, Local< Value > options={})
static Local< Value > WasmCompileError(Local< String > message, Local< Value > options={})
static Local< Value > SyntaxError(Local< String > message, Local< Value > options={})
static Local< Value > WasmLinkError(Local< String > message, Local< Value > options={})
static Local< Value > Error(Local< String > message, Local< Value > options={})
Definition: v8-isolate.h:212
Definition: v8-local-handle.h:266
Definition: v8-local-handle.h:632
Definition: v8-maybe.h:32
Definition: v8-exception.h:136
void SetVerbose(bool value)
Local< v8::Message > Message() const
bool HasTerminated() const
MaybeLocal< Value > StackTrace(Local< Context > context) const
void SetCaptureMessage(bool value)
TryCatch(Isolate *isolate)
TryCatch(const TryCatch &)=delete
static MaybeLocal< Value > StackTrace(Local< Context > context, Local< Value > exception)
void operator=(const TryCatch &)=delete
Local< Value > ReThrow()
bool IsVerbose() const
Local< Value > Exception() const
bool HasCaught() const
bool CanContinue() const
uintptr_t Address
Definition: v8-internal.h:51
Definition: libplatform.h:15
void(*)(ExceptionPropagationMessage message) ExceptionPropagationCallback
Definition: v8-exception.h:131
ExceptionContext
Definition: v8-exception.h:76
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:660