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 4163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4174 buffer[i] = c; | 4174 buffer[i] = c; |
4175 } | 4175 } |
4176 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) { | 4176 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) { |
4177 buffer[i] = '\0'; | 4177 buffer[i] = '\0'; |
4178 } | 4178 } |
4179 return i; | 4179 return i; |
4180 } | 4180 } |
4181 | 4181 |
4182 | 4182 |
4183 template<typename CharType> | 4183 template<typename CharType> |
4184 struct WriteHelper { | 4184 static inline int WriteHelper(const String* string, |
4185 static inline int Write(const String* string, | 4185 CharType* buffer, |
4186 CharType* buffer, | 4186 int start, |
4187 int start, | 4187 int length, |
4188 int length, | 4188 int options) { |
4189 int options) { | 4189 i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); |
4190 i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); | 4190 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; |
4191 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; | 4191 LOG_API(isolate, "String::Write"); |
4192 LOG_API(isolate, "String::Write"); | 4192 ENTER_V8(isolate); |
4193 ENTER_V8(isolate); | 4193 ASSERT(start >= 0 && length >= -1); |
4194 ASSERT(start >= 0 && length >= -1); | 4194 i::Handle<i::String> str = Utils::OpenHandle(string); |
4195 i::Handle<i::String> str = Utils::OpenHandle(string); | 4195 isolate->string_tracker()->RecordWrite(str); |
4196 isolate->string_tracker()->RecordWrite(str); | 4196 if (options & String::HINT_MANY_WRITES_EXPECTED) { |
4197 if (options & String::HINT_MANY_WRITES_EXPECTED) { | 4197 // Flatten the string for efficiency. This applies whether we are |
4198 // Flatten the string for efficiency. This applies whether we are | 4198 // using StringCharacterStream or Get(i) to access the characters. |
4199 // using StringCharacterStream or Get(i) to access the characters. | 4199 FlattenString(str); |
4200 FlattenString(str); | |
4201 } | |
4202 int end = start + length; | |
4203 if ((length == -1) || (length > str->length() - start) ) | |
4204 end = str->length(); | |
4205 if (end < 0) return 0; | |
4206 i::String::WriteToFlat(*str, buffer, start, end); | |
4207 if (!(options & String::NO_NULL_TERMINATION) && | |
4208 (length == -1 || end - start < length)) { | |
4209 buffer[end - start] = '\0'; | |
4210 } | |
4211 return end - start; | |
4212 } | 4200 } |
4213 }; | 4201 int end = start + length; |
| 4202 if ((length == -1) || (length > str->length() - start) ) |
| 4203 end = str->length(); |
| 4204 if (end < 0) return 0; |
| 4205 i::String::WriteToFlat(*str, buffer, start, end); |
| 4206 if (!(options & String::NO_NULL_TERMINATION) && |
| 4207 (length == -1 || end - start < length)) { |
| 4208 buffer[end - start] = '\0'; |
| 4209 } |
| 4210 return end - start; |
| 4211 } |
4214 | 4212 |
4215 | 4213 |
4216 int String::WriteOneByte(uint8_t* buffer, | 4214 int String::WriteOneByte(uint8_t* buffer, |
4217 int start, | 4215 int start, |
4218 int length, | 4216 int length, |
4219 int options) const { | 4217 int options) const { |
4220 return WriteHelper<uint8_t>::Write(this, buffer, start, length, options); | 4218 return WriteHelper(this, buffer, start, length, options); |
4221 } | 4219 } |
4222 | 4220 |
4223 | 4221 |
4224 int String::Write(uint16_t* buffer, | 4222 int String::Write(uint16_t* buffer, |
4225 int start, | 4223 int start, |
4226 int length, | 4224 int length, |
4227 int options) const { | 4225 int options) const { |
4228 return WriteHelper<uint16_t>::Write(this, buffer, start, length, options); | 4226 return WriteHelper(this, buffer, start, length, options); |
4229 } | 4227 } |
4230 | 4228 |
4231 | 4229 |
4232 bool v8::String::IsExternal() const { | 4230 bool v8::String::IsExternal() const { |
4233 i::Handle<i::String> str = Utils::OpenHandle(this); | 4231 i::Handle<i::String> str = Utils::OpenHandle(this); |
4234 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { | 4232 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { |
4235 return false; | 4233 return false; |
4236 } | 4234 } |
4237 EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); | 4235 EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
4238 return i::StringShape(*str).IsExternalTwoByte(); | 4236 return i::StringShape(*str).IsExternalTwoByte(); |
(...skipping 2502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6741 | 6739 |
6742 v->VisitPointers(blocks_.first(), first_block_limit_); | 6740 v->VisitPointers(blocks_.first(), first_block_limit_); |
6743 | 6741 |
6744 for (int i = 1; i < blocks_.length(); i++) { | 6742 for (int i = 1; i < blocks_.length(); i++) { |
6745 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 6743 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
6746 } | 6744 } |
6747 } | 6745 } |
6748 | 6746 |
6749 | 6747 |
6750 } } // namespace v8::internal | 6748 } } // namespace v8::internal |
OLD | NEW |