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