v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
pending-compilation-error-handler.h
Go to the documentation of this file.
1// Copyright 2015 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_PARSING_PENDING_COMPILATION_ERROR_HANDLER_H_
6#define V8_PARSING_PENDING_COMPILATION_ERROR_HANDLER_H_
7
8#include <forward_list>
9
11#include "src/base/macros.h"
12#include "src/common/globals.h"
14#include "src/handles/handles.h"
15
16namespace v8 {
17namespace internal {
18
19class AstRawString;
20class AstValueFactory;
21class Isolate;
22class Script;
23
24// Helper class for handling pending compilation errors consistently in various
25// compilation phases.
27 public:
30 delete;
32 const PendingCompilationErrorHandler&) = delete;
33
34 void ReportMessageAt(int start_position, int end_position,
35 MessageTemplate message, const char* arg = nullptr);
36
37 void ReportMessageAt(int start_position, int end_position,
38 MessageTemplate message, const AstRawString* arg);
39
40 void ReportMessageAt(int start_position, int end_position,
41 MessageTemplate message, const AstRawString* arg0,
42 const char* arg1);
43
44 void ReportMessageAt(int start_position, int end_position,
45 MessageTemplate message, const AstRawString* arg0,
46 const AstRawString* arg1, const char* arg2);
47
48 void ReportWarningAt(int start_position, int end_position,
49 MessageTemplate message, const char* arg = nullptr);
50
51 bool stack_overflow() const { return stack_overflow_; }
52
54 has_pending_error_ = true;
55 stack_overflow_ = true;
56 }
57
58 bool has_pending_error() const { return has_pending_error_; }
59 bool has_pending_warnings() const { return !warning_messages_.empty(); }
60
61 // Handle errors detected during parsing.
62 template <typename IsolateT>
64 void PrepareErrors(IsolateT* isolate, AstValueFactory* ast_value_factory);
66 Handle<Script> script) const;
67
68 // Handle warnings detected during compilation.
69 template <typename IsolateT>
70 void PrepareWarnings(IsolateT* isolate);
71 void ReportWarnings(Isolate* isolate, Handle<Script> script) const;
72
74 Isolate* isolate);
75
87
88 private:
90 public:
91 static constexpr int kMaxArgumentCount = 3;
92
98 MessageDetails(int start_position, int end_position,
99 MessageTemplate message, const AstRawString* arg0)
100 : start_position_(start_position),
101 end_position_(end_position),
102 message_(message),
104 MessageDetails(int start_position, int end_position,
105 MessageTemplate message, const AstRawString* arg0,
106 const char* arg1)
107 : start_position_(start_position),
108 end_position_(end_position),
109 message_(message),
111 MessageArgument{}} {
112 DCHECK_NOT_NULL(arg0);
113 DCHECK_NOT_NULL(arg1);
114 }
115 MessageDetails(int start_position, int end_position,
116 MessageTemplate message, const AstRawString* arg0,
117 const AstRawString* arg1, const char* arg2)
118 : start_position_(start_position),
119 end_position_(end_position),
120 message_(message),
122 MessageArgument{arg2}} {
123 DCHECK_NOT_NULL(arg0);
124 DCHECK_NOT_NULL(arg1);
125 DCHECK_NOT_NULL(arg2);
126 }
127 MessageDetails(int start_position, int end_position,
128 MessageTemplate message, const char* arg0)
129 : start_position_(start_position),
130 end_position_(end_position),
131 message_(message),
133
134 DirectHandle<String> ArgString(Isolate* isolate, int index) const;
135 int ArgCount() const {
136 int argc = 0;
137 for (int i = 0; i < kMaxArgumentCount; i++) {
138 if (args_[i].type == kNone) break;
139 argc++;
140 }
141#ifdef DEBUG
142 for (int i = argc; i < kMaxArgumentCount; i++) {
143 DCHECK_EQ(args_[i].type, kNone);
144 }
145#endif // DEBUG
146 return argc;
147 }
148
150 int start_pos() const { return start_position_; }
151 int end_pos() const { return end_position_; }
152 MessageTemplate message() const { return message_; }
153
154 template <typename IsolateT>
155 void Prepare(IsolateT* isolate);
156
157 private:
159
160 void SetString(int index, Handle<String> string, Isolate* isolate);
161 void SetString(int index, Handle<String> string, LocalIsolate* isolate);
162
165
167
168 struct MessageArgument final {
169 constexpr MessageArgument() : ast_string(nullptr), type(kNone) {}
170 explicit constexpr MessageArgument(const AstRawString* s)
171 : ast_string(s), type(s == nullptr ? kNone : kAstRawString) {}
172 explicit constexpr MessageArgument(const char* s)
173 : c_string(s), type(s == nullptr ? kNone : kConstCharString) {}
174
175 union {
177 const char* c_string;
179 };
181 };
182
184 };
185
186 void ThrowPendingError(Isolate* isolate, Handle<Script> script) const;
187
188 bool has_pending_error_ = false;
189 bool stack_overflow_ = false;
191
193
194 std::forward_list<MessageDetails> warning_messages_;
195};
196
198 Isolate* isolate, AstValueFactory* ast_value_factory);
200 LocalIsolate* isolate, AstValueFactory* ast_value_factory);
202 Isolate* isolate);
204 LocalIsolate* isolate);
205
206} // namespace internal
207} // namespace v8
208#endif // V8_PARSING_PENDING_COMPILATION_ERROR_HANDLER_H_
MessageDetails(int start_position, int end_position, MessageTemplate message, const AstRawString *arg0, const char *arg1)
MessageDetails(int start_position, int end_position, MessageTemplate message, const AstRawString *arg0, const AstRawString *arg1, const char *arg2)
MessageDetails(int start_position, int end_position, MessageTemplate message, const AstRawString *arg0)
MessageDetails(int start_position, int end_position, MessageTemplate message, const char *arg0)
void SetString(int index, Handle< String > string, Isolate *isolate)
DirectHandle< String > ArgString(Isolate *isolate, int index) const
void ReportWarningAt(int start_position, int end_position, MessageTemplate message, const char *arg=nullptr)
PendingCompilationErrorHandler(const PendingCompilationErrorHandler &)=delete
void ThrowPendingError(Isolate *isolate, Handle< Script > script) const
V8_EXPORT_PRIVATE DirectHandle< String > FormatErrorMessageForTest(Isolate *isolate)
V8_EXPORT_PRIVATE void ReportErrors(Isolate *isolate, Handle< Script > script) const
void ReportMessageAt(int start_position, int end_position, MessageTemplate message, const char *arg=nullptr)
void ReportWarnings(Isolate *isolate, Handle< Script > script) const
void PrepareErrors(IsolateT *isolate, AstValueFactory *ast_value_factory)
PendingCompilationErrorHandler & operator=(const PendingCompilationErrorHandler &)=delete
#define EXPORT_TEMPLATE_DECLARE(export)
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_EXPORT_PRIVATE
Definition macros.h:460