| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 { | 47 { |
| 48 V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastStri
ng(); | 48 V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastStri
ng(); |
| 49 data.GetParameter()->deref(); | 49 data.GetParameter()->deref(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void StringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbac
kDataType>& data) | 52 void StringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbac
kDataType>& data) |
| 53 { | 53 { |
| 54 V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastStri
ng(); | 54 V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastStri
ng(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 |
| 58 CompressibleStringCacheMapTraits::MapType* CompressibleStringCacheMapTraits::Map
FromWeakCallbackInfo( |
| 59 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) |
| 60 { |
| 61 return &(V8PerIsolateData::from(data.GetIsolate())->stringCache()->m_compres
sibleStringCache); |
| 62 } |
| 63 |
| 64 void CompressibleStringCacheMapTraits::Dispose( |
| 65 v8::Isolate* isolate, v8::Global<v8::String> value, CompressibleStringImpl*
key) |
| 66 { |
| 67 key->deref(); |
| 68 } |
| 69 |
| 70 void CompressibleStringCacheMapTraits::DisposeWeak(const v8::WeakCallbackInfo<We
akCallbackDataType>& data) |
| 71 { |
| 72 data.GetParameter()->deref(); |
| 73 } |
| 74 |
| 75 void CompressibleStringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo
<WeakCallbackDataType>& data) |
| 76 { |
| 77 } |
| 78 |
| 79 |
| 57 void StringCache::dispose() | 80 void StringCache::dispose() |
| 58 { | 81 { |
| 59 // The MapType::Dispose callback calls StringCache::InvalidateLastString, | 82 // The MapType::Dispose callback calls StringCache::InvalidateLastString, |
| 60 // which will only work while the destructor has not yet finished. Thus, | 83 // which will only work while the destructor has not yet finished. Thus, |
| 61 // we need to clear the map before the destructor has completed. | 84 // we need to clear the map before the destructor has completed. |
| 62 m_stringCache.Clear(); | 85 m_stringCache.Clear(); |
| 63 } | 86 } |
| 64 | 87 |
| 65 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri
ng& string) | 88 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri
ng& string) |
| 66 { | 89 { |
| 67 if (string.is8Bit()) { | 90 if (string.is8Bit()) { |
| 68 WebCoreStringResource8* stringResource = new WebCoreStringResource8(stri
ng); | 91 WebCoreStringResource8* stringResource = new WebCoreStringResource8(stri
ng); |
| 69 v8::Local<v8::String> newString; | 92 v8::Local<v8::String> newString; |
| 70 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne
wString)) { | 93 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne
wString)) { |
| 71 delete stringResource; | 94 delete stringResource; |
| 72 return v8::String::Empty(isolate); | 95 return v8::String::Empty(isolate); |
| 73 } | 96 } |
| 74 return newString; | 97 return newString; |
| 75 } | 98 } |
| 76 | 99 |
| 77 WebCoreStringResource16* stringResource = new WebCoreStringResource16(string
); | 100 WebCoreStringResource16* stringResource = new WebCoreStringResource16(string
); |
| 78 v8::Local<v8::String> newString; | 101 v8::Local<v8::String> newString; |
| 79 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr
ing)) { | 102 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr
ing)) { |
| 80 delete stringResource; | 103 delete stringResource; |
| 81 return v8::String::Empty(isolate); | 104 return v8::String::Empty(isolate); |
| 82 } | 105 } |
| 83 return newString; | 106 return newString; |
| 84 } | 107 } |
| 85 | 108 |
| 109 static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Comp
ressibleString& string) |
| 110 { |
| 111 if (string.is8Bit()) { |
| 112 WebCoreCompressibleStringResource8* stringResource = new WebCoreCompress
ibleStringResource8(string); |
| 113 v8::Local<v8::String> newString; |
| 114 if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&ne
wString)) { |
| 115 delete stringResource; |
| 116 return v8::String::Empty(isolate); |
| 117 } |
| 118 return newString; |
| 119 } |
| 120 |
| 121 WebCoreCompressibleStringResource16* stringResource = new WebCoreCompressibl
eStringResource16(string); |
| 122 v8::Local<v8::String> newString; |
| 123 if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newStr
ing)) { |
| 124 delete stringResource; |
| 125 return v8::String::Empty(isolate); |
| 126 } |
| 127 return newString; |
| 128 } |
| 129 |
| 86 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St
ringImpl* stringImpl) | 130 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St
ringImpl* stringImpl) |
| 87 { | 131 { |
| 88 if (!stringImpl->length()) | 132 if (!stringImpl->length()) |
| 89 return v8::String::Empty(isolate); | 133 return v8::String::Empty(isolate); |
| 90 | 134 |
| 91 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s
tringCache.GetReference(stringImpl); | 135 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s
tringCache.GetReference(stringImpl); |
| 92 if (!cachedV8String.IsEmpty()) { | 136 if (!cachedV8String.IsEmpty()) { |
| 93 m_lastStringImpl = stringImpl; | 137 m_lastStringImpl = stringImpl; |
| 94 m_lastV8String = cachedV8String; | 138 m_lastV8String = cachedV8String; |
| 95 return m_lastV8String.NewLocal(isolate); | 139 return m_lastV8String.NewLocal(isolate); |
| 96 } | 140 } |
| 97 | 141 |
| 98 return createStringAndInsertIntoCache(isolate, stringImpl); | 142 return createStringAndInsertIntoCache(isolate, stringImpl); |
| 99 } | 143 } |
| 100 | 144 |
| 145 v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, co
nst CompressibleString& string) |
| 146 { |
| 147 if (!string.length()) |
| 148 return v8::String::Empty(isolate); |
| 149 |
| 150 return createStringAndInsertIntoCache(isolate, string); |
| 151 } |
| 152 |
| 101 void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> return
Value, StringImpl* stringImpl) | 153 void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> return
Value, StringImpl* stringImpl) |
| 102 { | 154 { |
| 103 if (!stringImpl->length()) { | 155 if (!stringImpl->length()) { |
| 104 returnValue.SetEmptyString(); | 156 returnValue.SetEmptyString(); |
| 105 return; | 157 return; |
| 106 } | 158 } |
| 107 | 159 |
| 108 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s
tringCache.GetReference(stringImpl); | 160 StringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_s
tringCache.GetReference(stringImpl); |
| 109 if (!cachedV8String.IsEmpty()) { | 161 if (!cachedV8String.IsEmpty()) { |
| 110 m_lastStringImpl = stringImpl; | 162 m_lastStringImpl = stringImpl; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 128 v8::UniquePersistent<v8::String> wrapper(isolate, newString); | 180 v8::UniquePersistent<v8::String> wrapper(isolate, newString); |
| 129 | 181 |
| 130 stringImpl->ref(); | 182 stringImpl->ref(); |
| 131 wrapper.MarkIndependent(); | 183 wrapper.MarkIndependent(); |
| 132 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); | 184 m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String); |
| 133 m_lastStringImpl = stringImpl; | 185 m_lastStringImpl = stringImpl; |
| 134 | 186 |
| 135 return newString; | 187 return newString; |
| 136 } | 188 } |
| 137 | 189 |
| 190 v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i
solate, const CompressibleString& string) |
| 191 { |
| 192 CompressibleStringImpl* stringImpl = string.impl().get(); |
| 193 |
| 194 ASSERT(!m_compressibleStringCache.Contains(stringImpl)); |
| 195 ASSERT(stringImpl->originalLength()); |
| 196 |
| 197 v8::Local<v8::String> newString = makeExternalString(isolate, string); |
| 198 ASSERT(!newString.IsEmpty()); |
| 199 ASSERT(newString->Length()); |
| 200 |
| 201 v8::UniquePersistent<v8::String> wrapper(isolate, newString); |
| 202 |
| 203 stringImpl->ref(); |
| 204 wrapper.MarkIndependent(); |
| 205 CompressibleStringCacheMapTraits::MapType::PersistentValueReference unused; |
| 206 m_compressibleStringCache.Set(stringImpl, wrapper.Pass(), &unused); |
| 207 |
| 208 return newString; |
| 209 } |
| 210 |
| 138 void StringCache::InvalidateLastString() | 211 void StringCache::InvalidateLastString() |
| 139 { | 212 { |
| 140 m_lastStringImpl = nullptr; | 213 m_lastStringImpl = nullptr; |
| 141 m_lastV8String.Reset(); | 214 m_lastV8String.Reset(); |
| 142 } | 215 } |
| 143 | 216 |
| 144 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |