OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PENDING_COMPILATION_ERROR_HANDLER_H_ | 5 #ifndef V8_PENDING_COMPILATION_ERROR_HANDLER_H_ |
6 #define V8_PENDING_COMPILATION_ERROR_HANDLER_H_ | 6 #define V8_PENDING_COMPILATION_ERROR_HANDLER_H_ |
7 | 7 |
8 #include "src/base/macros.h" | 8 #include "src/base/macros.h" |
9 #include "src/globals.h" | 9 #include "src/globals.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
| 11 #include "src/messages.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 class AstRawString; | 16 class AstRawString; |
16 class Isolate; | 17 class Isolate; |
17 class Script; | 18 class Script; |
18 | 19 |
19 // Helper class for handling pending compilation errors consistently in various | 20 // Helper class for handling pending compilation errors consistently in various |
20 // compilation phases. | 21 // compilation phases. |
21 class PendingCompilationErrorHandler { | 22 class PendingCompilationErrorHandler { |
22 public: | 23 public: |
23 PendingCompilationErrorHandler() | 24 PendingCompilationErrorHandler() |
24 : has_pending_error_(false), | 25 : has_pending_error_(false), |
25 start_position_(-1), | 26 start_position_(-1), |
26 end_position_(-1), | 27 end_position_(-1), |
27 message_(nullptr), | 28 message_(MessageTemplate::kNone), |
28 arg_(nullptr), | 29 arg_(nullptr), |
29 char_arg_(nullptr), | 30 char_arg_(nullptr), |
30 error_type_(kSyntaxError) {} | 31 error_type_(kSyntaxError) {} |
31 | 32 |
32 void ReportMessageAt(int start_position, int end_position, | 33 void ReportMessageAt(int start_position, int end_position, |
33 const char* message, const char* arg = nullptr, | 34 MessageTemplate::Template message, |
| 35 const char* arg = nullptr, |
34 ParseErrorType error_type = kSyntaxError) { | 36 ParseErrorType error_type = kSyntaxError) { |
35 if (has_pending_error_) return; | 37 if (has_pending_error_) return; |
36 has_pending_error_ = true; | 38 has_pending_error_ = true; |
37 start_position_ = start_position; | 39 start_position_ = start_position; |
38 end_position_ = end_position; | 40 end_position_ = end_position; |
39 message_ = message; | 41 message_ = message; |
40 char_arg_ = arg; | 42 char_arg_ = arg; |
41 arg_ = nullptr; | 43 arg_ = nullptr; |
42 error_type_ = error_type; | 44 error_type_ = error_type; |
43 } | 45 } |
44 | 46 |
45 void ReportMessageAt(int start_position, int end_position, | 47 void ReportMessageAt(int start_position, int end_position, |
46 const char* message, const AstRawString* arg, | 48 MessageTemplate::Template message, |
| 49 const AstRawString* arg, |
47 ParseErrorType error_type = kSyntaxError) { | 50 ParseErrorType error_type = kSyntaxError) { |
48 if (has_pending_error_) return; | 51 if (has_pending_error_) return; |
49 has_pending_error_ = true; | 52 has_pending_error_ = true; |
50 start_position_ = start_position; | 53 start_position_ = start_position; |
51 end_position_ = end_position; | 54 end_position_ = end_position; |
52 message_ = message; | 55 message_ = message; |
53 char_arg_ = nullptr; | 56 char_arg_ = nullptr; |
54 arg_ = arg; | 57 arg_ = arg; |
55 error_type_ = error_type; | 58 error_type_ = error_type; |
56 } | 59 } |
57 | 60 |
58 void ReportMessageAt(int start_position, int end_position, | 61 void ReportMessageAt(int start_position, int end_position, |
59 const char* message, Handle<String> arg, | 62 MessageTemplate::Template message, Handle<String> arg, |
60 ParseErrorType error_type = kSyntaxError) { | 63 ParseErrorType error_type = kSyntaxError) { |
61 if (has_pending_error_) return; | 64 if (has_pending_error_) return; |
62 has_pending_error_ = true; | 65 has_pending_error_ = true; |
63 start_position_ = start_position; | 66 start_position_ = start_position; |
64 end_position_ = end_position; | 67 end_position_ = end_position; |
65 message_ = message; | 68 message_ = message; |
66 char_arg_ = nullptr; | 69 char_arg_ = nullptr; |
67 arg_ = nullptr; | 70 arg_ = nullptr; |
68 handle_arg_ = arg; | 71 handle_arg_ = arg; |
69 error_type_ = error_type; | 72 error_type_ = error_type; |
70 } | 73 } |
71 | 74 |
72 bool has_pending_error() const { return has_pending_error_; } | 75 bool has_pending_error() const { return has_pending_error_; } |
73 | 76 |
74 void ThrowPendingError(Isolate* isolate, Handle<Script> script); | 77 void ThrowPendingError(Isolate* isolate, Handle<Script> script); |
75 | 78 |
76 private: | 79 private: |
77 bool has_pending_error_; | 80 bool has_pending_error_; |
78 int start_position_; | 81 int start_position_; |
79 int end_position_; | 82 int end_position_; |
80 const char* message_; | 83 MessageTemplate::Template message_; |
81 const AstRawString* arg_; | 84 const AstRawString* arg_; |
82 const char* char_arg_; | 85 const char* char_arg_; |
83 Handle<String> handle_arg_; | 86 Handle<String> handle_arg_; |
84 ParseErrorType error_type_; | 87 ParseErrorType error_type_; |
85 | 88 |
86 DISALLOW_COPY_AND_ASSIGN(PendingCompilationErrorHandler); | 89 DISALLOW_COPY_AND_ASSIGN(PendingCompilationErrorHandler); |
87 }; | 90 }; |
88 | 91 |
89 } // namespace internal | 92 } // namespace internal |
90 } // namespace v8 | 93 } // namespace v8 |
91 #endif // V8_PENDING_COMPILATION_ERROR_HANDLER_H_ | 94 #endif // V8_PENDING_COMPILATION_ERROR_HANDLER_H_ |
OLD | NEW |