Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/messages.cc

Issue 6368051: A MessageObject is a purely internal object to hold information about (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/messages.h ('k') | src/messages.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 // Copyright 2006-2008 the V8 project authors. All rights reserved. 2 // Copyright 2006-2008 the V8 project authors. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are 4 // modification, are permitted provided that the following conditions are
5 // met: 5 // met:
6 // 6 //
7 // * Redistributions of source code must retain the above copyright 7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer. 8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above 9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following 10 // copyright notice, this list of conditions and the following
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 loc->start_pos(), *str); 55 loc->start_pos(), *str);
56 } 56 }
57 } 57 }
58 58
59 59
60 void MessageHandler::ReportMessage(const char* msg) { 60 void MessageHandler::ReportMessage(const char* msg) {
61 PrintF("%s\n", msg); 61 PrintF("%s\n", msg);
62 } 62 }
63 63
64 64
65 Handle<Object> MessageHandler::MakeMessageObject( 65 Handle<JSMessageObject> MessageHandler::MakeMessageObject(
66 const char* type, 66 const char* type,
67 MessageLocation* loc, 67 MessageLocation* loc,
68 Vector< Handle<Object> > args, 68 Vector< Handle<Object> > args,
69 Handle<String> stack_trace, 69 Handle<String> stack_trace,
70 Handle<JSArray> stack_frames) { 70 Handle<JSArray> stack_frames) {
71 // Build error message object 71 Handle<String> type_handle = Factory::LookupAsciiSymbol(type);
72 v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom. 72 Handle<JSArray> arguments_handle = Factory::NewJSArray(args.length());
73 Handle<Object> type_str = Factory::LookupAsciiSymbol(type); 73 for (int i = 0; i < args.length(); i++) {
74 Handle<Object> array = Factory::NewJSArray(args.length()); 74 SetElement(arguments_handle, i, args[i]);
75 for (int i = 0; i < args.length(); i++) 75 }
76 SetElement(Handle<JSArray>::cast(array), i, args[i]);
77 76
78 Handle<JSFunction> fun(Top::global_context()->make_message_fun()); 77 int start = 0;
79 int start, end; 78 int end = 0;
80 Handle<Object> script; 79 Handle<Object> script_handle = Factory::undefined_value();
81 if (loc) { 80 if (loc) {
82 start = loc->start_pos(); 81 start = loc->start_pos();
83 end = loc->end_pos(); 82 end = loc->end_pos();
84 script = GetScriptWrapper(loc->script()); 83 script_handle = GetScriptWrapper(loc->script());
85 } else {
86 start = end = 0;
87 script = Factory::undefined_value();
88 } 84 }
89 Handle<Object> start_handle(Smi::FromInt(start));
90 Handle<Object> end_handle(Smi::FromInt(end));
91 Handle<Object> stack_trace_val = stack_trace.is_null()
92 ? Factory::undefined_value()
93 : Handle<Object>::cast(stack_trace);
94 Handle<Object> stack_frames_val = stack_frames.is_null()
95 ? Factory::undefined_value()
96 : Handle<Object>::cast(stack_frames);
97 const int argc = 7;
98 Object** argv[argc] = { type_str.location(),
99 array.location(),
100 start_handle.location(),
101 end_handle.location(),
102 script.location(),
103 stack_trace_val.location(),
104 stack_frames_val.location() };
105 85
106 // Setup a catch handler to catch exceptions in creating the message. This 86 Handle<Object> stack_trace_handle = stack_trace.is_null()
107 // handler is non-verbose to avoid calling MakeMessage recursively in case of 87 ? Factory::undefined_value()
108 // an exception. 88 : Handle<Object>::cast(stack_trace);
109 v8::TryCatch catcher;
110 catcher.SetVerbose(false);
111 catcher.SetCaptureMessage(false);
112 89
113 // Format the message. 90 Handle<Object> stack_frames_handle = stack_frames.is_null()
114 bool caught_exception = false; 91 ? Factory::undefined_value()
115 Handle<Object> message = 92 : Handle<Object>::cast(stack_frames);
116 Execution::Call(fun, Factory::undefined_value(), argc, argv,
117 &caught_exception);
118 93
119 // If creating the message (in JS code) resulted in an exception, we 94 Handle<JSMessageObject> message =
120 // skip doing the callback. This usually only happens in case of 95 Factory::NewJSMessageObject(type_handle,
121 // stack overflow exceptions being thrown by the parser when the 96 arguments_handle,
122 // stack is almost full. 97 start,
123 if (caught_exception) return Handle<Object>(); 98 end,
99 script_handle,
100 stack_trace_handle,
101 stack_frames_handle);
124 102
125 return message.EscapeFrom(&scope); 103 return message;
126 } 104 }
127 105
128 106
129 void MessageHandler::ReportMessage(MessageLocation* loc, 107 void MessageHandler::ReportMessage(MessageLocation* loc,
130 Handle<Object> message) { 108 Handle<Object> message) {
131 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); 109 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
132 110
133 v8::NeanderArray global_listeners(Factory::message_listeners()); 111 v8::NeanderArray global_listeners(Factory::message_listeners());
134 int global_length = global_listeners.length(); 112 int global_length = global_listeners.length();
135 if (global_length == 0) { 113 if (global_length == 0) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 152 }
175 153
176 154
177 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { 155 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) {
178 HandleScope scope; 156 HandleScope scope;
179 return GetMessage(data)->ToCString(DISALLOW_NULLS); 157 return GetMessage(data)->ToCString(DISALLOW_NULLS);
180 } 158 }
181 159
182 160
183 } } // namespace v8::internal 161 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/messages.h ('k') | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698