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 3875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3886 | 3886 |
3887 bool String::MayContainNonAscii() const { | 3887 bool String::MayContainNonAscii() const { |
3888 i::Handle<i::String> str = Utils::OpenHandle(this); | 3888 i::Handle<i::String> str = Utils::OpenHandle(this); |
3889 if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) { | 3889 if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) { |
3890 return false; | 3890 return false; |
3891 } | 3891 } |
3892 return !str->HasOnlyAsciiChars(); | 3892 return !str->HasOnlyAsciiChars(); |
3893 } | 3893 } |
3894 | 3894 |
3895 | 3895 |
3896 bool String::IsOneByte() const { | |
3897 i::Handle<i::String> str = Utils::OpenHandle(this); | |
3898 if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) { | |
Yang
2013/01/14 11:21:38
This should reflect the method name since this str
| |
3899 return false; | |
3900 } | |
3901 return str->IsOneByteConvertible(); | |
3902 } | |
3903 | |
3904 | |
3896 class Utf8LengthVisitor { | 3905 class Utf8LengthVisitor { |
3897 public: | 3906 public: |
3898 explicit Utf8LengthVisitor() | 3907 explicit Utf8LengthVisitor() |
3899 : utf8_length_(0), | 3908 : utf8_length_(0), |
3900 last_character_(unibrow::Utf16::kNoPreviousCharacter) {} | 3909 last_character_(unibrow::Utf16::kNoPreviousCharacter) {} |
3901 | 3910 |
3902 inline int GetLength() { | 3911 inline int GetLength() { |
3903 return utf8_length_; | 3912 return utf8_length_; |
3904 } | 3913 } |
3905 | 3914 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4187 if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' '; | 4196 if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' '; |
4188 buffer[i] = c; | 4197 buffer[i] = c; |
4189 } | 4198 } |
4190 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) { | 4199 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) { |
4191 buffer[i] = '\0'; | 4200 buffer[i] = '\0'; |
4192 } | 4201 } |
4193 return i; | 4202 return i; |
4194 } | 4203 } |
4195 | 4204 |
4196 | 4205 |
4206 template<typename CharType> | |
4207 struct WriteHelper { | |
4208 static inline int Write(const String* string, | |
4209 CharType* buffer, | |
4210 int start, | |
4211 int length, | |
4212 int options) { | |
4213 i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); | |
4214 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; | |
4215 LOG_API(isolate, "String::Write"); | |
4216 ENTER_V8(isolate); | |
4217 ASSERT(start >= 0 && length >= -1); | |
4218 i::Handle<i::String> str = Utils::OpenHandle(string); | |
4219 isolate->string_tracker()->RecordWrite(str); | |
4220 if (options & String::HINT_MANY_WRITES_EXPECTED) { | |
4221 // Flatten the string for efficiency. This applies whether we are | |
4222 // using StringCharacterStream or Get(i) to access the characters. | |
4223 FlattenString(str); | |
4224 } | |
4225 int end = start + length; | |
4226 if ((length == -1) || (length > str->length() - start) ) | |
4227 end = str->length(); | |
4228 if (end < 0) return 0; | |
4229 i::String::WriteToFlat(*str, buffer, start, end); | |
4230 if (!(options & String::NO_NULL_TERMINATION) && | |
4231 (length == -1 || end - start < length)) { | |
4232 buffer[end - start] = '\0'; | |
4233 } | |
4234 return end - start; | |
4235 } | |
4236 }; | |
4237 | |
4238 | |
4239 int String::WriteOneByte(uint8_t* buffer, | |
4240 int start, | |
4241 int length, | |
4242 int options) const { | |
4243 return WriteHelper<uint8_t>::Write(this, buffer, start, length, options); | |
4244 } | |
4245 | |
4246 | |
4197 int String::Write(uint16_t* buffer, | 4247 int String::Write(uint16_t* buffer, |
4198 int start, | 4248 int start, |
4199 int length, | 4249 int length, |
4200 int options) const { | 4250 int options) const { |
4201 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4251 return WriteHelper<uint16_t>::Write(this, buffer, start, length, options); |
4202 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; | |
4203 LOG_API(isolate, "String::Write"); | |
4204 ENTER_V8(isolate); | |
4205 ASSERT(start >= 0 && length >= -1); | |
4206 i::Handle<i::String> str = Utils::OpenHandle(this); | |
4207 isolate->string_tracker()->RecordWrite(str); | |
4208 if (options & HINT_MANY_WRITES_EXPECTED) { | |
4209 // Flatten the string for efficiency. This applies whether we are | |
4210 // using StringCharacterStream or Get(i) to access the characters. | |
4211 FlattenString(str); | |
4212 } | |
4213 int end = start + length; | |
4214 if ((length == -1) || (length > str->length() - start) ) | |
4215 end = str->length(); | |
4216 if (end < 0) return 0; | |
4217 i::String::WriteToFlat(*str, buffer, start, end); | |
4218 if (!(options & NO_NULL_TERMINATION) && | |
4219 (length == -1 || end - start < length)) { | |
4220 buffer[end - start] = '\0'; | |
4221 } | |
4222 return end - start; | |
4223 } | 4252 } |
4224 | 4253 |
4225 | 4254 |
4226 bool v8::String::IsExternal() const { | 4255 bool v8::String::IsExternal() const { |
4227 i::Handle<i::String> str = Utils::OpenHandle(this); | 4256 i::Handle<i::String> str = Utils::OpenHandle(this); |
4228 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { | 4257 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { |
4229 return false; | 4258 return false; |
4230 } | 4259 } |
4231 EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); | 4260 EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
4232 return i::StringShape(*str).IsExternalTwoByte(); | 4261 return i::StringShape(*str).IsExternalTwoByte(); |
(...skipping 2514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6747 | 6776 |
6748 v->VisitPointers(blocks_.first(), first_block_limit_); | 6777 v->VisitPointers(blocks_.first(), first_block_limit_); |
6749 | 6778 |
6750 for (int i = 1; i < blocks_.length(); i++) { | 6779 for (int i = 1; i < blocks_.length(); i++) { |
6751 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 6780 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
6752 } | 6781 } |
6753 } | 6782 } |
6754 | 6783 |
6755 | 6784 |
6756 } } // namespace v8::internal | 6785 } } // namespace v8::internal |
OLD | NEW |