Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef SerializedScriptValue_h | 31 #ifndef SerializedScriptValue_h |
| 32 #define SerializedScriptValue_h | 32 #define SerializedScriptValue_h |
| 33 | 33 |
| 34 #include "bindings/v8/BlobInfo.h" | |
| 34 #include "bindings/v8/ScriptValue.h" | 35 #include "bindings/v8/ScriptValue.h" |
| 35 | 36 |
| 36 #include "wtf/ThreadSafeRefCounted.h" | 37 #include "wtf/ThreadSafeRefCounted.h" |
| 37 #include <v8.h> | 38 #include <v8.h> |
| 38 | 39 |
| 39 namespace WTF { | 40 namespace WTF { |
| 40 | 41 |
| 41 class ArrayBuffer; | 42 class ArrayBuffer; |
| 42 class ArrayBufferContents; | 43 class ArrayBufferContents; |
| 43 | 44 |
| 44 } | 45 } |
| 45 | 46 |
| 46 namespace WebCore { | 47 namespace WebCore { |
| 47 | 48 |
| 48 class MessagePort; | 49 class MessagePort; |
| 49 | 50 |
| 50 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; | 51 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; |
| 51 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; | 52 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; |
| 52 | 53 |
| 53 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue> { | 54 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue> { |
| 54 public: | 55 public: |
| 55 virtual ~SerializedScriptValue(); | 56 virtual ~SerializedScriptValue(); |
| 56 | 57 |
| 57 // If a serialization error occurs (e.g., cyclic input value) this | 58 // If a serialization error occurs (e.g., cyclic input value) this |
| 58 // function returns an empty representation, schedules a V8 exception to | 59 // function returns an empty representation, schedules a V8 exception to |
| 59 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 60 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case |
| 60 // the caller must not invoke any V8 operations until control returns to | 61 // the caller must not invoke any V8 operations until control returns to |
| 61 // V8. When serialization is successful, |didThrow| is false. | 62 // V8. When serialization is successful, |didThrow| is false. |
| 62 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*); | 63 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, Vector<BlobInfo>*, bool& didThrow, v8::Isolate* ); |
|
jsbell
2013/09/12 22:52:17
For symmetry, a with MessagePortArray and ArrayBuf
ericu
2013/11/20 23:06:08
Huh. That won't compile, despite being identical.
| |
| 64 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Vecto r<BlobInfo>*, bool&); | |
| 65 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, bool&, v8::Isolate*); | |
| 63 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, v8::I solate*); | 66 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, v8::I solate*); |
| 64 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); | 67 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); |
| 65 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&); | 68 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&); |
| 66 static PassRefPtr<SerializedScriptValue> create(const String&); | 69 static PassRefPtr<SerializedScriptValue> create(const String&); |
| 67 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ; | 70 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ; |
| 68 static PassRefPtr<SerializedScriptValue> create(); | 71 static PassRefPtr<SerializedScriptValue> create(); |
| 69 | 72 |
| 70 // Never throws exceptions. | 73 // Never throws exceptions. |
| 71 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand le<v8::Value>, v8::Isolate*); | 74 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand le<v8::Value>, v8::Isolate*); |
| 72 | 75 |
| 73 static PassRefPtr<SerializedScriptValue> nullValue(); | 76 static PassRefPtr<SerializedScriptValue> nullValue(); |
| 74 static PassRefPtr<SerializedScriptValue> nullValue(v8::Isolate*); | 77 static PassRefPtr<SerializedScriptValue> nullValue(v8::Isolate*); |
| 75 static PassRefPtr<SerializedScriptValue> undefinedValue(); | 78 static PassRefPtr<SerializedScriptValue> undefinedValue(); |
| 76 static PassRefPtr<SerializedScriptValue> undefinedValue(v8::Isolate*); | 79 static PassRefPtr<SerializedScriptValue> undefinedValue(v8::Isolate*); |
| 77 static PassRefPtr<SerializedScriptValue> booleanValue(bool); | 80 static PassRefPtr<SerializedScriptValue> booleanValue(bool); |
| 78 static PassRefPtr<SerializedScriptValue> booleanValue(bool, v8::Isolate*); | 81 static PassRefPtr<SerializedScriptValue> booleanValue(bool, v8::Isolate*); |
| 79 static PassRefPtr<SerializedScriptValue> numberValue(double); | 82 static PassRefPtr<SerializedScriptValue> numberValue(double); |
| 80 static PassRefPtr<SerializedScriptValue> numberValue(double, v8::Isolate*); | 83 static PassRefPtr<SerializedScriptValue> numberValue(double, v8::Isolate*); |
| 81 | 84 |
| 82 static uint32_t wireFormatVersion(); | 85 static uint32_t wireFormatVersion(); |
| 83 | 86 |
| 84 PassRefPtr<SerializedScriptValue> release(); | 87 PassRefPtr<SerializedScriptValue> release(); |
| 85 | 88 |
| 86 String toWireString() const { return m_data; } | 89 String toWireString() const { return m_data; } |
| 87 void toWireBytes(Vector<char>&) const; | 90 void toWireBytes(Vector<char>&) const; |
| 88 | 91 |
| 89 // Deserializes the value (in the current context). Returns a null value in | 92 // Deserializes the value (in the current context). Returns a null value in |
| 90 // case of failure. | 93 // case of failure. |
| 91 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); | 94 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); |
| 92 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); | 95 v8::Handle<v8::Value> deserialize(const Vector<BlobInfo>*); |
| 96 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const | |
| 97 Vector<BlobInfo>* = 0); | |
| 93 | 98 |
| 94 ScriptValue deserializeForInspector(ScriptState*); | 99 ScriptValue deserializeForInspector(ScriptState*); |
| 95 | 100 |
| 96 const Vector<String>& blobURLs() const { return m_blobURLs; } | 101 const Vector<BlobInfo>* blobInfo() const { return m_blobInfo; } |
|
jsbell
2013/09/12 22:52:17
So far as I can tell, this is only used in a DCHEC
ericu
2013/11/20 23:06:08
Yup! Done.
| |
| 97 | 102 |
| 98 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute | 103 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute |
| 99 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. | 104 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. |
| 100 // Ok to invoke multiple times (only adds memory once). | 105 // Ok to invoke multiple times (only adds memory once). |
| 101 // The memory registration is revoked automatically in destructor. | 106 // The memory registration is revoked automatically in destructor. |
| 102 void registerMemoryAllocatedWithCurrentScriptContext(); | 107 void registerMemoryAllocatedWithCurrentScriptContext(); |
| 103 | 108 |
| 104 private: | 109 private: |
| 105 enum StringDataMode { | 110 enum StringDataMode { |
| 106 StringValue, | 111 StringValue, |
| 107 WireData | 112 WireData |
| 108 }; | 113 }; |
| 109 enum ExceptionPolicy { | 114 enum ExceptionPolicy { |
| 110 ThrowExceptions, | 115 ThrowExceptions, |
| 111 DoNotThrowExceptions | 116 DoNotThrowExceptions |
| 112 }; | 117 }; |
| 113 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 118 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
| 114 | 119 |
| 115 SerializedScriptValue(); | 120 SerializedScriptValue(); |
| 116 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, bool& didThrow, v8::Isolate*, ExceptionPolicy = ThrowExceptions); | 121 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, Vector<BlobInfo>*, bool& didThrow, v8::Isolate*, ExceptionPolicy = ThrowE xceptions); |
| 117 explicit SerializedScriptValue(const String& wireData); | 122 explicit SerializedScriptValue(const String& wireData); |
| 118 | 123 |
| 119 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, bool& didThrow, v8::Isolate*); | 124 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, bool& didThrow, v8::Isolate*); |
| 120 | 125 |
| 121 String m_data; | 126 String m_data; |
| 122 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 127 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 123 Vector<String> m_blobURLs; | 128 Vector<BlobInfo> *m_blobInfo; |
| 124 intptr_t m_externallyAllocatedMemory; | 129 intptr_t m_externallyAllocatedMemory; |
| 125 }; | 130 }; |
| 126 | 131 |
| 127 } // namespace WebCore | 132 } // namespace WebCore |
| 128 | 133 |
| 129 #endif // SerializedScriptValue_h | 134 #endif // SerializedScriptValue_h |
| OLD | NEW |