OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 2017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 } | 2028 } |
2029 | 2029 |
2030 | 2030 |
2031 int String::WriteAscii(char* buffer, int start, int length) { | 2031 int String::WriteAscii(char* buffer, int start, int length) { |
2032 if (IsDeadCheck("v8::String::WriteAscii()")) return 0; | 2032 if (IsDeadCheck("v8::String::WriteAscii()")) return 0; |
2033 LOG_API("String::WriteAscii"); | 2033 LOG_API("String::WriteAscii"); |
2034 ASSERT(start >= 0 && length >= -1); | 2034 ASSERT(start >= 0 && length >= -1); |
2035 i::Handle<i::String> str = Utils::OpenHandle(this); | 2035 i::Handle<i::String> str = Utils::OpenHandle(this); |
2036 // Flatten the string for efficiency. This applies whether we are | 2036 // Flatten the string for efficiency. This applies whether we are |
2037 // using StringInputBuffer or Get(i) to access the characters. | 2037 // using StringInputBuffer or Get(i) to access the characters. |
2038 str->TryFlatten(); | 2038 str->TryFlatten(i::StringShape(*str)); |
2039 int end = length; | 2039 int end = length; |
2040 if ( (length == -1) || (length > str->length() - start) ) | 2040 if ( (length == -1) || (length > str->length() - start) ) |
2041 end = str->length() - start; | 2041 end = str->length() - start; |
2042 if (end < 0) return 0; | 2042 if (end < 0) return 0; |
2043 write_input_buffer.Reset(start, *str); | 2043 write_input_buffer.Reset(start, *str); |
2044 int i; | 2044 int i; |
2045 for (i = 0; i < end; i++) { | 2045 for (i = 0; i < end; i++) { |
2046 char c = static_cast<char>(write_input_buffer.GetNext()); | 2046 char c = static_cast<char>(write_input_buffer.GetNext()); |
2047 if (c == '\0') c = ' '; | 2047 if (c == '\0') c = ' '; |
2048 buffer[i] = c; | 2048 buffer[i] = c; |
2049 } | 2049 } |
2050 if (length == -1 || i < length) | 2050 if (length == -1 || i < length) |
2051 buffer[i] = '\0'; | 2051 buffer[i] = '\0'; |
2052 return i; | 2052 return i; |
2053 } | 2053 } |
2054 | 2054 |
2055 | 2055 |
2056 int String::Write(uint16_t* buffer, int start, int length) { | 2056 int String::Write(uint16_t* buffer, int start, int length) { |
2057 if (IsDeadCheck("v8::String::Write()")) return 0; | 2057 if (IsDeadCheck("v8::String::Write()")) return 0; |
2058 LOG_API("String::Write"); | 2058 LOG_API("String::Write"); |
2059 ASSERT(start >= 0 && length >= -1); | 2059 ASSERT(start >= 0 && length >= -1); |
2060 i::Handle<i::String> str = Utils::OpenHandle(this); | 2060 i::Handle<i::String> str = Utils::OpenHandle(this); |
2061 // Flatten the string for efficiency. This applies whether we are | 2061 // Flatten the string for efficiency. This applies whether we are |
2062 // using StringInputBuffer or Get(i) to access the characters. | 2062 // using StringInputBuffer or Get(i) to access the characters. |
2063 str->TryFlatten(); | 2063 str->TryFlatten(i::StringShape(*str)); |
2064 int end = length; | 2064 int end = length; |
2065 if ( (length == -1) || (length > str->length() - start) ) | 2065 if ( (length == -1) || (length > str->length() - start) ) |
2066 end = str->length() - start; | 2066 end = str->length() - start; |
2067 if (end < 0) return 0; | 2067 if (end < 0) return 0; |
2068 write_input_buffer.Reset(start, *str); | 2068 write_input_buffer.Reset(start, *str); |
2069 int i; | 2069 int i; |
2070 for (i = 0; i < end; i++) | 2070 for (i = 0; i < end; i++) |
2071 buffer[i] = write_input_buffer.GetNext(); | 2071 buffer[i] = write_input_buffer.GetNext(); |
2072 if (length == -1 || i < length) | 2072 if (length == -1 || i < length) |
2073 buffer[i] = '\0'; | 2073 buffer[i] = '\0'; |
2074 return i; | 2074 return i; |
2075 } | 2075 } |
2076 | 2076 |
2077 | 2077 |
2078 bool v8::String::IsExternal() { | 2078 bool v8::String::IsExternal() { |
2079 EnsureInitialized("v8::String::IsExternal()"); | 2079 EnsureInitialized("v8::String::IsExternal()"); |
2080 i::Handle<i::String> str = Utils::OpenHandle(this); | 2080 i::Handle<i::String> str = Utils::OpenHandle(this); |
2081 return str->IsExternalTwoByteString(); | 2081 i::StringShape shape(*str); |
| 2082 return shape.IsExternalTwoByte(); |
2082 } | 2083 } |
2083 | 2084 |
2084 | 2085 |
2085 bool v8::String::IsExternalAscii() { | 2086 bool v8::String::IsExternalAscii() { |
2086 EnsureInitialized("v8::String::IsExternalAscii()"); | 2087 EnsureInitialized("v8::String::IsExternalAscii()"); |
2087 i::Handle<i::String> str = Utils::OpenHandle(this); | 2088 i::Handle<i::String> str = Utils::OpenHandle(this); |
2088 return str->IsExternalAsciiString(); | 2089 i::StringShape shape(*str); |
| 2090 return shape.IsExternalAscii(); |
2089 } | 2091 } |
2090 | 2092 |
2091 | 2093 |
2092 v8::String::ExternalStringResource* v8::String::GetExternalStringResource() { | 2094 v8::String::ExternalStringResource* v8::String::GetExternalStringResource() { |
2093 EnsureInitialized("v8::String::GetExternalStringResource()"); | 2095 EnsureInitialized("v8::String::GetExternalStringResource()"); |
2094 i::Handle<i::String> str = Utils::OpenHandle(this); | 2096 i::Handle<i::String> str = Utils::OpenHandle(this); |
2095 ASSERT(str->IsExternalTwoByteString()); | 2097 ASSERT(str->IsExternalTwoByteString()); |
2096 void* resource = i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); | 2098 void* resource = i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
2097 return reinterpret_cast<ExternalStringResource*>(resource); | 2099 return reinterpret_cast<ExternalStringResource*>(resource); |
2098 } | 2100 } |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2966 reinterpret_cast<HandleScopeImplementer*>(storage); | 2968 reinterpret_cast<HandleScopeImplementer*>(storage); |
2967 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); | 2969 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); |
2968 ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = | 2970 ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = |
2969 &thread_local->handle_scope_data_; | 2971 &thread_local->handle_scope_data_; |
2970 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); | 2972 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); |
2971 | 2973 |
2972 return storage + ArchiveSpacePerThread(); | 2974 return storage + ArchiveSpacePerThread(); |
2973 } | 2975 } |
2974 | 2976 |
2975 } } // namespace v8::internal | 2977 } } // namespace v8::internal |
OLD | NEW |