OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/execution.h" | 8 #include "src/execution.h" |
9 #include "src/heap/spaces-inl.h" | 9 #include "src/heap/spaces-inl.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), | 273 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), |
274 isolate->factory()->constructor_string()); | 274 isolate->factory()->constructor_string()); |
275 return constructor.is_identical_to(fun_); | 275 return constructor.is_identical_to(fun_); |
276 } | 276 } |
277 | 277 |
278 | 278 |
279 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, | 279 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, |
280 int template_index, | 280 int template_index, |
281 Handle<Object> arg) { | 281 Handle<Object> arg) { |
282 Factory* factory = isolate->factory(); | 282 Factory* factory = isolate->factory(); |
283 Handle<String> fmt_str = factory->InternalizeOneByteString( | 283 Handle<String> result_string; |
284 STATIC_CHAR_VECTOR("$noSideEffectToString")); | 284 if (arg->IsString()) { |
285 Handle<JSFunction> fun = Handle<JSFunction>::cast( | 285 result_string = Handle<String>::cast(arg); |
286 Object::GetProperty(isolate->js_builtins_object(), fmt_str) | 286 } else { |
287 .ToHandleChecked()); | 287 Handle<String> fmt_str = factory->InternalizeOneByteString( |
| 288 STATIC_CHAR_VECTOR("$noSideEffectToString")); |
| 289 Handle<JSFunction> fun = Handle<JSFunction>::cast( |
| 290 Object::GetProperty(isolate->js_builtins_object(), fmt_str) |
| 291 .ToHandleChecked()); |
288 | 292 |
289 MaybeHandle<Object> maybe_result = | 293 MaybeHandle<Object> maybe_result = |
290 Execution::TryCall(fun, isolate->js_builtins_object(), 1, &arg); | 294 Execution::TryCall(fun, isolate->js_builtins_object(), 1, &arg); |
291 Handle<Object> result; | 295 Handle<Object> result; |
292 if (!maybe_result.ToHandle(&result) || !result->IsString()) { | 296 if (!maybe_result.ToHandle(&result) || !result->IsString()) { |
293 return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>")); | 297 return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>")); |
| 298 } |
| 299 result_string = Handle<String>::cast(result); |
294 } | 300 } |
295 MaybeHandle<String> maybe_result_string = MessageTemplate::FormatMessage( | 301 MaybeHandle<String> maybe_result_string = MessageTemplate::FormatMessage( |
296 template_index, Handle<String>::cast(result), factory->empty_string(), | 302 template_index, result_string, factory->empty_string(), |
297 factory->empty_string()); | 303 factory->empty_string()); |
298 Handle<String> result_string; | |
299 if (!maybe_result_string.ToHandle(&result_string)) { | 304 if (!maybe_result_string.ToHandle(&result_string)) { |
300 return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>")); | 305 return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>")); |
301 } | 306 } |
302 // A string that has been obtained from JS code in this way is | 307 // A string that has been obtained from JS code in this way is |
303 // likely to be a complicated ConsString of some sort. We flatten it | 308 // likely to be a complicated ConsString of some sort. We flatten it |
304 // here to improve the efficiency of converting it to a C string and | 309 // here to improve the efficiency of converting it to a C string and |
305 // other operations that are likely to take place (see GetLocalizedMessage | 310 // other operations that are likely to take place (see GetLocalizedMessage |
306 // for example). | 311 // for example). |
307 return String::Flatten(result_string); | 312 return String::Flatten(result_string); |
308 } | 313 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 builder.AppendString(args[i++]); | 348 builder.AppendString(args[i++]); |
344 } | 349 } |
345 } else { | 350 } else { |
346 builder.AppendCharacter(*c); | 351 builder.AppendCharacter(*c); |
347 } | 352 } |
348 } | 353 } |
349 | 354 |
350 return builder.Finish(); | 355 return builder.Finish(); |
351 } | 356 } |
352 } } // namespace v8::internal | 357 } } // namespace v8::internal |
OLD | NEW |