| 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 10 matching lines...) Expand all Loading... |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef V8ValueCache_h | 26 #ifndef V8ValueCache_h |
| 27 #define V8ValueCache_h | 27 #define V8ValueCache_h |
| 28 | 28 |
| 29 #include "bindings/core/v8/V8GlobalValueMap.h" | 29 #include "bindings/core/v8/V8GlobalValueMap.h" |
| 30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 31 #include "wtf/Allocator.h" |
| 31 #include "wtf/HashMap.h" | 32 #include "wtf/HashMap.h" |
| 32 #include "wtf/Noncopyable.h" | 33 #include "wtf/Noncopyable.h" |
| 33 #include "wtf/RefPtr.h" | 34 #include "wtf/RefPtr.h" |
| 34 #include "wtf/text/AtomicString.h" | 35 #include "wtf/text/AtomicString.h" |
| 35 #include "wtf/text/WTFString.h" | 36 #include "wtf/text/WTFString.h" |
| 36 #include <v8.h> | 37 #include <v8.h> |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 class StringCacheMapTraits : public V8GlobalValueMapTraits<StringImpl*, v8::Stri
ng, v8::kWeakWithParameter> { | 41 class StringCacheMapTraits : public V8GlobalValueMapTraits<StringImpl*, v8::Stri
ng, v8::kWeakWithParameter> { |
| 42 STATIC_ONLY(StringCacheMapTraits); |
| 41 public: | 43 public: |
| 42 // Weak traits: | 44 // Weak traits: |
| 43 typedef StringImpl WeakCallbackDataType; | 45 typedef StringImpl WeakCallbackDataType; |
| 44 typedef v8::GlobalValueMap<StringImpl*, v8::String, StringCacheMapTraits> Ma
pType; | 46 typedef v8::GlobalValueMap<StringImpl*, v8::String, StringCacheMapTraits> Ma
pType; |
| 45 | 47 |
| 46 static WeakCallbackDataType* WeakCallbackParameter( | 48 static WeakCallbackDataType* WeakCallbackParameter( |
| 47 MapType* map, StringImpl* key, v8::Local<v8::String>& value) { return ke
y; } | 49 MapType* map, StringImpl* key, v8::Local<v8::String>& value) { return ke
y; } |
| 48 static void DisposeCallbackData(WeakCallbackDataType* callbackData) { } | 50 static void DisposeCallbackData(WeakCallbackDataType* callbackData) { } |
| 49 | 51 |
| 50 static MapType* MapFromWeakCallbackInfo( | 52 static MapType* MapFromWeakCallbackInfo( |
| 51 const v8::WeakCallbackInfo<WeakCallbackDataType>&); | 53 const v8::WeakCallbackInfo<WeakCallbackDataType>&); |
| 52 | 54 |
| 53 static StringImpl* KeyFromWeakCallbackInfo( | 55 static StringImpl* KeyFromWeakCallbackInfo( |
| 54 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) | 56 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) |
| 55 { | 57 { |
| 56 return data.GetParameter(); | 58 return data.GetParameter(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 static void OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataType>&
); | 61 static void OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataType>&
); |
| 60 | 62 |
| 61 static void Dispose(v8::Isolate*, v8::Global<v8::String> value, StringImpl*
key); | 63 static void Dispose(v8::Isolate*, v8::Global<v8::String> value, StringImpl*
key); |
| 62 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>&); | 64 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>&); |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 | 67 |
| 66 class CORE_EXPORT StringCache { | 68 class CORE_EXPORT StringCache { |
| 69 WTF_MAKE_FAST_ALLOCATED(StringCache); |
| 67 WTF_MAKE_NONCOPYABLE(StringCache); | 70 WTF_MAKE_NONCOPYABLE(StringCache); |
| 68 public: | 71 public: |
| 69 explicit StringCache(v8::Isolate* isolate) : m_stringCache(isolate) { } | 72 explicit StringCache(v8::Isolate* isolate) : m_stringCache(isolate) { } |
| 70 | 73 |
| 71 v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, StringImpl* str
ingImpl) | 74 v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, StringImpl* str
ingImpl) |
| 72 { | 75 { |
| 73 ASSERT(stringImpl); | 76 ASSERT(stringImpl); |
| 74 if (m_lastStringImpl.get() == stringImpl) | 77 if (m_lastStringImpl.get() == stringImpl) |
| 75 return m_lastV8String.NewLocal(isolate); | 78 return m_lastV8String.NewLocal(isolate); |
| 76 return v8ExternalStringSlow(isolate, stringImpl); | 79 return v8ExternalStringSlow(isolate, stringImpl); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 100 | 103 |
| 101 // Note: RefPtr is a must as we cache by StringImpl* equality, not identity | 104 // Note: RefPtr is a must as we cache by StringImpl* equality, not identity |
| 102 // hence lastStringImpl might be not a key of the cache (in sense of identit
y) | 105 // hence lastStringImpl might be not a key of the cache (in sense of identit
y) |
| 103 // and hence it's not refed on addition. | 106 // and hence it's not refed on addition. |
| 104 RefPtr<StringImpl> m_lastStringImpl; | 107 RefPtr<StringImpl> m_lastStringImpl; |
| 105 }; | 108 }; |
| 106 | 109 |
| 107 } // namespace blink | 110 } // namespace blink |
| 108 | 111 |
| 109 #endif // V8ValueCache_h | 112 #endif // V8ValueCache_h |
| OLD | NEW |