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.
5 #ifndef V8_PENDING_COMPILATION_ERROR_HANDLER_H_
6 #define V8_PENDING_COMPILATION_ERROR_HANDLER_H_
8 #include "src/base/macros.h"
9 #include "src/globals.h"
10 #include "src/handles.h"
19 // Helper class for handling pending compilation errors consistently in various
20 // compilation phases.
21 class PendingCompilationErrorHandler {
23 PendingCompilationErrorHandler()
24 : has_pending_error_(false),
30 error_type_(kSyntaxError) {}
32 void ReportMessageAt(int start_position, int end_position,
33 const char* message, const char* arg = nullptr,
34 ParseErrorType error_type = kSyntaxError) {
35 if (has_pending_error_) return;
36 has_pending_error_ = true;
37 start_position_ = start_position;
38 end_position_ = end_position;
42 error_type_ = error_type;
45 void ReportMessageAt(int start_position, int end_position,
46 const char* message, const AstRawString* arg,
47 ParseErrorType error_type = kSyntaxError) {
48 if (has_pending_error_) return;
49 has_pending_error_ = true;
50 start_position_ = start_position;
51 end_position_ = end_position;
55 error_type_ = error_type;
58 void ReportMessageAt(int start_position, int end_position,
59 const char* message, Handle<String> arg,
60 ParseErrorType error_type = kSyntaxError) {
61 if (has_pending_error_) return;
62 has_pending_error_ = true;
63 start_position_ = start_position;
64 end_position_ = end_position;
69 error_type_ = error_type;
72 bool has_pending_error() const { return has_pending_error_; }
74 void ThrowPendingError(Isolate* isolate, Handle<Script> script);
77 bool has_pending_error_;
81 const AstRawString* arg_;
82 const char* char_arg_;
83 Handle<String> handle_arg_;
84 ParseErrorType error_type_;
86 DISALLOW_COPY_AND_ASSIGN(PendingCompilationErrorHandler);
89 } // namespace internal
91 #endif // V8_PENDING_COMPILATION_ERROR_HANDLER_H_