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 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 } | 1855 } |
1856 | 1856 |
1857 | 1857 |
1858 v8::Local<Value> v8::TryCatch::StackTrace() const { | 1858 v8::Local<Value> v8::TryCatch::StackTrace() const { |
1859 ASSERT(isolate_ == i::Isolate::Current()); | 1859 ASSERT(isolate_ == i::Isolate::Current()); |
1860 if (HasCaught()) { | 1860 if (HasCaught()) { |
1861 i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); | 1861 i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); |
1862 if (!raw_obj->IsJSObject()) return v8::Local<Value>(); | 1862 if (!raw_obj->IsJSObject()) return v8::Local<Value>(); |
1863 i::HandleScope scope(isolate_); | 1863 i::HandleScope scope(isolate_); |
1864 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); | 1864 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); |
1865 i::Handle<i::String> name = isolate_->factory()->stack_symbol(); | 1865 i::Handle<i::String> name = |
| 1866 isolate_->factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("stack")); |
1866 if (!obj->HasProperty(*name)) return v8::Local<Value>(); | 1867 if (!obj->HasProperty(*name)) return v8::Local<Value>(); |
1867 i::Handle<i::Object> value = i::GetProperty(obj, name); | 1868 i::Handle<i::Object> value = i::GetProperty(obj, name); |
1868 if (value.is_null()) return v8::Local<Value>(); | 1869 if (value.is_null()) return v8::Local<Value>(); |
1869 return v8::Utils::ToLocal(scope.CloseAndEscape(value)); | 1870 return v8::Utils::ToLocal(scope.CloseAndEscape(value)); |
1870 } else { | 1871 } else { |
1871 return v8::Local<Value>(); | 1872 return v8::Local<Value>(); |
1872 } | 1873 } |
1873 } | 1874 } |
1874 | 1875 |
1875 | 1876 |
(...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3885 | 3886 |
3886 bool String::MayContainNonAscii() const { | 3887 bool String::MayContainNonAscii() const { |
3887 i::Handle<i::String> str = Utils::OpenHandle(this); | 3888 i::Handle<i::String> str = Utils::OpenHandle(this); |
3888 if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) { | 3889 if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) { |
3889 return false; | 3890 return false; |
3890 } | 3891 } |
3891 return !str->HasOnlyAsciiChars(); | 3892 return !str->HasOnlyAsciiChars(); |
3892 } | 3893 } |
3893 | 3894 |
3894 | 3895 |
3895 bool String::IsOneByte() const { | |
3896 i::Handle<i::String> str = Utils::OpenHandle(this); | |
3897 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsOneByte()")) { | |
3898 return false; | |
3899 } | |
3900 return str->IsOneByteConvertible(); | |
3901 } | |
3902 | |
3903 | |
3904 class Utf8LengthVisitor { | 3896 class Utf8LengthVisitor { |
3905 public: | 3897 public: |
3906 explicit Utf8LengthVisitor() | 3898 explicit Utf8LengthVisitor() |
3907 : utf8_length_(0), | 3899 : utf8_length_(0), |
3908 last_character_(unibrow::Utf16::kNoPreviousCharacter) {} | 3900 last_character_(unibrow::Utf16::kNoPreviousCharacter) {} |
3909 | 3901 |
3910 inline int GetLength() { | 3902 inline int GetLength() { |
3911 return utf8_length_; | 3903 return utf8_length_; |
3912 } | 3904 } |
3913 | 3905 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4195 if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' '; | 4187 if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' '; |
4196 buffer[i] = c; | 4188 buffer[i] = c; |
4197 } | 4189 } |
4198 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) { | 4190 if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) { |
4199 buffer[i] = '\0'; | 4191 buffer[i] = '\0'; |
4200 } | 4192 } |
4201 return i; | 4193 return i; |
4202 } | 4194 } |
4203 | 4195 |
4204 | 4196 |
4205 template<typename CharType> | |
4206 struct WriteHelper { | |
4207 static inline int Write(const String* string, | |
4208 CharType* buffer, | |
4209 int start, | |
4210 int length, | |
4211 int options) { | |
4212 i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); | |
4213 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; | |
4214 LOG_API(isolate, "String::Write"); | |
4215 ENTER_V8(isolate); | |
4216 ASSERT(start >= 0 && length >= -1); | |
4217 i::Handle<i::String> str = Utils::OpenHandle(string); | |
4218 isolate->string_tracker()->RecordWrite(str); | |
4219 if (options & String::HINT_MANY_WRITES_EXPECTED) { | |
4220 // Flatten the string for efficiency. This applies whether we are | |
4221 // using StringCharacterStream or Get(i) to access the characters. | |
4222 FlattenString(str); | |
4223 } | |
4224 int end = start + length; | |
4225 if ((length == -1) || (length > str->length() - start) ) | |
4226 end = str->length(); | |
4227 if (end < 0) return 0; | |
4228 i::String::WriteToFlat(*str, buffer, start, end); | |
4229 if (!(options & String::NO_NULL_TERMINATION) && | |
4230 (length == -1 || end - start < length)) { | |
4231 buffer[end - start] = '\0'; | |
4232 } | |
4233 return end - start; | |
4234 } | |
4235 }; | |
4236 | |
4237 | |
4238 int String::WriteOneByte(uint8_t* buffer, | |
4239 int start, | |
4240 int length, | |
4241 int options) const { | |
4242 return WriteHelper<uint8_t>::Write(this, buffer, start, length, options); | |
4243 } | |
4244 | |
4245 | |
4246 int String::Write(uint16_t* buffer, | 4197 int String::Write(uint16_t* buffer, |
4247 int start, | 4198 int start, |
4248 int length, | 4199 int length, |
4249 int options) const { | 4200 int options) const { |
4250 return WriteHelper<uint16_t>::Write(this, buffer, start, length, options); | 4201 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 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; |
4251 } | 4223 } |
4252 | 4224 |
4253 | 4225 |
4254 bool v8::String::IsExternal() const { | 4226 bool v8::String::IsExternal() const { |
4255 i::Handle<i::String> str = Utils::OpenHandle(this); | 4227 i::Handle<i::String> str = Utils::OpenHandle(this); |
4256 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { | 4228 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { |
4257 return false; | 4229 return false; |
4258 } | 4230 } |
4259 EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); | 4231 EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
4260 return i::StringShape(*str).IsExternalTwoByte(); | 4232 return i::StringShape(*str).IsExternalTwoByte(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4428 | 4400 |
4429 | 4401 |
4430 static void* ExternalValue(i::Object* obj) { | 4402 static void* ExternalValue(i::Object* obj) { |
4431 // Obscure semantics for undefined, but somehow checked in our unit tests... | 4403 // Obscure semantics for undefined, but somehow checked in our unit tests... |
4432 if (obj->IsUndefined()) return NULL; | 4404 if (obj->IsUndefined()) return NULL; |
4433 i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); | 4405 i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); |
4434 return i::Foreign::cast(foreign)->foreign_address(); | 4406 return i::Foreign::cast(foreign)->foreign_address(); |
4435 } | 4407 } |
4436 | 4408 |
4437 | 4409 |
| 4410 void* Object::GetPointerFromInternalField(int index) { |
| 4411 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4412 const char* location = "v8::Object::GetPointerFromInternalField()"; |
| 4413 if (!InternalFieldOK(obj, index, location)) return NULL; |
| 4414 return ExternalValue(obj->GetInternalField(index)); |
| 4415 } |
| 4416 |
| 4417 |
4438 // --- E n v i r o n m e n t --- | 4418 // --- E n v i r o n m e n t --- |
4439 | 4419 |
4440 | 4420 |
4441 bool v8::V8::Initialize() { | 4421 bool v8::V8::Initialize() { |
4442 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); | 4422 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
4443 if (isolate != NULL && isolate->IsInitialized()) { | 4423 if (isolate != NULL && isolate->IsInitialized()) { |
4444 return true; | 4424 return true; |
4445 } | 4425 } |
4446 return InitializeHelper(); | 4426 return InitializeHelper(); |
4447 } | 4427 } |
(...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6767 | 6747 |
6768 v->VisitPointers(blocks_.first(), first_block_limit_); | 6748 v->VisitPointers(blocks_.first(), first_block_limit_); |
6769 | 6749 |
6770 for (int i = 1; i < blocks_.length(); i++) { | 6750 for (int i = 1; i < blocks_.length(); i++) { |
6771 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 6751 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
6772 } | 6752 } |
6773 } | 6753 } |
6774 | 6754 |
6775 | 6755 |
6776 } } // namespace v8::internal | 6756 } } // namespace v8::internal |
OLD | NEW |