blob: aec346903522a87857284652f646e89a82669469 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
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 Murdochb8a8cc12014-11-26 15:28:44 +000013#include "src/handles-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000014
15// Forward declaration of MessageLocation.
16namespace v8 {
17namespace internal {
18class MessageLocation;
19} } // namespace v8::internal
20
21
22class 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
38namespace v8 {
39namespace internal {
40
41struct Language;
42class SourceInfo;
43
44class 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
67class MessageHandler {
68 public:
Steve Blocka7e24c12009-10-30 11:49:00 +000069 // Returns a message object for the API to use.
Steve Block1e0659c2011-05-24 12:43:12 +010070 static Handle<JSMessageObject> MakeMessageObject(
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 Isolate* isolate,
Steve Block1e0659c2011-05-24 12:43:12 +010072 const char* type,
73 MessageLocation* loc,
74 Vector< Handle<Object> > args,
Steve Block1e0659c2011-05-24 12:43:12 +010075 Handle<JSArray> stack_frames);
Steve Blocka7e24c12009-10-30 11:49:00 +000076
77 // Report a formatted message (needs JS allocation).
Ben Murdoch8b112d22011-06-08 16:22:53 +010078 static void ReportMessage(Isolate* isolate,
79 MessageLocation* loc,
80 Handle<Object> message);
Steve Blocka7e24c12009-10-30 11:49:00 +000081
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082 static void DefaultMessageReport(Isolate* isolate,
83 const MessageLocation* loc,
Steve Blocka7e24c12009-10-30 11:49:00 +000084 Handle<Object> message_obj);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000085 static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
86 static SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
87 Handle<Object> data);
Steve Blocka7e24c12009-10-30 11:49:00 +000088};
89
90} } // namespace v8::internal
91
92#endif // V8_MESSAGES_H_