Line data Source code
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 <forward_list>
9 :
10 : #include "src/base/macros.h"
11 : #include "src/globals.h"
12 : #include "src/handles.h"
13 : #include "src/message-template.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 :
18 : class AstRawString;
19 : class AstValueFactory;
20 : class Isolate;
21 : class Script;
22 :
23 : // Helper class for handling pending compilation errors consistently in various
24 : // compilation phases.
25 2975429 : class PendingCompilationErrorHandler {
26 : public:
27 : PendingCompilationErrorHandler()
28 : : has_pending_error_(false),
29 : stack_overflow_(false),
30 5950874 : error_type_(kSyntaxError) {}
31 :
32 : void ReportMessageAt(int start_position, int end_position,
33 : MessageTemplate message, const char* arg = nullptr,
34 : ParseErrorType error_type = kSyntaxError);
35 :
36 : void ReportMessageAt(int start_position, int end_position,
37 : MessageTemplate message, const AstRawString* arg,
38 : ParseErrorType error_type = kSyntaxError);
39 :
40 : void ReportWarningAt(int start_position, int end_position,
41 : MessageTemplate message, const char* arg = nullptr);
42 :
43 : bool stack_overflow() const { return stack_overflow_; }
44 :
45 : void set_stack_overflow() {
46 12753 : has_pending_error_ = true;
47 12753 : stack_overflow_ = true;
48 : }
49 :
50 : bool has_pending_error() const { return has_pending_error_; }
51 : bool has_pending_warnings() const { return !warning_messages_.empty(); }
52 :
53 : // Handle errors detected during parsing.
54 : void ReportErrors(Isolate* isolate, Handle<Script> script,
55 : AstValueFactory* ast_value_factory);
56 :
57 : // Handle warnings detected during compilation.
58 : void ReportWarnings(Isolate* isolate, Handle<Script> script);
59 :
60 : Handle<String> FormatErrorMessageForTest(Isolate* isolate) const;
61 :
62 : void set_unidentifiable_error() {
63 1655668 : has_pending_error_ = true;
64 1655668 : unidentifiable_error_ = true;
65 : }
66 : void clear_unidentifiable_error() {
67 48875 : has_pending_error_ = false;
68 48875 : unidentifiable_error_ = false;
69 : }
70 : bool has_error_unidentifiable_by_preparser() const {
71 : return unidentifiable_error_;
72 : }
73 :
74 : private:
75 : class MessageDetails {
76 : public:
77 : MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(MessageDetails);
78 : MessageDetails()
79 : : start_position_(-1),
80 : end_position_(-1),
81 : message_(MessageTemplate::kNone),
82 : arg_(nullptr),
83 2975437 : char_arg_(nullptr) {}
84 : MessageDetails(int start_position, int end_position,
85 : MessageTemplate message, const AstRawString* arg,
86 : const char* char_arg)
87 : : start_position_(start_position),
88 : end_position_(end_position),
89 : message_(message),
90 : arg_(arg),
91 1255 : char_arg_(char_arg) {}
92 :
93 : Handle<String> ArgumentString(Isolate* isolate) const;
94 : MessageLocation GetLocation(Handle<Script> script) const;
95 : MessageTemplate message() const { return message_; }
96 :
97 : private:
98 : int start_position_;
99 : int end_position_;
100 : MessageTemplate message_;
101 : const AstRawString* arg_;
102 : const char* char_arg_;
103 : };
104 :
105 : void ThrowPendingError(Isolate* isolate, Handle<Script> script);
106 :
107 : bool has_pending_error_;
108 : bool stack_overflow_;
109 : bool unidentifiable_error_ = false;
110 :
111 : MessageDetails error_details_;
112 : ParseErrorType error_type_;
113 :
114 : std::forward_list<MessageDetails> warning_messages_;
115 :
116 : DISALLOW_COPY_AND_ASSIGN(PendingCompilationErrorHandler);
117 : };
118 :
119 : } // namespace internal
120 : } // namespace v8
121 : #endif // V8_PENDING_COMPILATION_ERROR_HANDLER_H_
|