| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3614 int String::Utf8Length() const { | 3614 int String::Utf8Length() const { |
| 3615 i::Handle<i::String> str = Utils::OpenHandle(this); | 3615 i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3616 if (IsDeadCheck(str->GetIsolate(), "v8::String::Utf8Length()")) return 0; | 3616 if (IsDeadCheck(str->GetIsolate(), "v8::String::Utf8Length()")) return 0; |
| 3617 return str->Utf8Length(); | 3617 return str->Utf8Length(); |
| 3618 } | 3618 } |
| 3619 | 3619 |
| 3620 | 3620 |
| 3621 int String::WriteUtf8(char* buffer, | 3621 int String::WriteUtf8(char* buffer, |
| 3622 int capacity, | 3622 int capacity, |
| 3623 int* nchars_ref, | 3623 int* nchars_ref, |
| 3624 WriteHints hints) const { | 3624 int options) const { |
| 3625 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3625 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3626 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; | 3626 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; |
| 3627 LOG_API(isolate, "String::WriteUtf8"); | 3627 LOG_API(isolate, "String::WriteUtf8"); |
| 3628 ENTER_V8(isolate); | 3628 ENTER_V8(isolate); |
| 3629 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); | 3629 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
| 3630 i::Handle<i::String> str = Utils::OpenHandle(this); | 3630 i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3631 isolate->string_tracker()->RecordWrite(str); | 3631 isolate->string_tracker()->RecordWrite(str); |
| 3632 if (hints & HINT_MANY_WRITES_EXPECTED) { | 3632 if (options & MANY_WRITES_EXPECTED) { |
| 3633 // Flatten the string for efficiency. This applies whether we are | 3633 // Flatten the string for efficiency. This applies whether we are |
| 3634 // using StringInputBuffer or Get(i) to access the characters. | 3634 // using StringInputBuffer or Get(i) to access the characters. |
| 3635 str->TryFlatten(); | 3635 str->TryFlatten(); |
| 3636 } | 3636 } |
| 3637 write_input_buffer.Reset(0, *str); | 3637 write_input_buffer.Reset(0, *str); |
| 3638 int len = str->length(); | 3638 int len = str->length(); |
| 3639 // Encode the first K - 3 bytes directly into the buffer since we | 3639 // Encode the first K - 3 bytes directly into the buffer since we |
| 3640 // know there's room for them. If no capacity is given we copy all | 3640 // know there's room for them. If no capacity is given we copy all |
| 3641 // of them here. | 3641 // of them here. |
| 3642 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); | 3642 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3662 buffer[pos + j] = intermediate[j]; | 3662 buffer[pos + j] = intermediate[j]; |
| 3663 pos += written; | 3663 pos += written; |
| 3664 nchars++; | 3664 nchars++; |
| 3665 } else { | 3665 } else { |
| 3666 // We've reached the end of the buffer | 3666 // We've reached the end of the buffer |
| 3667 break; | 3667 break; |
| 3668 } | 3668 } |
| 3669 } | 3669 } |
| 3670 } | 3670 } |
| 3671 if (nchars_ref != NULL) *nchars_ref = nchars; | 3671 if (nchars_ref != NULL) *nchars_ref = nchars; |
| 3672 if (i == len && (capacity == -1 || pos < capacity)) | 3672 if (!(options & WRITE_NO_NULL_TERMINATION) && |
| 3673 (i == len && (capacity == -1 || pos < capacity))) |
| 3673 buffer[pos++] = '\0'; | 3674 buffer[pos++] = '\0'; |
| 3674 return pos; | 3675 return pos; |
| 3675 } | 3676 } |
| 3676 | 3677 |
| 3677 | 3678 |
| 3678 int String::WriteAscii(char* buffer, | 3679 int String::WriteAscii(char* buffer, |
| 3679 int start, | 3680 int start, |
| 3680 int length, | 3681 int length, |
| 3681 WriteHints hints) const { | 3682 int options) const { |
| 3682 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3683 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3683 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; | 3684 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; |
| 3684 LOG_API(isolate, "String::WriteAscii"); | 3685 LOG_API(isolate, "String::WriteAscii"); |
| 3685 ENTER_V8(isolate); | 3686 ENTER_V8(isolate); |
| 3686 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); | 3687 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
| 3687 ASSERT(start >= 0 && length >= -1); | 3688 ASSERT(start >= 0 && length >= -1); |
| 3688 i::Handle<i::String> str = Utils::OpenHandle(this); | 3689 i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3689 isolate->string_tracker()->RecordWrite(str); | 3690 isolate->string_tracker()->RecordWrite(str); |
| 3690 if (hints & HINT_MANY_WRITES_EXPECTED) { | 3691 if (options & MANY_WRITES_EXPECTED) { |
| 3691 // Flatten the string for efficiency. This applies whether we are | 3692 // Flatten the string for efficiency. This applies whether we are |
| 3692 // using StringInputBuffer or Get(i) to access the characters. | 3693 // using StringInputBuffer or Get(i) to access the characters. |
| 3693 str->TryFlatten(); | 3694 str->TryFlatten(); |
| 3694 } | 3695 } |
| 3695 int end = length; | 3696 int end = length; |
| 3696 if ( (length == -1) || (length > str->length() - start) ) | 3697 if ( (length == -1) || (length > str->length() - start) ) |
| 3697 end = str->length() - start; | 3698 end = str->length() - start; |
| 3698 if (end < 0) return 0; | 3699 if (end < 0) return 0; |
| 3699 write_input_buffer.Reset(start, *str); | 3700 write_input_buffer.Reset(start, *str); |
| 3700 int i; | 3701 int i; |
| 3701 for (i = 0; i < end; i++) { | 3702 for (i = 0; i < end; i++) { |
| 3702 char c = static_cast<char>(write_input_buffer.GetNext()); | 3703 char c = static_cast<char>(write_input_buffer.GetNext()); |
| 3703 if (c == '\0') c = ' '; | 3704 if (c == '\0') c = ' '; |
| 3704 buffer[i] = c; | 3705 buffer[i] = c; |
| 3705 } | 3706 } |
| 3706 if (length == -1 || i < length) | 3707 if (!(options & WRITE_NO_NULL_TERMINATION) && (length == -1 || i < length)) |
| 3707 buffer[i] = '\0'; | 3708 buffer[i] = '\0'; |
| 3708 return i; | 3709 return i; |
| 3709 } | 3710 } |
| 3710 | 3711 |
| 3711 | 3712 |
| 3712 int String::Write(uint16_t* buffer, | 3713 int String::Write(uint16_t* buffer, |
| 3713 int start, | 3714 int start, |
| 3714 int length, | 3715 int length, |
| 3715 WriteHints hints) const { | 3716 int options) const { |
| 3716 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3717 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3717 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; | 3718 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; |
| 3718 LOG_API(isolate, "String::Write"); | 3719 LOG_API(isolate, "String::Write"); |
| 3719 ENTER_V8(isolate); | 3720 ENTER_V8(isolate); |
| 3720 ASSERT(start >= 0 && length >= -1); | 3721 ASSERT(start >= 0 && length >= -1); |
| 3721 i::Handle<i::String> str = Utils::OpenHandle(this); | 3722 i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3722 isolate->string_tracker()->RecordWrite(str); | 3723 isolate->string_tracker()->RecordWrite(str); |
| 3723 if (hints & HINT_MANY_WRITES_EXPECTED) { | 3724 if (options & MANY_WRITES_EXPECTED) { |
| 3724 // Flatten the string for efficiency. This applies whether we are | 3725 // Flatten the string for efficiency. This applies whether we are |
| 3725 // using StringInputBuffer or Get(i) to access the characters. | 3726 // using StringInputBuffer or Get(i) to access the characters. |
| 3726 str->TryFlatten(); | 3727 str->TryFlatten(); |
| 3727 } | 3728 } |
| 3728 int end = start + length; | 3729 int end = start + length; |
| 3729 if ((length == -1) || (length > str->length() - start) ) | 3730 if ((length == -1) || (length > str->length() - start) ) |
| 3730 end = str->length(); | 3731 end = str->length(); |
| 3731 if (end < 0) return 0; | 3732 if (end < 0) return 0; |
| 3732 i::String::WriteToFlat(*str, buffer, start, end); | 3733 i::String::WriteToFlat(*str, buffer, start, end); |
| 3733 if (length == -1 || end - start < length) { | 3734 if (!(options & WRITE_NO_NULL_TERMINATION) && |
| 3735 (length == -1 || end - start < length)) { |
| 3734 buffer[end - start] = '\0'; | 3736 buffer[end - start] = '\0'; |
| 3735 } | 3737 } |
| 3736 return end - start; | 3738 return end - start; |
| 3737 } | 3739 } |
| 3738 | 3740 |
| 3739 | 3741 |
| 3740 bool v8::String::IsExternal() const { | 3742 bool v8::String::IsExternal() const { |
| 3741 i::Handle<i::String> str = Utils::OpenHandle(this); | 3743 i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3742 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { | 3744 if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { |
| 3743 return false; | 3745 return false; |
| (...skipping 2292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6036 | 6038 |
| 6037 | 6039 |
| 6038 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 6040 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 6039 HandleScopeImplementer* scope_implementer = | 6041 HandleScopeImplementer* scope_implementer = |
| 6040 reinterpret_cast<HandleScopeImplementer*>(storage); | 6042 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 6041 scope_implementer->IterateThis(v); | 6043 scope_implementer->IterateThis(v); |
| 6042 return storage + ArchiveSpacePerThread(); | 6044 return storage + ArchiveSpacePerThread(); |
| 6043 } | 6045 } |
| 6044 | 6046 |
| 6045 } } // namespace v8::internal | 6047 } } // namespace v8::internal |
| OLD | NEW |