Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: Source/bindings/core/v8/V8StringResource.h

Issue 1278983003: Adding allocator annotations to blink classes and structs. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 V8StringResource_h 26 #ifndef V8StringResource_h
27 #define V8StringResource_h 27 #define V8StringResource_h
28 28
29 #include "bindings/core/v8/ExceptionState.h" 29 #include "bindings/core/v8/ExceptionState.h"
30 #include "core/CoreExport.h" 30 #include "core/CoreExport.h"
31 #include "wtf/Allocator.h"
31 #include "wtf/Threading.h" 32 #include "wtf/Threading.h"
32 #include "wtf/text/AtomicString.h" 33 #include "wtf/text/AtomicString.h"
33 #include <v8.h> 34 #include <v8.h>
34 35
35 namespace blink { 36 namespace blink {
36 37
37 // WebCoreStringResource is a helper class for v8ExternalString. It is used 38 // WebCoreStringResource is a helper class for v8ExternalString. It is used
38 // to manage the life-cycle of the underlying buffer of the external string. 39 // to manage the life-cycle of the underlying buffer of the external string.
39 class WebCoreStringResourceBase { 40 class WebCoreStringResourceBase {
41 WTF_MAKE_FAST_ALLOCATED(WebCoreStringResourceBase);
42 WTF_MAKE_NONCOPYABLE(WebCoreStringResourceBase);
40 public: 43 public:
41 explicit WebCoreStringResourceBase(const String& string) 44 explicit WebCoreStringResourceBase(const String& string)
42 : m_plainString(string) 45 : m_plainString(string)
43 { 46 {
44 #if ENABLE(ASSERT) 47 #if ENABLE(ASSERT)
45 m_threadId = WTF::currentThread(); 48 m_threadId = WTF::currentThread();
46 #endif 49 #endif
47 ASSERT(!string.isNull()); 50 ASSERT(!string.isNull());
48 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(memoryC onsumption(string)); 51 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(memoryC onsumption(string));
49 } 52 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 static int memoryConsumption(const String& string) 103 static int memoryConsumption(const String& string)
101 { 104 {
102 return string.length() * (string.is8Bit() ? sizeof(LChar) : sizeof(UChar )); 105 return string.length() * (string.is8Bit() ? sizeof(LChar) : sizeof(UChar ));
103 } 106 }
104 #if ENABLE(ASSERT) 107 #if ENABLE(ASSERT)
105 WTF::ThreadIdentifier m_threadId; 108 WTF::ThreadIdentifier m_threadId;
106 #endif 109 #endif
107 }; 110 };
108 111
109 class WebCoreStringResource16 final : public WebCoreStringResourceBase, public v 8::String::ExternalStringResource { 112 class WebCoreStringResource16 final : public WebCoreStringResourceBase, public v 8::String::ExternalStringResource {
113 WTF_MAKE_NONCOPYABLE(WebCoreStringResource16);
110 public: 114 public:
111 explicit WebCoreStringResource16(const String& string) 115 explicit WebCoreStringResource16(const String& string)
112 : WebCoreStringResourceBase(string) 116 : WebCoreStringResourceBase(string)
113 { 117 {
114 ASSERT(!string.is8Bit()); 118 ASSERT(!string.is8Bit());
115 } 119 }
116 120
117 explicit WebCoreStringResource16(const AtomicString& string) 121 explicit WebCoreStringResource16(const AtomicString& string)
118 : WebCoreStringResourceBase(string) 122 : WebCoreStringResourceBase(string)
119 { 123 {
120 ASSERT(!string.is8Bit()); 124 ASSERT(!string.is8Bit());
121 } 125 }
122 126
123 size_t length() const override { return m_plainString.impl()->length(); } 127 size_t length() const override { return m_plainString.impl()->length(); }
124 const uint16_t* data() const override 128 const uint16_t* data() const override
125 { 129 {
126 return reinterpret_cast<const uint16_t*>(m_plainString.impl()->character s16()); 130 return reinterpret_cast<const uint16_t*>(m_plainString.impl()->character s16());
127 } 131 }
128 }; 132 };
129 133
130 class WebCoreStringResource8 final : public WebCoreStringResourceBase, public v8 ::String::ExternalOneByteStringResource { 134 class WebCoreStringResource8 final : public WebCoreStringResourceBase, public v8 ::String::ExternalOneByteStringResource {
135 WTF_MAKE_NONCOPYABLE(WebCoreStringResource8);
131 public: 136 public:
132 explicit WebCoreStringResource8(const String& string) 137 explicit WebCoreStringResource8(const String& string)
133 : WebCoreStringResourceBase(string) 138 : WebCoreStringResourceBase(string)
134 { 139 {
135 ASSERT(string.is8Bit()); 140 ASSERT(string.is8Bit());
136 } 141 }
137 142
138 explicit WebCoreStringResource8(const AtomicString& string) 143 explicit WebCoreStringResource8(const AtomicString& string)
139 : WebCoreStringResourceBase(string) 144 : WebCoreStringResourceBase(string)
140 { 145 {
(...skipping 20 matching lines...) Expand all
161 // or AtomicStrings as appropriate, using multiple typecast operators. 166 // or AtomicStrings as appropriate, using multiple typecast operators.
162 enum V8StringResourceMode { 167 enum V8StringResourceMode {
163 DefaultMode, 168 DefaultMode,
164 TreatNullAsEmptyString, 169 TreatNullAsEmptyString,
165 TreatNullAsNullString, 170 TreatNullAsNullString,
166 TreatNullAndUndefinedAsNullString 171 TreatNullAndUndefinedAsNullString
167 }; 172 };
168 173
169 template <V8StringResourceMode Mode = DefaultMode> 174 template <V8StringResourceMode Mode = DefaultMode>
170 class V8StringResource { 175 class V8StringResource {
176 STACK_ALLOCATED();
171 public: 177 public:
172 V8StringResource() 178 V8StringResource()
173 : m_mode(Externalize) 179 : m_mode(Externalize)
174 { 180 {
175 } 181 }
176 182
177 V8StringResource(v8::Local<v8::Value> object) 183 V8StringResource(v8::Local<v8::Value> object)
178 : m_v8Object(object) 184 : m_v8Object(object)
179 , m_mode(Externalize) 185 , m_mode(Externalize)
180 { 186 {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 320 }
315 321
316 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa llbackString() const 322 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa llbackString() const
317 { 323 {
318 return String(); 324 return String();
319 } 325 }
320 326
321 } // namespace blink 327 } // namespace blink
322 328
323 #endif // V8StringResource_h 329 #endif // V8StringResource_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698