Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / v8 / src / messages.h
1 // Copyright 2006-2008 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 // 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
13 #include "handles-inl.h"
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:
69   // Returns a message object for the API to use.
70   static Handle<JSMessageObject> MakeMessageObject(
71       Isolate* isolate,
72       const char* type,
73       MessageLocation* loc,
74       Vector< Handle<Object> > args,
75       Handle<JSArray> stack_frames);
76
77   // Report a formatted message (needs JS allocation).
78   static void ReportMessage(Isolate* isolate,
79                             MessageLocation* loc,
80                             Handle<Object> message);
81
82   static void DefaultMessageReport(Isolate* isolate,
83                                    const MessageLocation* loc,
84                                    Handle<Object> message_obj);
85   static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
86   static SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
87                                                      Handle<Object> data);
88 };
89
90 } }  // namespace v8::internal
91
92 #endif  // V8_MESSAGES_H_