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

Side by Side Diff: src/messages.cc

Issue 11014017: Pass pending exception to the message listener. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 8 years, 2 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/api.cc ('k') | test/cctest/test-api.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 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 return message; 99 return message;
100 } 100 }
101 101
102 102
103 void MessageHandler::ReportMessage(Isolate* isolate, 103 void MessageHandler::ReportMessage(Isolate* isolate,
104 MessageLocation* loc, 104 MessageLocation* loc,
105 Handle<Object> message) { 105 Handle<Object> message) {
106 // We are calling into embedder's code which can throw exceptions. 106 // We are calling into embedder's code which can throw exceptions.
107 // Thus we need to save current exception state, reset it to the clean one 107 // Thus we need to save current exception state, reset it to the clean one
108 // and ignore scheduled exceptions callbacks can throw. 108 // and ignore scheduled exceptions callbacks can throw.
109
110 // We pass the exception object into the message handler callback though.
111 Object* exception_object = isolate->heap()->undefined_value();
112 if (isolate->has_pending_exception()) {
113 isolate->pending_exception()->ToObject(&exception_object);
114 }
115 Handle<Object> exception_handle(exception_object);
116
109 Isolate::ExceptionScope exception_scope(isolate); 117 Isolate::ExceptionScope exception_scope(isolate);
110 isolate->clear_pending_exception(); 118 isolate->clear_pending_exception();
111 isolate->set_external_caught_exception(false); 119 isolate->set_external_caught_exception(false);
112 120
113 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); 121 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
122 v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception_handle);
114 123
115 v8::NeanderArray global_listeners(FACTORY->message_listeners()); 124 v8::NeanderArray global_listeners(FACTORY->message_listeners());
116 int global_length = global_listeners.length(); 125 int global_length = global_listeners.length();
117 if (global_length == 0) { 126 if (global_length == 0) {
118 DefaultMessageReport(loc, message); 127 DefaultMessageReport(loc, message);
119 if (isolate->has_scheduled_exception()) { 128 if (isolate->has_scheduled_exception()) {
120 isolate->clear_scheduled_exception(); 129 isolate->clear_scheduled_exception();
121 } 130 }
122 } else { 131 } else {
123 for (int i = 0; i < global_length; i++) { 132 for (int i = 0; i < global_length; i++) {
124 HandleScope scope; 133 HandleScope scope;
125 if (global_listeners.get(i)->IsUndefined()) continue; 134 if (global_listeners.get(i)->IsUndefined()) continue;
126 v8::NeanderObject listener(JSObject::cast(global_listeners.get(i))); 135 Handle<Foreign> callback_obj(Foreign::cast(global_listeners.get(i)));
127 Handle<Foreign> callback_obj(Foreign::cast(listener.get(0)));
128 v8::MessageCallback callback = 136 v8::MessageCallback callback =
129 FUNCTION_CAST<v8::MessageCallback>(callback_obj->foreign_address()); 137 FUNCTION_CAST<v8::MessageCallback>(callback_obj->foreign_address());
130 Handle<Object> callback_data(listener.get(1));
131 { 138 {
132 // Do not allow exceptions to propagate. 139 // Do not allow exceptions to propagate.
133 v8::TryCatch try_catch; 140 v8::TryCatch try_catch;
134 callback(api_message_obj, v8::Utils::ToLocal(callback_data)); 141 callback(api_message_obj, api_exception_obj);
135 } 142 }
136 if (isolate->has_scheduled_exception()) { 143 if (isolate->has_scheduled_exception()) {
137 isolate->clear_scheduled_exception(); 144 isolate->clear_scheduled_exception();
138 } 145 }
139 } 146 }
140 } 147 }
141 } 148 }
142 149
143 150
144 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { 151 Handle<String> MessageHandler::GetMessage(Handle<Object> data) {
(...skipping 28 matching lines...) Expand all
173 180
174 181
175 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( 182 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage(
176 Handle<Object> data) { 183 Handle<Object> data) {
177 HandleScope scope; 184 HandleScope scope;
178 return GetMessage(data)->ToCString(DISALLOW_NULLS); 185 return GetMessage(data)->ToCString(DISALLOW_NULLS);
179 } 186 }
180 187
181 188
182 } } // namespace v8::internal 189 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698