Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | // The infrastructure used for (localized) message reporting in V8. |
| 6 | // |
| 7 | // Note: there's a big unresolved issue about ownership of the data |
| 8 | // structures used by this framework. |
| 9 | |
| 10 | #ifndef V8_MESSAGES_H_ |
| 11 | #define V8_MESSAGES_H_ |
| 12 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 13 | #include "src/handles-inl.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 14 | |
| 15 | // Forward declaration of MessageLocation. |
| 16 | namespace v8 { |
| 17 | namespace internal { |
| 18 | class MessageLocation; |
| 19 | } } // namespace v8::internal |
| 20 | |
| 21 | |
| 22 | class V8Message { |
| 23 | public: |
| 24 | V8Message(char* type, |
| 25 | v8::internal::Handle<v8::internal::JSArray> args, |
| 26 | const v8::internal::MessageLocation* loc) : |
| 27 | type_(type), args_(args), loc_(loc) { } |
| 28 | char* type() const { return type_; } |
| 29 | v8::internal::Handle<v8::internal::JSArray> args() const { return args_; } |
| 30 | const v8::internal::MessageLocation* loc() const { return loc_; } |
| 31 | private: |
| 32 | char* type_; |
| 33 | v8::internal::Handle<v8::internal::JSArray> const args_; |
| 34 | const v8::internal::MessageLocation* loc_; |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | namespace v8 { |
| 39 | namespace internal { |
| 40 | |
| 41 | struct Language; |
| 42 | class SourceInfo; |
| 43 | |
| 44 | class MessageLocation { |
| 45 | public: |
| 46 | MessageLocation(Handle<Script> script, |
| 47 | int start_pos, |
| 48 | int end_pos) |
| 49 | : script_(script), |
| 50 | start_pos_(start_pos), |
| 51 | end_pos_(end_pos) { } |
| 52 | MessageLocation() : start_pos_(-1), end_pos_(-1) { } |
| 53 | |
| 54 | Handle<Script> script() const { return script_; } |
| 55 | int start_pos() const { return start_pos_; } |
| 56 | int end_pos() const { return end_pos_; } |
| 57 | |
| 58 | private: |
| 59 | Handle<Script> script_; |
| 60 | int start_pos_; |
| 61 | int end_pos_; |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | // A message handler is a convenience interface for accessing the list |
| 66 | // of message listeners registered in an environment |
| 67 | class MessageHandler { |
| 68 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 69 | // Returns a message object for the API to use. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 70 | static Handle<JSMessageObject> MakeMessageObject( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 71 | Isolate* isolate, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 72 | const char* type, |
| 73 | MessageLocation* loc, |
| 74 | Vector< Handle<Object> > args, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 75 | Handle<JSArray> stack_frames); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 76 | |
| 77 | // Report a formatted message (needs JS allocation). |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 78 | static void ReportMessage(Isolate* isolate, |
| 79 | MessageLocation* loc, |
| 80 | Handle<Object> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 81 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 82 | static void DefaultMessageReport(Isolate* isolate, |
| 83 | const MessageLocation* loc, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 84 | Handle<Object> message_obj); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 85 | static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data); |
| 86 | static SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate, |
| 87 | Handle<Object> data); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } } // namespace v8::internal |
| 91 | |
| 92 | #endif // V8_MESSAGES_H_ |