| OLD | NEW |
| 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 20 matching lines...) Expand all Loading... |
| 31 #include "execution.h" | 31 #include "execution.h" |
| 32 #include "messages.h" | 32 #include "messages.h" |
| 33 #include "spaces-inl.h" | 33 #include "spaces-inl.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 | 38 |
| 39 // If no message listeners have been registered this one is called | 39 // If no message listeners have been registered this one is called |
| 40 // by default. | 40 // by default. |
| 41 void MessageHandler::DefaultMessageReport(const MessageLocation* loc, | 41 void MessageHandler::DefaultMessageReport(Isolate* isolate, |
| 42 const MessageLocation* loc, |
| 42 Handle<Object> message_obj) { | 43 Handle<Object> message_obj) { |
| 43 SmartArrayPointer<char> str = GetLocalizedMessage(message_obj); | 44 SmartArrayPointer<char> str = GetLocalizedMessage(isolate, message_obj); |
| 44 if (loc == NULL) { | 45 if (loc == NULL) { |
| 45 PrintF("%s\n", *str); | 46 PrintF("%s\n", *str); |
| 46 } else { | 47 } else { |
| 47 HandleScope scope; | 48 HandleScope scope(isolate); |
| 48 Handle<Object> data(loc->script()->name()); | 49 Handle<Object> data(loc->script()->name()); |
| 49 SmartArrayPointer<char> data_str; | 50 SmartArrayPointer<char> data_str; |
| 50 if (data->IsString()) | 51 if (data->IsString()) |
| 51 data_str = Handle<String>::cast(data)->ToCString(DISALLOW_NULLS); | 52 data_str = Handle<String>::cast(data)->ToCString(DISALLOW_NULLS); |
| 52 PrintF("%s:%i: %s\n", *data_str ? *data_str : "<unknown>", | 53 PrintF("%s:%i: %s\n", *data_str ? *data_str : "<unknown>", |
| 53 loc->start_pos(), *str); | 54 loc->start_pos(), *str); |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 57 | 58 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 Isolate::ExceptionScope exception_scope(isolate); | 118 Isolate::ExceptionScope exception_scope(isolate); |
| 118 isolate->clear_pending_exception(); | 119 isolate->clear_pending_exception(); |
| 119 isolate->set_external_caught_exception(false); | 120 isolate->set_external_caught_exception(false); |
| 120 | 121 |
| 121 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); | 122 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); |
| 122 v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception_handle); | 123 v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception_handle); |
| 123 | 124 |
| 124 v8::NeanderArray global_listeners(FACTORY->message_listeners()); | 125 v8::NeanderArray global_listeners(FACTORY->message_listeners()); |
| 125 int global_length = global_listeners.length(); | 126 int global_length = global_listeners.length(); |
| 126 if (global_length == 0) { | 127 if (global_length == 0) { |
| 127 DefaultMessageReport(loc, message); | 128 DefaultMessageReport(isolate, loc, message); |
| 128 if (isolate->has_scheduled_exception()) { | 129 if (isolate->has_scheduled_exception()) { |
| 129 isolate->clear_scheduled_exception(); | 130 isolate->clear_scheduled_exception(); |
| 130 } | 131 } |
| 131 } else { | 132 } else { |
| 132 for (int i = 0; i < global_length; i++) { | 133 for (int i = 0; i < global_length; i++) { |
| 133 HandleScope scope; | 134 HandleScope scope(isolate); |
| 134 if (global_listeners.get(i)->IsUndefined()) continue; | 135 if (global_listeners.get(i)->IsUndefined()) continue; |
| 135 Handle<Foreign> callback_obj(Foreign::cast(global_listeners.get(i))); | 136 Handle<Foreign> callback_obj(Foreign::cast(global_listeners.get(i))); |
| 136 v8::MessageCallback callback = | 137 v8::MessageCallback callback = |
| 137 FUNCTION_CAST<v8::MessageCallback>(callback_obj->foreign_address()); | 138 FUNCTION_CAST<v8::MessageCallback>(callback_obj->foreign_address()); |
| 138 { | 139 { |
| 139 // Do not allow exceptions to propagate. | 140 // Do not allow exceptions to propagate. |
| 140 v8::TryCatch try_catch; | 141 v8::TryCatch try_catch; |
| 141 callback(api_message_obj, api_exception_obj); | 142 callback(api_message_obj, api_exception_obj); |
| 142 } | 143 } |
| 143 if (isolate->has_scheduled_exception()) { | 144 if (isolate->has_scheduled_exception()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // likely to be a complicated ConsString of some sort. We flatten it | 177 // likely to be a complicated ConsString of some sort. We flatten it |
| 177 // here to improve the efficiency of converting it to a C string and | 178 // here to improve the efficiency of converting it to a C string and |
| 178 // other operations that are likely to take place (see GetLocalizedMessage | 179 // other operations that are likely to take place (see GetLocalizedMessage |
| 179 // for example). | 180 // for example). |
| 180 FlattenString(result_string); | 181 FlattenString(result_string); |
| 181 return result_string; | 182 return result_string; |
| 182 } | 183 } |
| 183 | 184 |
| 184 | 185 |
| 185 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( | 186 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( |
| 187 Isolate* isolate, |
| 186 Handle<Object> data) { | 188 Handle<Object> data) { |
| 187 HandleScope scope; | 189 HandleScope scope(isolate); |
| 188 return GetMessage(data)->ToCString(DISALLOW_NULLS); | 190 return GetMessage(data)->ToCString(DISALLOW_NULLS); |
| 189 } | 191 } |
| 190 | 192 |
| 191 | 193 |
| 192 } } // namespace v8::internal | 194 } } // namespace v8::internal |
| OLD | NEW |