| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 "externalizeString() can't externalize twice.")); | 96 "externalizeString() can't externalize twice.")); |
| 97 return; | 97 return; |
| 98 } | 98 } |
| 99 if (string->IsOneByteRepresentation() && !force_two_byte) { | 99 if (string->IsOneByteRepresentation() && !force_two_byte) { |
| 100 uint8_t* data = new uint8_t[string->length()]; | 100 uint8_t* data = new uint8_t[string->length()]; |
| 101 String::WriteToFlat(*string, data, 0, string->length()); | 101 String::WriteToFlat(*string, data, 0, string->length()); |
| 102 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource( | 102 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource( |
| 103 reinterpret_cast<char*>(data), string->length()); | 103 reinterpret_cast<char*>(data), string->length()); |
| 104 result = string->MakeExternal(resource); | 104 result = string->MakeExternal(resource); |
| 105 if (result && !string->IsInternalizedString()) { | 105 if (result && !string->IsInternalizedString()) { |
| 106 HEAP->external_string_table()->AddString(*string); | 106 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); |
| 107 isolate->heap()->external_string_table()->AddString(*string); |
| 107 } | 108 } |
| 108 if (!result) delete resource; | 109 if (!result) delete resource; |
| 109 } else { | 110 } else { |
| 110 uc16* data = new uc16[string->length()]; | 111 uc16* data = new uc16[string->length()]; |
| 111 String::WriteToFlat(*string, data, 0, string->length()); | 112 String::WriteToFlat(*string, data, 0, string->length()); |
| 112 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource( | 113 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource( |
| 113 data, string->length()); | 114 data, string->length()); |
| 114 result = string->MakeExternal(resource); | 115 result = string->MakeExternal(resource); |
| 115 if (result && !string->IsInternalizedString()) { | 116 if (result && !string->IsInternalizedString()) { |
| 116 HEAP->external_string_table()->AddString(*string); | 117 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); |
| 118 isolate->heap()->external_string_table()->AddString(*string); |
| 117 } | 119 } |
| 118 if (!result) delete resource; | 120 if (!result) delete resource; |
| 119 } | 121 } |
| 120 if (!result) { | 122 if (!result) { |
| 121 v8::ThrowException(v8::String::New("externalizeString() failed.")); | 123 v8::ThrowException(v8::String::New("externalizeString() failed.")); |
| 122 return; | 124 return; |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 | 127 |
| 126 | 128 |
| 127 void ExternalizeStringExtension::IsAscii( | 129 void ExternalizeStringExtension::IsAscii( |
| 128 const v8::FunctionCallbackInfo<v8::Value>& args) { | 130 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 129 if (args.Length() != 1 || !args[0]->IsString()) { | 131 if (args.Length() != 1 || !args[0]->IsString()) { |
| 130 v8::ThrowException(v8::String::New( | 132 v8::ThrowException(v8::String::New( |
| 131 "isAsciiString() requires a single string argument.")); | 133 "isAsciiString() requires a single string argument.")); |
| 132 return; | 134 return; |
| 133 } | 135 } |
| 134 bool is_one_byte = | 136 bool is_one_byte = |
| 135 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation(); | 137 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation(); |
| 136 args.GetReturnValue().Set(is_one_byte); | 138 args.GetReturnValue().Set(is_one_byte); |
| 137 } | 139 } |
| 138 | 140 |
| 139 | 141 |
| 140 void ExternalizeStringExtension::Register() { | 142 void ExternalizeStringExtension::Register() { |
| 141 static ExternalizeStringExtension externalize_extension; | 143 static ExternalizeStringExtension externalize_extension; |
| 142 static v8::DeclareExtension declaration(&externalize_extension); | 144 static v8::DeclareExtension declaration(&externalize_extension); |
| 143 } | 145 } |
| 144 | 146 |
| 145 } } // namespace v8::internal | 147 } } // namespace v8::internal |
| OLD | NEW |