OLD | NEW |
(Empty) | |
| 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_PENDING_COMPILATION_ERROR_HANDLER_H_ |
| 6 #define V8_PENDING_COMPILATION_ERROR_HANDLER_H_ |
| 7 |
| 8 #include "src/base/macros.h" |
| 9 #include "src/globals.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 |
| 14 class AstRawString; |
| 15 template <class T> |
| 16 class Handle; |
| 17 class Isolate; |
| 18 class Script; |
| 19 |
| 20 // Helper class for handling pending compilation errors consistently in various |
| 21 // compilation phases. |
| 22 class PendingCompilationErrorHandler { |
| 23 public: |
| 24 PendingCompilationErrorHandler() |
| 25 : has_pending_error_(false), |
| 26 start_position_(-1), |
| 27 end_position_(-1), |
| 28 message_(nullptr), |
| 29 arg_(nullptr), |
| 30 char_arg_(nullptr), |
| 31 error_type_(kSyntaxError) {} |
| 32 |
| 33 void ReportMessageAt(int start_position, int end_position, |
| 34 const char* message, const char* arg = nullptr, |
| 35 ParseErrorType error_type = kSyntaxError) { |
| 36 if (has_pending_error_) return; |
| 37 has_pending_error_ = true; |
| 38 start_position_ = start_position; |
| 39 end_position_ = end_position; |
| 40 message_ = message; |
| 41 char_arg_ = arg; |
| 42 arg_ = nullptr; |
| 43 error_type_ = error_type; |
| 44 } |
| 45 |
| 46 void ReportMessageAt(int start_position, int end_position, |
| 47 const char* message, const AstRawString* arg, |
| 48 ParseErrorType error_type = kSyntaxError) { |
| 49 if (has_pending_error_) return; |
| 50 has_pending_error_ = true; |
| 51 start_position_ = start_position; |
| 52 end_position_ = end_position; |
| 53 message_ = message; |
| 54 char_arg_ = nullptr; |
| 55 arg_ = arg; |
| 56 error_type_ = error_type; |
| 57 } |
| 58 |
| 59 bool has_pending_error() const { return has_pending_error_; } |
| 60 |
| 61 void ThrowPendingError(Isolate* isolate, Handle<Script> script); |
| 62 |
| 63 private: |
| 64 bool has_pending_error_; |
| 65 int start_position_; |
| 66 int end_position_; |
| 67 const char* message_; |
| 68 const AstRawString* arg_; |
| 69 const char* char_arg_; |
| 70 ParseErrorType error_type_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(PendingCompilationErrorHandler); |
| 73 }; |
| 74 |
| 75 } // namespace internal |
| 76 } // namespace v8 |
| 77 #endif // V8_PENDING_COMPILATION_ERROR_HANDLER_H_ |
OLD | NEW |