deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / pending-compilation-error-handler.h
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 #include "src/handles.h"
11
12 namespace v8 {
13 namespace internal {
14
15 class AstRawString;
16 class Isolate;
17 class Script;
18
19 // Helper class for handling pending compilation errors consistently in various
20 // compilation phases.
21 class PendingCompilationErrorHandler {
22  public:
23   PendingCompilationErrorHandler()
24       : has_pending_error_(false),
25         start_position_(-1),
26         end_position_(-1),
27         message_(nullptr),
28         arg_(nullptr),
29         char_arg_(nullptr),
30         error_type_(kSyntaxError) {}
31
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;
39     message_ = message;
40     char_arg_ = arg;
41     arg_ = nullptr;
42     error_type_ = error_type;
43   }
44
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;
52     message_ = message;
53     char_arg_ = nullptr;
54     arg_ = arg;
55     error_type_ = error_type;
56   }
57
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;
65     message_ = message;
66     char_arg_ = nullptr;
67     arg_ = nullptr;
68     handle_arg_ = arg;
69     error_type_ = error_type;
70   }
71
72   bool has_pending_error() const { return has_pending_error_; }
73
74   void ThrowPendingError(Isolate* isolate, Handle<Script> script);
75
76  private:
77   bool has_pending_error_;
78   int start_position_;
79   int end_position_;
80   const char* message_;
81   const AstRawString* arg_;
82   const char* char_arg_;
83   Handle<String> handle_arg_;
84   ParseErrorType error_type_;
85
86   DISALLOW_COPY_AND_ASSIGN(PendingCompilationErrorHandler);
87 };
88
89 }  // namespace internal
90 }  // namespace v8
91 #endif  // V8_PENDING_COMPILATION_ERROR_HANDLER_H_