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

Side by Side Diff: src/messages.cc

Issue 6685087: 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: Next round Created 9 years, 9 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
« src/api.cc ('K') | « src/messages.h ('k') | src/top.cc » ('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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 start, 99 start,
100 end, 100 end,
101 script_handle, 101 script_handle,
102 stack_trace_handle, 102 stack_trace_handle,
103 stack_frames_handle); 103 stack_frames_handle);
104 104
105 return message; 105 return message;
106 } 106 }
107 107
108 108
109 void MessageHandler::ReportMessage(MessageLocation* loc, 109 void MessageHandler::ReportMessage(Isolate* isolate,
110 MessageLocation* loc,
110 Handle<Object> message) { 111 Handle<Object> message) {
112 // If we are in process of message reporting, just ignore all other requests
113 // to report a message as they are due to unhandled exceptions thrown in
114 // message callbacks.
115 if (isolate->in_exception_reporting()) {
116 ReportMessage("uncaught exception thrown while reporting");
117 return;
118 }
119 isolate->set_in_exception_reporting(true);
120
121 // We are calling into embedder's code which can throw exceptions.
122 // Thus we need to save current exception state, reset it to the clean one
123 // and ignore scheduled exceptions callbacks can throw.
124 Isolate::ExceptionScope exception_scope(isolate);
125 isolate->clear_pending_exception();
126 isolate->set_external_caught_exception(false);
127
111 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); 128 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
112 129
113 v8::NeanderArray global_listeners(FACTORY->message_listeners()); 130 v8::NeanderArray global_listeners(FACTORY->message_listeners());
114 int global_length = global_listeners.length(); 131 int global_length = global_listeners.length();
115 if (global_length == 0) { 132 if (global_length == 0) {
116 DefaultMessageReport(loc, message); 133 DefaultMessageReport(loc, message);
134 if (isolate->has_scheduled_exception()) {
135 isolate->clear_scheduled_exception();
136 }
117 } else { 137 } else {
118 for (int i = 0; i < global_length; i++) { 138 for (int i = 0; i < global_length; i++) {
119 HandleScope scope; 139 HandleScope scope;
120 if (global_listeners.get(i)->IsUndefined()) continue; 140 if (global_listeners.get(i)->IsUndefined()) continue;
121 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i))); 141 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i)));
122 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0))); 142 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0)));
123 v8::MessageCallback callback = 143 v8::MessageCallback callback =
124 FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy()); 144 FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy());
125 Handle<Object> callback_data(listener.get(1)); 145 Handle<Object> callback_data(listener.get(1));
126 callback(api_message_obj, v8::Utils::ToLocal(callback_data)); 146 callback(api_message_obj, v8::Utils::ToLocal(callback_data));
147 if (isolate->has_scheduled_exception()) {
148 isolate->clear_scheduled_exception();
149 }
127 } 150 }
128 } 151 }
152
153 isolate->set_in_exception_reporting(false);
129 } 154 }
130 155
131 156
132 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { 157 Handle<String> MessageHandler::GetMessage(Handle<Object> data) {
133 Handle<String> fmt_str = FACTORY->LookupAsciiSymbol("FormatMessage"); 158 Handle<String> fmt_str = FACTORY->LookupAsciiSymbol("FormatMessage");
134 Handle<JSFunction> fun = 159 Handle<JSFunction> fun =
135 Handle<JSFunction>( 160 Handle<JSFunction>(
136 JSFunction::cast( 161 JSFunction::cast(
137 Isolate::Current()->js_builtins_object()-> 162 Isolate::Current()->js_builtins_object()->
138 GetPropertyNoExceptionThrown(*fmt_str))); 163 GetPropertyNoExceptionThrown(*fmt_str)));
(...skipping 18 matching lines...) Expand all
157 } 182 }
158 183
159 184
160 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) { 185 SmartPointer<char> MessageHandler::GetLocalizedMessage(Handle<Object> data) {
161 HandleScope scope; 186 HandleScope scope;
162 return GetMessage(data)->ToCString(DISALLOW_NULLS); 187 return GetMessage(data)->ToCString(DISALLOW_NULLS);
163 } 188 }
164 189
165 190
166 } } // namespace v8::internal 191 } } // namespace v8::internal
OLDNEW
« src/api.cc ('K') | « src/messages.h ('k') | src/top.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698