| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "api.h" | 30 #include "api.h" |
| 31 #include "debug.h" | 31 #include "debug.h" |
| 32 #include "execution.h" | 32 #include "execution.h" |
| 33 #include "factory.h" | 33 #include "factory.h" |
| 34 #include "macro-assembler.h" | 34 #include "macro-assembler.h" |
| 35 #include "objects.h" | 35 #include "objects.h" |
| 36 #include "objects-visiting.h" | 36 #include "objects-visiting.h" |
| 37 #include "platform.h" |
| 37 #include "scopeinfo.h" | 38 #include "scopeinfo.h" |
| 38 | 39 |
| 39 namespace v8 { | 40 namespace v8 { |
| 40 namespace internal { | 41 namespace internal { |
| 41 | 42 |
| 42 | 43 |
| 43 Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) { | 44 Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) { |
| 44 ASSERT(0 <= size); | 45 ASSERT(0 <= size); |
| 45 CALL_HEAP_FUNCTION( | 46 CALL_HEAP_FUNCTION( |
| 46 isolate(), | 47 isolate(), |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 return NewError("MakeEvalError", type, args); | 669 return NewError("MakeEvalError", type, args); |
| 669 } | 670 } |
| 670 | 671 |
| 671 | 672 |
| 672 Handle<Object> Factory::NewError(const char* type, | 673 Handle<Object> Factory::NewError(const char* type, |
| 673 Vector< Handle<Object> > args) { | 674 Vector< Handle<Object> > args) { |
| 674 return NewError("MakeError", type, args); | 675 return NewError("MakeError", type, args); |
| 675 } | 676 } |
| 676 | 677 |
| 677 | 678 |
| 679 Handle<String> Factory::EmergencyNewError(const char* type, |
| 680 Handle<JSArray> args) { |
| 681 const int kBufferSize = 1000; |
| 682 char buffer[kBufferSize]; |
| 683 size_t space = kBufferSize; |
| 684 char* p = &buffer[0]; |
| 685 |
| 686 Vector<char> v(buffer, kBufferSize); |
| 687 OS::StrNCpy(v, type, space); |
| 688 space -= Min(space, strlen(type)); |
| 689 p = &buffer[kBufferSize] - space; |
| 690 |
| 691 for (unsigned i = 0; i < ARRAY_SIZE(args); i++) { |
| 692 if (space > 0) { |
| 693 *p++ = ' '; |
| 694 space--; |
| 695 if (space > 0) { |
| 696 MaybeObject* maybe_arg = args->GetElement(i); |
| 697 Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg)); |
| 698 const char* arg = *arg_str->ToCString(); |
| 699 Vector<char> v2(p, space); |
| 700 OS::StrNCpy(v2, arg, space); |
| 701 space -= Min(space, strlen(arg)); |
| 702 p = &buffer[kBufferSize] - space; |
| 703 } |
| 704 } |
| 705 } |
| 706 if (space > 0) { |
| 707 *p = '\0'; |
| 708 } else { |
| 709 buffer[kBufferSize - 1] = '\0'; |
| 710 } |
| 711 Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); |
| 712 return error_string; |
| 713 } |
| 714 |
| 715 |
| 678 Handle<Object> Factory::NewError(const char* maker, | 716 Handle<Object> Factory::NewError(const char* maker, |
| 679 const char* type, | 717 const char* type, |
| 680 Handle<JSArray> args) { | 718 Handle<JSArray> args) { |
| 681 Handle<String> make_str = LookupAsciiSymbol(maker); | 719 Handle<String> make_str = LookupAsciiSymbol(maker); |
| 682 Handle<Object> fun_obj( | 720 Handle<Object> fun_obj( |
| 683 isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str)); | 721 isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str)); |
| 684 // If the builtins haven't been properly configured yet this error | 722 // If the builtins haven't been properly configured yet this error |
| 685 // constructor may not have been defined. Bail out. | 723 // constructor may not have been defined. Bail out. |
| 686 if (!fun_obj->IsJSFunction()) | 724 if (!fun_obj->IsJSFunction()) { |
| 687 return undefined_value(); | 725 return EmergencyNewError(type, args); |
| 726 } |
| 688 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); | 727 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
| 689 Handle<Object> type_obj = LookupAsciiSymbol(type); | 728 Handle<Object> type_obj = LookupAsciiSymbol(type); |
| 690 Handle<Object> argv[] = { type_obj, args }; | 729 Handle<Object> argv[] = { type_obj, args }; |
| 691 | 730 |
| 692 // Invoke the JavaScript factory method. If an exception is thrown while | 731 // Invoke the JavaScript factory method. If an exception is thrown while |
| 693 // running the factory method, use the exception as the result. | 732 // running the factory method, use the exception as the result. |
| 694 bool caught_exception; | 733 bool caught_exception; |
| 695 Handle<Object> result = Execution::TryCall(fun, | 734 Handle<Object> result = Execution::TryCall(fun, |
| 696 isolate()->js_builtins_object(), | 735 isolate()->js_builtins_object(), |
| 697 ARRAY_SIZE(argv), | 736 ARRAY_SIZE(argv), |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 | 1480 |
| 1442 | 1481 |
| 1443 Handle<Object> Factory::ToBoolean(bool value) { | 1482 Handle<Object> Factory::ToBoolean(bool value) { |
| 1444 return Handle<Object>(value | 1483 return Handle<Object>(value |
| 1445 ? isolate()->heap()->true_value() | 1484 ? isolate()->heap()->true_value() |
| 1446 : isolate()->heap()->false_value()); | 1485 : isolate()->heap()->false_value()); |
| 1447 } | 1486 } |
| 1448 | 1487 |
| 1449 | 1488 |
| 1450 } } // namespace v8::internal | 1489 } } // namespace v8::internal |
| OLD | NEW |