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 28 matching lines...) Expand all Loading... |
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(Isolate* isolate, | 41 void MessageHandler::DefaultMessageReport(Isolate* isolate, |
42 const MessageLocation* loc, | 42 const MessageLocation* loc, |
43 Handle<Object> message_obj) { | 43 Handle<Object> message_obj) { |
44 SmartArrayPointer<char> str = GetLocalizedMessage(isolate, message_obj); | 44 SmartArrayPointer<char> str = GetLocalizedMessage(isolate, message_obj); |
45 if (loc == NULL) { | 45 if (loc == NULL) { |
46 PrintF("%s\n", *str); | 46 PrintF("%s\n", *str); |
47 } else { | 47 } else { |
48 HandleScope scope(isolate); | 48 HandleScope scope(isolate); |
49 Handle<Object> data(loc->script()->name()); | 49 Handle<Object> data(loc->script()->name(), isolate); |
50 SmartArrayPointer<char> data_str; | 50 SmartArrayPointer<char> data_str; |
51 if (data->IsString()) | 51 if (data->IsString()) |
52 data_str = Handle<String>::cast(data)->ToCString(DISALLOW_NULLS); | 52 data_str = Handle<String>::cast(data)->ToCString(DISALLOW_NULLS); |
53 PrintF("%s:%i: %s\n", *data_str ? *data_str : "<unknown>", | 53 PrintF("%s:%i: %s\n", *data_str ? *data_str : "<unknown>", |
54 loc->start_pos(), *str); | 54 loc->start_pos(), *str); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 Handle<JSMessageObject> MessageHandler::MakeMessageObject( | 59 Handle<JSMessageObject> MessageHandler::MakeMessageObject( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 Handle<Object> message) { | 106 Handle<Object> message) { |
107 // We are calling into embedder's code which can throw exceptions. | 107 // We are calling into embedder's code which can throw exceptions. |
108 // 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 |
109 // and ignore scheduled exceptions callbacks can throw. | 109 // and ignore scheduled exceptions callbacks can throw. |
110 | 110 |
111 // We pass the exception object into the message handler callback though. | 111 // We pass the exception object into the message handler callback though. |
112 Object* exception_object = isolate->heap()->undefined_value(); | 112 Object* exception_object = isolate->heap()->undefined_value(); |
113 if (isolate->has_pending_exception()) { | 113 if (isolate->has_pending_exception()) { |
114 isolate->pending_exception()->ToObject(&exception_object); | 114 isolate->pending_exception()->ToObject(&exception_object); |
115 } | 115 } |
116 Handle<Object> exception_handle(exception_object); | 116 Handle<Object> exception_handle(exception_object, isolate); |
117 | 117 |
118 Isolate::ExceptionScope exception_scope(isolate); | 118 Isolate::ExceptionScope exception_scope(isolate); |
119 isolate->clear_pending_exception(); | 119 isolate->clear_pending_exception(); |
120 isolate->set_external_caught_exception(false); | 120 isolate->set_external_caught_exception(false); |
121 | 121 |
122 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); | 122 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); |
123 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); |
124 | 124 |
125 v8::NeanderArray global_listeners(FACTORY->message_listeners()); | 125 v8::NeanderArray global_listeners(FACTORY->message_listeners()); |
126 int global_length = global_listeners.length(); | 126 int global_length = global_listeners.length(); |
(...skipping 15 matching lines...) Expand all Loading... |
142 callback(api_message_obj, api_exception_obj); | 142 callback(api_message_obj, api_exception_obj); |
143 } | 143 } |
144 if (isolate->has_scheduled_exception()) { | 144 if (isolate->has_scheduled_exception()) { |
145 isolate->clear_scheduled_exception(); | 145 isolate->clear_scheduled_exception(); |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 Handle<String> MessageHandler::GetMessage(Handle<Object> data) { | 152 Handle<String> MessageHandler::GetMessage(Isolate* isolate, |
| 153 Handle<Object> data) { |
| 154 Factory* factory = isolate->factory(); |
153 Handle<String> fmt_str = | 155 Handle<String> fmt_str = |
154 FACTORY->LookupOneByteSymbol(STATIC_ASCII_VECTOR("FormatMessage")); | 156 factory->LookupOneByteSymbol(STATIC_ASCII_VECTOR("FormatMessage")); |
155 Handle<JSFunction> fun = | 157 Handle<JSFunction> fun = |
156 Handle<JSFunction>( | 158 Handle<JSFunction>( |
157 JSFunction::cast( | 159 JSFunction::cast( |
158 Isolate::Current()->js_builtins_object()-> | 160 isolate->js_builtins_object()-> |
159 GetPropertyNoExceptionThrown(*fmt_str))); | 161 GetPropertyNoExceptionThrown(*fmt_str))); |
160 Handle<JSMessageObject> message = Handle<JSMessageObject>::cast(data); | 162 Handle<JSMessageObject> message = Handle<JSMessageObject>::cast(data); |
161 Handle<Object> argv[] = { Handle<Object>(message->type()), | 163 Handle<Object> argv[] = { Handle<Object>(message->type(), isolate), |
162 Handle<Object>(message->arguments()) }; | 164 Handle<Object>(message->arguments(), isolate) }; |
163 | 165 |
164 bool caught_exception; | 166 bool caught_exception; |
165 Handle<Object> result = | 167 Handle<Object> result = |
166 Execution::TryCall(fun, | 168 Execution::TryCall(fun, |
167 Isolate::Current()->js_builtins_object(), | 169 isolate->js_builtins_object(), |
168 ARRAY_SIZE(argv), | 170 ARRAY_SIZE(argv), |
169 argv, | 171 argv, |
170 &caught_exception); | 172 &caught_exception); |
171 | 173 |
172 if (caught_exception || !result->IsString()) { | 174 if (caught_exception || !result->IsString()) { |
173 return FACTORY->LookupOneByteSymbol(STATIC_ASCII_VECTOR("<error>")); | 175 return factory->LookupOneByteSymbol(STATIC_ASCII_VECTOR("<error>")); |
174 } | 176 } |
175 Handle<String> result_string = Handle<String>::cast(result); | 177 Handle<String> result_string = Handle<String>::cast(result); |
176 // A string that has been obtained from JS code in this way is | 178 // A string that has been obtained from JS code in this way is |
177 // likely to be a complicated ConsString of some sort. We flatten it | 179 // likely to be a complicated ConsString of some sort. We flatten it |
178 // here to improve the efficiency of converting it to a C string and | 180 // here to improve the efficiency of converting it to a C string and |
179 // other operations that are likely to take place (see GetLocalizedMessage | 181 // other operations that are likely to take place (see GetLocalizedMessage |
180 // for example). | 182 // for example). |
181 FlattenString(result_string); | 183 FlattenString(result_string); |
182 return result_string; | 184 return result_string; |
183 } | 185 } |
184 | 186 |
185 | 187 |
186 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( | 188 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( |
187 Isolate* isolate, | 189 Isolate* isolate, |
188 Handle<Object> data) { | 190 Handle<Object> data) { |
189 HandleScope scope(isolate); | 191 HandleScope scope(isolate); |
190 return GetMessage(data)->ToCString(DISALLOW_NULLS); | 192 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); |
191 } | 193 } |
192 | 194 |
193 | 195 |
194 } } // namespace v8::internal | 196 } } // namespace v8::internal |
OLD | NEW |