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

Side by Side Diff: src/messages.cc

Issue 6397011: Make exception thrown via v8 public API propagate to v8::TryCatch as JS thrown exceptions do. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing Vitaly's 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
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // stack overflow exceptions being thrown by the parser when the 121 // stack overflow exceptions being thrown by the parser when the
122 // stack is almost full. 122 // stack is almost full.
123 if (caught_exception) return Handle<Object>(); 123 if (caught_exception) return Handle<Object>();
124 124
125 return message.EscapeFrom(&scope); 125 return message.EscapeFrom(&scope);
126 } 126 }
127 127
128 128
129 void MessageHandler::ReportMessage(MessageLocation* loc, 129 void MessageHandler::ReportMessage(MessageLocation* loc,
130 Handle<Object> message) { 130 Handle<Object> message) {
131 // We are calling into embedder's code which can throw exceptions.
132 // Thus we need to save current exception state, reset it to the clean one
133 // and ignore scheduled exceptions callbacks can throw.
134 Top::Scope top_scope;
Vitaly Repeshko 2011/02/01 19:07:17 I don't like the name. ExceptionScope? Also given
antonm 2011/02/01 20:14:39 Renamed to ExceptionScope.
135 Top::clear_pending_exception();
136 Top::set_external_caught_exception(false);
137
131 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); 138 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
132 139
133 v8::NeanderArray global_listeners(Factory::message_listeners()); 140 v8::NeanderArray global_listeners(Factory::message_listeners());
134 int global_length = global_listeners.length(); 141 int global_length = global_listeners.length();
135 if (global_length == 0) { 142 if (global_length == 0) {
136 DefaultMessageReport(loc, message); 143 DefaultMessageReport(loc, message);
144 if (Top::has_scheduled_exception()) {
145 // Consider logging it somehow.
Vitaly Repeshko 2011/02/01 19:07:17 Please file a bug to not forget about "scary" exce
antonm 2011/02/01 20:14:39 Will do.
146 Top::clear_scheduled_exception();
147 }
137 } else { 148 } else {
138 for (int i = 0; i < global_length; i++) { 149 for (int i = 0; i < global_length; i++) {
139 HandleScope scope; 150 HandleScope scope;
140 if (global_listeners.get(i)->IsUndefined()) continue; 151 if (global_listeners.get(i)->IsUndefined()) continue;
141 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i))); 152 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i)));
142 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0))); 153 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0)));
143 v8::MessageCallback callback = 154 v8::MessageCallback callback =
144 FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy()); 155 FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy());
145 Handle<Object> callback_data(listener.get(1)); 156 Handle<Object> callback_data(listener.get(1));
146 callback(api_message_obj, v8::Utils::ToLocal(callback_data)); 157 callback(api_message_obj, v8::Utils::ToLocal(callback_data));
158 if (Top::has_scheduled_exception()) {
159 // Consider logging it somehow.
160 Top::clear_scheduled_exception();
161 }
147 } 162 }
148 } 163 }
149 } 164 }
150 165
151 166
152 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { 167 Handle<String> MessageHandler::GetMessage(Handle<Object> data) {
153 Handle<String> fmt_str = Factory::LookupAsciiSymbol("FormatMessage"); 168 Handle<String> fmt_str = Factory::LookupAsciiSymbol("FormatMessage");
154 Handle<JSFunction> fun = 169 Handle<JSFunction> fun =
155 Handle<JSFunction>(JSFunction::cast( 170 Handle<JSFunction>(JSFunction::cast(
156 Top::builtins()->GetPropertyNoExceptionThrown(*fmt_str))); 171 Top::builtins()->GetPropertyNoExceptionThrown(*fmt_str)));
(...skipping 17 matching lines...) Expand all
174 } 189 }
175 190
176 191
177 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { 192 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) {
178 HandleScope scope; 193 HandleScope scope;
179 return GetMessage(data)->ToCString(DISALLOW_NULLS); 194 return GetMessage(data)->ToCString(DISALLOW_NULLS);
180 } 195 }
181 196
182 197
183 } } // namespace v8::internal 198 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698