Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 | 77 |
| 78 WebCoreStringResource16* stringResource = new WebCoreStringResource16(string ); | 78 WebCoreStringResource16* stringResource = new WebCoreStringResource16(string ); |
| 79 v8::Local<v8::String> newString; | 79 v8::Local<v8::String> newString; |
| 80 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr ing)) { | 80 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr ing)) { |
| 81 delete stringResource; | 81 delete stringResource; |
| 82 return v8::String::Empty(isolate); | 82 return v8::String::Empty(isolate); |
| 83 } | 83 } |
| 84 return newString; | 84 return newString; |
| 85 } | 85 } |
| 86 | 86 |
| 87 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Comp ressableString& string) | |
| 88 { | |
| 89 if (string.is8Bit()) { | |
| 90 WebCoreCompressableStringResource8* stringResource = new WebCoreCompress ableStringResource8(string); | |
| 91 v8::Local<v8::String> newString; | |
| 92 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne wString)) { | |
| 93 delete stringResource; | |
| 94 return v8::String::Empty(isolate); | |
| 95 } | |
| 96 return newString; | |
| 97 } | |
| 98 | |
| 99 WebCoreCompressableStringResource16* stringResource = new WebCoreCompressabl eStringResource16(string); | |
| 100 v8::Local<v8::String> newString; | |
| 101 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr ing)) { | |
| 102 delete stringResource; | |
| 103 return v8::String::Empty(isolate); | |
| 104 } | |
| 105 return newString; | |
| 106 } | |
| 107 | |
| 87 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St ringImpl* stringImpl) | 108 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St ringImpl* stringImpl) |
| 88 { | 109 { |
| 89 if (!stringImpl->length()) | 110 if (!stringImpl->length()) |
| 90 return v8::String::Empty(isolate); | 111 return v8::String::Empty(isolate); |
| 91 | 112 |
| 92 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s tringCache.GetReference(stringImpl); | 113 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s tringCache.GetReference(stringImpl); |
| 93 if (!cachedV8String.IsEmpty()) { | 114 if (!cachedV8String.IsEmpty()) { |
| 94 m_lastStringImpl = stringImpl; | 115 m_lastStringImpl = stringImpl; |
| 95 m_lastV8String = cachedV8String; | 116 m_lastV8String = cachedV8String; |
| 96 return m_lastV8String.NewLocal(isolate); | 117 return m_lastV8String.NewLocal(isolate); |
| 97 } | 118 } |
| 98 | 119 |
| 99 return createStringAndInsertIntoCache(isolate, stringImpl); | 120 return createStringAndInsertIntoCache(isolate, stringImpl); |
| 100 } | 121 } |
| 101 | 122 |
| 123 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, co nst CompressableString& string) | |
| 124 { | |
| 125 if (!string.length()) | |
| 126 return v8::String::Empty(isolate); | |
| 127 | |
| 128 return createStringAndInsertIntoCache(isolate, string); | |
| 129 } | |
| 130 | |
| 102 void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> return Value, StringImpl* stringImpl) | 131 void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> return Value, StringImpl* stringImpl) |
| 103 { | 132 { |
| 104 if (!stringImpl->length()) { | 133 if (!stringImpl->length()) { |
| 105 returnValue.SetEmptyString(); | 134 returnValue.SetEmptyString(); |
| 106 return; | 135 return; |
| 107 } | 136 } |
| 108 | 137 |
| 109 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s tringCache.GetReference(stringImpl); | 138 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s tringCache.GetReference(stringImpl); |
| 110 if (!cachedV8String.IsEmpty()) { | 139 if (!cachedV8String.IsEmpty()) { |
| 111 m_lastStringImpl = stringImpl; | 140 m_lastStringImpl = stringImpl; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 129 v8::UniquePersistent<v8::String> wrapper(isolate, newString); | 158 v8::UniquePersistent<v8::String> wrapper(isolate, newString); |
| 130 | 159 |
| 131 stringImpl->ref(); | 160 stringImpl->ref(); |
| 132 wrapper.MarkIndependent(); | 161 wrapper.MarkIndependent(); |
| 133 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); | 162 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); |
| 134 m_lastStringImpl = stringImpl; | 163 m_lastStringImpl = stringImpl; |
| 135 | 164 |
| 136 return newString; | 165 return newString; |
| 137 } | 166 } |
| 138 | 167 |
| 168 v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i solate, const CompressableString& string) | |
| 169 { | |
| 170 // ASSERT(!m_stringCache.Contains(stringImpl)); | |
| 171 ASSERT(string.length()); | |
| 172 | |
| 173 v8::Local<v8::String> newString = makeExternalString(isolate, string); | |
| 174 ASSERT(!newString.IsEmpty()); | |
| 175 ASSERT(newString->Length()); | |
| 176 | |
| 177 v8::UniquePersistent<v8::String> wrapper(isolate, newString); | |
| 178 | |
| 179 // TODO(hajimehoshi): I'm not sure this ref is needed. | |
| 180 // string->ref(); | |
|
haraken
2015/11/24 11:15:41
This ref is needed. If you don't have the ref, who
| |
| 181 wrapper.MarkIndependent(); | |
| 182 // m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); | |
|
haraken
2015/11/24 11:15:41
You need to put the CompressableString into the m_
hajimehoshi
2015/11/26 10:49:13
Hmm, I didn't know m_stringCache was the owner of
| |
| 183 // m_lastStringImpl = stringImpl; | |
| 184 | |
| 185 return newString; | |
| 186 } | |
| 187 | |
| 139 void StringCache::InvalidateLastString() | 188 void StringCache::InvalidateLastString() |
| 140 { | 189 { |
| 141 m_lastStringImpl = nullptr; | 190 m_lastStringImpl = nullptr; |
| 142 m_lastV8String.Reset(); | 191 m_lastV8String.Reset(); |
| 143 } | 192 } |
| 144 | 193 |
| 145 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |