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/messages.h" | 5 #include "src/messages.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/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 #include "src/string-builder.h" | 10 #include "src/string-builder.h" |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 if (scope.has_visited()) return isolate->factory()->empty_string(); | 393 if (scope.has_visited()) return isolate->factory()->empty_string(); |
394 | 394 |
395 Handle<String> name; | 395 Handle<String> name; |
396 Handle<String> message; | 396 Handle<String> message; |
397 Handle<Name> internal_key = isolate->factory()->internal_error_symbol(); | 397 Handle<Name> internal_key = isolate->factory()->internal_error_symbol(); |
398 Handle<String> message_string = | 398 Handle<String> message_string = |
399 isolate->factory()->NewStringFromStaticChars("message"); | 399 isolate->factory()->NewStringFromStaticChars("message"); |
400 Handle<String> name_string = isolate->factory()->name_string(); | 400 Handle<String> name_string = isolate->factory()->name_string(); |
401 LookupIterator internal_error_lookup( | 401 LookupIterator internal_error_lookup( |
402 error, internal_key, LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); | 402 error, internal_key, LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); |
403 LookupIterator message_lookup( | |
404 error, message_string, LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); | |
405 LookupIterator name_lookup(error, name_string, | |
406 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); | |
407 | 403 |
408 // Find out whether an internally created error object is on the prototype | 404 // Find out whether an internally created error object is on the prototype |
409 // chain. If the name property is found on a holder prior to the internally | 405 // chain. If the name property is found on a holder prior to the internally |
410 // created error object, use that name property. Otherwise just use the | 406 // created error object, use that name property. Otherwise just use the |
411 // constructor name to avoid triggering possible side effects. | 407 // constructor name to avoid triggering possible side effects. |
412 // Similar for the message property. If the message property shadows the | 408 // Similar for the message property. If the message property shadows the |
413 // internally created error object, use that message property. Otherwise | 409 // internally created error object, use that message property. Otherwise |
414 // use empty string as message. | 410 // use empty string as message. |
415 if (internal_error_lookup.IsFound()) { | 411 LookupIterator name_lookup(error, name_string, |
416 if (!ShadowsInternalError(isolate, &name_lookup, &internal_error_lookup)) { | 412 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); |
417 Handle<JSObject> holder = internal_error_lookup.GetHolder<JSObject>(); | 413 if (internal_error_lookup.IsFound() && |
418 name = Handle<String>(holder->constructor_name()); | 414 !ShadowsInternalError(isolate, &name_lookup, &internal_error_lookup)) { |
419 } | 415 Handle<JSObject> holder = internal_error_lookup.GetHolder<JSObject>(); |
420 if (!ShadowsInternalError(isolate, &message_lookup, | 416 name = Handle<String>(holder->constructor_name()); |
421 &internal_error_lookup)) { | 417 } else { |
422 message = isolate->factory()->empty_string(); | |
423 } | |
424 } | |
425 if (name.is_null()) { | |
426 ASSIGN_RETURN_ON_EXCEPTION( | 418 ASSIGN_RETURN_ON_EXCEPTION( |
427 isolate, name, | 419 isolate, name, |
428 GetStringifiedProperty(isolate, &name_lookup, | 420 GetStringifiedProperty(isolate, &name_lookup, |
429 isolate->factory()->Error_string()), | 421 isolate->factory()->Error_string()), |
430 String); | 422 String); |
431 } | 423 } |
432 if (message.is_null()) { | 424 |
| 425 LookupIterator message_lookup( |
| 426 error, message_string, LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); |
| 427 if (internal_error_lookup.IsFound() && |
| 428 !ShadowsInternalError(isolate, &message_lookup, &internal_error_lookup)) { |
| 429 message = isolate->factory()->empty_string(); |
| 430 } else { |
433 ASSIGN_RETURN_ON_EXCEPTION( | 431 ASSIGN_RETURN_ON_EXCEPTION( |
434 isolate, message, | 432 isolate, message, |
435 GetStringifiedProperty(isolate, &message_lookup, | 433 GetStringifiedProperty(isolate, &message_lookup, |
436 isolate->factory()->empty_string()), | 434 isolate->factory()->empty_string()), |
437 String); | 435 String); |
438 } | 436 } |
439 | 437 |
440 if (name->length() == 0) return message; | 438 if (name->length() == 0) return message; |
441 if (message->length() == 0) return name; | 439 if (message->length() == 0) return name; |
442 IncrementalStringBuilder builder(isolate); | 440 IncrementalStringBuilder builder(isolate); |
(...skipping 30 matching lines...) Expand all Loading... |
473 if (obj->IsUndefined()) return default_value; | 471 if (obj->IsUndefined()) return default_value; |
474 if (!obj->IsString()) { | 472 if (!obj->IsString()) { |
475 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, Object::ToString(isolate, obj), | 473 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, Object::ToString(isolate, obj), |
476 String); | 474 String); |
477 } | 475 } |
478 return Handle<String>::cast(obj); | 476 return Handle<String>::cast(obj); |
479 } | 477 } |
480 | 478 |
481 } // namespace internal | 479 } // namespace internal |
482 } // namespace v8 | 480 } // namespace v8 |
OLD | NEW |