OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 } | 790 } |
791 if (string->IsAsciiRepresentation() && !force_two_byte) { | 791 if (string->IsAsciiRepresentation() && !force_two_byte) { |
792 char* data = new char[string->length()]; | 792 char* data = new char[string->length()]; |
793 String::WriteToFlat(*string, data, 0, string->length()); | 793 String::WriteToFlat(*string, data, 0, string->length()); |
794 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource( | 794 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource( |
795 data, string->length()); | 795 data, string->length()); |
796 result = string->MakeExternal(resource); | 796 result = string->MakeExternal(resource); |
797 if (result && !string->IsSymbol()) { | 797 if (result && !string->IsSymbol()) { |
798 i::ExternalStringTable::AddString(*string); | 798 i::ExternalStringTable::AddString(*string); |
799 } | 799 } |
| 800 if (!result) delete resource; |
800 } else { | 801 } else { |
801 uc16* data = new uc16[string->length()]; | 802 uc16* data = new uc16[string->length()]; |
802 String::WriteToFlat(*string, data, 0, string->length()); | 803 String::WriteToFlat(*string, data, 0, string->length()); |
803 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource( | 804 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource( |
804 data, string->length()); | 805 data, string->length()); |
805 result = string->MakeExternal(resource); | 806 result = string->MakeExternal(resource); |
806 if (result && !string->IsSymbol()) { | 807 if (result && !string->IsSymbol()) { |
807 i::ExternalStringTable::AddString(*string); | 808 i::ExternalStringTable::AddString(*string); |
808 } | 809 } |
| 810 if (!result) delete resource; |
809 } | 811 } |
810 if (!result) { | 812 if (!result) { |
811 return v8::ThrowException(v8::String::New("externalizeString() failed.")); | 813 return v8::ThrowException(v8::String::New("externalizeString() failed.")); |
812 } | 814 } |
813 return v8::Undefined(); | 815 return v8::Undefined(); |
814 } | 816 } |
815 | 817 |
816 | 818 |
817 v8::Handle<v8::Value> ExternalizeStringExtension::IsAscii( | 819 v8::Handle<v8::Value> ExternalizeStringExtension::IsAscii( |
818 const v8::Arguments& args) { | 820 const v8::Arguments& args) { |
819 if (args.Length() != 1 || !args[0]->IsString()) { | 821 if (args.Length() != 1 || !args[0]->IsString()) { |
820 return v8::ThrowException(v8::String::New( | 822 return v8::ThrowException(v8::String::New( |
821 "isAsciiString() requires a single string argument.")); | 823 "isAsciiString() requires a single string argument.")); |
822 } | 824 } |
823 return Utils::OpenHandle(*args[0].As<v8::String>())->IsAsciiRepresentation() ? | 825 return Utils::OpenHandle(*args[0].As<v8::String>())->IsAsciiRepresentation() ? |
824 v8::True() : v8::False(); | 826 v8::True() : v8::False(); |
825 } | 827 } |
826 | 828 |
827 | 829 |
828 static ExternalizeStringExtension externalize_extension; | 830 static ExternalizeStringExtension externalize_extension; |
829 static v8::DeclareExtension externalize_extension_declaration( | 831 static v8::DeclareExtension externalize_extension_declaration( |
830 &externalize_extension); | 832 &externalize_extension); |
831 | 833 |
832 } } // namespace v8::internal | 834 } } // namespace v8::internal |
OLD | NEW |