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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.h

Issue 2716733006: SerializedScriptValue: Remove the 16-bit string representation. (Closed)
Patch Set: SSV::data can now be const Created 3 years, 9 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2010 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const ImageBitmapArray&, 127 const ImageBitmapArray&,
128 ExceptionState&); 128 ExceptionState&);
129 129
130 // Informs the V8 about external memory allocated and owned by this object. 130 // Informs the V8 about external memory allocated and owned by this object.
131 // Large values should contribute to GC counters to eventually trigger a GC, 131 // Large values should contribute to GC counters to eventually trigger a GC,
132 // otherwise flood of postMessage() can cause OOM. 132 // otherwise flood of postMessage() can cause OOM.
133 // Ok to invoke multiple times (only adds memory once). 133 // Ok to invoke multiple times (only adds memory once).
134 // The memory registration is revoked automatically in destructor. 134 // The memory registration is revoked automatically in destructor.
135 void registerMemoryAllocatedWithCurrentScriptContext(); 135 void registerMemoryAllocatedWithCurrentScriptContext();
136 136
137 // Provides access to the data and its attributes, regardless of whether the 137 const uint8_t* data() const { return m_dataBuffer.get(); }
138 // data was created as a string or as a vector. 138 size_t dataLengthInBytes() const { return m_dataBufferSize; }
139 // TODO(jbroman): Remove the 16-bit string representation, and simplify.
140 const uint8_t* data() {
141 if (!m_dataString.isNull()) {
142 DCHECK(!m_dataBuffer);
143 m_dataString.ensure16Bit();
144 return reinterpret_cast<const uint8_t*>(m_dataString.characters16());
145 }
146 return m_dataBuffer.get();
147 }
148 size_t dataLengthInBytes() const {
149 if (!m_dataString.isNull())
150 return m_dataString.length() * 2;
151 return m_dataBufferSize;
152 }
153 bool dataHasOneRef() const {
154 if (!m_dataString.isNull())
155 return m_dataString.impl()->hasOneRef();
156 return true;
157 }
158 139
159 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } 140 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; }
160 ArrayBufferContentsArray* getArrayBufferContentsArray() { 141 ArrayBufferContentsArray* getArrayBufferContentsArray() {
161 return m_arrayBufferContentsArray.get(); 142 return m_arrayBufferContentsArray.get();
162 } 143 }
163 ImageBitmapContentsArray* getImageBitmapContentsArray() { 144 ImageBitmapContentsArray* getImageBitmapContentsArray() {
164 return m_imageBitmapContentsArray.get(); 145 return m_imageBitmapContentsArray.get();
165 } 146 }
166 147
167 private: 148 private:
168 friend class ScriptValueSerializer; 149 friend class ScriptValueSerializer;
169 friend class V8ScriptValueSerializer; 150 friend class V8ScriptValueSerializer;
170 151
171 struct BufferDeleter { 152 struct BufferDeleter {
172 void operator()(uint8_t* buffer) { WTF::Partitions::bufferFree(buffer); } 153 void operator()(uint8_t* buffer) { WTF::Partitions::bufferFree(buffer); }
173 }; 154 };
174 using DataBufferPtr = std::unique_ptr<uint8_t[], BufferDeleter>; 155 using DataBufferPtr = std::unique_ptr<uint8_t[], BufferDeleter>;
175 156
176 SerializedScriptValue(); 157 SerializedScriptValue();
177 explicit SerializedScriptValue(const String& wireData); 158 explicit SerializedScriptValue(const String& wireData);
178 159
179 void setData(const String& data) {
180 m_dataString = data;
181 m_dataBuffer.reset();
182 m_dataBufferSize = 0;
183 }
184 void setData(DataBufferPtr data, size_t size) { 160 void setData(DataBufferPtr data, size_t size) {
185 m_dataString = String();
186 m_dataBuffer = std::move(data); 161 m_dataBuffer = std::move(data);
187 m_dataBufferSize = size; 162 m_dataBufferSize = size;
188 } 163 }
189 164
190 void transferArrayBuffers(v8::Isolate*, 165 void transferArrayBuffers(v8::Isolate*,
191 const ArrayBufferArray&, 166 const ArrayBufferArray&,
192 ExceptionState&); 167 ExceptionState&);
193 void transferImageBitmaps(v8::Isolate*, 168 void transferImageBitmaps(v8::Isolate*,
194 const ImageBitmapArray&, 169 const ImageBitmapArray&,
195 ExceptionState&); 170 ExceptionState&);
196 void transferOffscreenCanvas(v8::Isolate*, 171 void transferOffscreenCanvas(v8::Isolate*,
197 const OffscreenCanvasArray&, 172 const OffscreenCanvasArray&,
198 ExceptionState&); 173 ExceptionState&);
199 174
200 // Either:
201 // - |m_dataString| is non-null, and contains the data as a WTF::String which,
202 // when made 16-bit, is the serialized data (padded to a two-byte boundary),
203 // or
204 // - |m_dataBuffer| is non-null, and |m_dataBufferSize| contains its size;
205 // unlike |m_dataString|, that size is not guaranteed to be padded to a
206 // two-byte boundary
207 String m_dataString;
208 DataBufferPtr m_dataBuffer; 175 DataBufferPtr m_dataBuffer;
209 size_t m_dataBufferSize = 0; 176 size_t m_dataBufferSize = 0;
210 177
211 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; 178 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray;
212 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; 179 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray;
213 BlobDataHandleMap m_blobDataHandles; 180 BlobDataHandleMap m_blobDataHandles;
214 intptr_t m_externallyAllocatedMemory; 181 intptr_t m_externallyAllocatedMemory;
215 }; 182 };
216 183
217 } // namespace blink 184 } // namespace blink
218 185
219 #endif // SerializedScriptValue_h 186 #endif // SerializedScriptValue_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698