OLD | NEW |
---|---|
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 stack_trace_handle, | 97 stack_trace_handle, |
98 stack_frames_handle); | 98 stack_frames_handle); |
99 | 99 |
100 return message; | 100 return message; |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 void MessageHandler::ReportMessage(Isolate* isolate, | 104 void MessageHandler::ReportMessage(Isolate* isolate, |
105 MessageLocation* loc, | 105 MessageLocation* loc, |
106 Handle<Object> message) { | 106 Handle<Object> message) { |
107 // If we are in process of message reporting, just ignore all other requests | |
108 // to report a message as they are due to unhandled exceptions thrown in | |
109 // message callbacks. | |
110 if (isolate->in_exception_reporting()) { | |
111 PrintF("uncaught exception thrown while reporting\n"); | |
112 return; | |
113 } | |
114 isolate->set_in_exception_reporting(true); | |
115 | |
116 // We are calling into embedder's code which can throw exceptions. | 107 // We are calling into embedder's code which can throw exceptions. |
117 // Thus we need to save current exception state, reset it to the clean one | 108 // Thus we need to save current exception state, reset it to the clean one |
118 // and ignore scheduled exceptions callbacks can throw. | 109 // and ignore scheduled exceptions callbacks can throw. |
119 Isolate::ExceptionScope exception_scope(isolate); | 110 Isolate::ExceptionScope exception_scope(isolate); |
120 isolate->clear_pending_exception(); | 111 isolate->clear_pending_exception(); |
121 isolate->set_external_caught_exception(false); | 112 isolate->set_external_caught_exception(false); |
122 | 113 |
123 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); | 114 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); |
124 | 115 |
125 v8::NeanderArray global_listeners(FACTORY->message_listeners()); | 116 v8::NeanderArray global_listeners(FACTORY->message_listeners()); |
126 int global_length = global_listeners.length(); | 117 int global_length = global_listeners.length(); |
127 if (global_length == 0) { | 118 if (global_length == 0) { |
128 DefaultMessageReport(loc, message); | 119 DefaultMessageReport(loc, message); |
129 if (isolate->has_scheduled_exception()) { | 120 if (isolate->has_scheduled_exception()) { |
130 isolate->clear_scheduled_exception(); | 121 isolate->clear_scheduled_exception(); |
131 } | 122 } |
132 } else { | 123 } else { |
133 for (int i = 0; i < global_length; i++) { | 124 for (int i = 0; i < global_length; i++) { |
134 HandleScope scope; | 125 HandleScope scope; |
135 if (global_listeners.get(i)->IsUndefined()) continue; | 126 if (global_listeners.get(i)->IsUndefined()) continue; |
136 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i))); | 127 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i))); |
137 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0))); | 128 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0))); |
138 v8::MessageCallback callback = | 129 v8::MessageCallback callback = |
139 FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy()); | 130 FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy()); |
140 Handle<Object> callback_data(listener.get(1)); | 131 Handle<Object> callback_data(listener.get(1)); |
141 callback(api_message_obj, v8::Utils::ToLocal(callback_data)); | 132 { |
133 // Do not allow exceptions to propagate. | |
134 v8::TryCatch tryCatch; | |
Vitaly Repeshko
2011/04/11 19:37:39
nit: noCamelCase
antonm
2011/04/15 12:15:34
Done.
| |
135 callback(api_message_obj, v8::Utils::ToLocal(callback_data)); | |
136 } | |
142 if (isolate->has_scheduled_exception()) { | 137 if (isolate->has_scheduled_exception()) { |
143 isolate->clear_scheduled_exception(); | 138 isolate->clear_scheduled_exception(); |
144 } | 139 } |
145 } | 140 } |
146 } | 141 } |
147 | |
148 isolate->set_in_exception_reporting(false); | |
149 } | 142 } |
150 | 143 |
151 | 144 |
152 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { | 145 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { |
153 Handle<String> fmt_str = FACTORY->LookupAsciiSymbol("FormatMessage"); | 146 Handle<String> fmt_str = FACTORY->LookupAsciiSymbol("FormatMessage"); |
154 Handle<JSFunction> fun = | 147 Handle<JSFunction> fun = |
155 Handle<JSFunction>( | 148 Handle<JSFunction>( |
156 JSFunction::cast( | 149 JSFunction::cast( |
157 Isolate::Current()->js_builtins_object()-> | 150 Isolate::Current()->js_builtins_object()-> |
158 GetPropertyNoExceptionThrown(*fmt_str))); | 151 GetPropertyNoExceptionThrown(*fmt_str))); |
(...skipping 18 matching lines...) Expand all Loading... | |
177 } | 170 } |
178 | 171 |
179 | 172 |
180 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { | 173 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { |
181 HandleScope scope; | 174 HandleScope scope; |
182 return GetMessage(data)->ToCString(DISALLOW_NULLS); | 175 return GetMessage(data)->ToCString(DISALLOW_NULLS); |
183 } | 176 } |
184 | 177 |
185 | 178 |
186 } } // namespace v8::internal | 179 } } // namespace v8::internal |
OLD | NEW |