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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 Factory* factory = isolate->factory(); | 154 Factory* factory = isolate->factory(); |
155 Handle<String> fmt_str = | 155 Handle<String> fmt_str = |
156 factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("FormatMessage")); | 156 factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("FormatMessage")); |
157 Handle<JSFunction> fun = Handle<JSFunction>::cast( | 157 Handle<JSFunction> fun = Handle<JSFunction>::cast( |
158 GlobalObject::GetPropertyNoExceptionThrown( | 158 GlobalObject::GetPropertyNoExceptionThrown( |
159 isolate->js_builtins_object(), fmt_str)); | 159 isolate->js_builtins_object(), fmt_str)); |
160 Handle<JSMessageObject> message = Handle<JSMessageObject>::cast(data); | 160 Handle<JSMessageObject> message = Handle<JSMessageObject>::cast(data); |
161 Handle<Object> argv[] = { Handle<Object>(message->type(), isolate), | 161 Handle<Object> argv[] = { Handle<Object>(message->type(), isolate), |
162 Handle<Object>(message->arguments(), isolate) }; | 162 Handle<Object>(message->arguments(), isolate) }; |
163 | 163 |
164 bool caught_exception; | 164 MaybeHandle<Object> maybe_result = Execution::TryCall( |
165 Handle<Object> result = | 165 fun, isolate->js_builtins_object(), ARRAY_SIZE(argv), argv); |
166 Execution::TryCall(fun, | 166 Handle<Object> result; |
167 isolate->js_builtins_object(), | 167 if (!maybe_result.ToHandle(&result) || !result->IsString()) { |
168 ARRAY_SIZE(argv), | |
169 argv, | |
170 &caught_exception); | |
171 | |
172 if (caught_exception || !result->IsString()) { | |
173 return factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("<error>")); | 168 return factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("<error>")); |
174 } | 169 } |
175 Handle<String> result_string = Handle<String>::cast(result); | 170 Handle<String> result_string = Handle<String>::cast(result); |
176 // A string that has been obtained from JS code in this way is | 171 // 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 | 172 // 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 | 173 // here to improve the efficiency of converting it to a C string and |
179 // other operations that are likely to take place (see GetLocalizedMessage | 174 // other operations that are likely to take place (see GetLocalizedMessage |
180 // for example). | 175 // for example). |
181 result_string = String::Flatten(result_string); | 176 result_string = String::Flatten(result_string); |
182 return result_string; | 177 return result_string; |
183 } | 178 } |
184 | 179 |
185 | 180 |
186 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( | 181 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( |
187 Isolate* isolate, | 182 Isolate* isolate, |
188 Handle<Object> data) { | 183 Handle<Object> data) { |
189 HandleScope scope(isolate); | 184 HandleScope scope(isolate); |
190 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); | 185 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); |
191 } | 186 } |
192 | 187 |
193 | 188 |
194 } } // namespace v8::internal | 189 } } // namespace v8::internal |
OLD | NEW |