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

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

Issue 718383003: bindings: fixed incorrect dependency of SerializedScriptValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added fast/js/structured-clone.html Created 6 years 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, 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 class DOMArrayBuffer; 48 class DOMArrayBuffer;
49 class ExceptionState; 49 class ExceptionState;
50 class MessagePort; 50 class MessagePort;
51 class WebBlobInfo; 51 class WebBlobInfo;
52 52
53 typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray; 53 typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray;
54 typedef Vector<RefPtr<DOMArrayBuffer>, 1> ArrayBufferArray; 54 typedef Vector<RefPtr<DOMArrayBuffer>, 1> ArrayBufferArray;
55 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; 55 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap;
56 typedef Vector<blink::WebBlobInfo> WebBlobInfoArray; 56 typedef Vector<blink::WebBlobInfo> WebBlobInfoArray;
57 57
58 class SerializedScriptValue final : public ThreadSafeRefCounted<SerializedScript Value> { 58 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue> {
59 public: 59 public:
60 // Increment this for each incompatible change to the wire format. 60 // Increment this for each incompatible change to the wire format.
61 // Version 2: Added StringUCharTag for UChar v8 strings. 61 // Version 2: Added StringUCharTag for UChar v8 strings.
62 // Version 3: Switched to using uuids as blob data identifiers. 62 // Version 3: Switched to using uuids as blob data identifiers.
63 // Version 4: Extended File serialization to be complete. 63 // Version 4: Extended File serialization to be complete.
64 // Version 5: Added CryptoKeyTag for Key objects. 64 // Version 5: Added CryptoKeyTag for Key objects.
65 // Version 6: Added indexed serialization for File, Blob, and FileList. 65 // Version 6: Added indexed serialization for File, Blob, and FileList.
66 // Version 7: Extended File serialization with user visibility. 66 // Version 7: Extended File serialization with user visibility.
67 static const uint32_t wireFormatVersion = 7; 67 static const uint32_t wireFormatVersion = 7;
68 68
69 ~SerializedScriptValue();
70
71 // VarInt encoding constants. 69 // VarInt encoding constants.
72 static const int varIntShift = 7; 70 static const int varIntShift = 7;
73 static const int varIntMask = (1 << varIntShift) - 1; 71 static const int varIntMask = (1 << varIntShift) - 1;
74 72
75 // If a serialization error occurs (e.g., cyclic input value) this 73 virtual ~SerializedScriptValue();
76 // function returns an empty representation, schedules a V8 exception to
77 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case
78 // the caller must not invoke any V8 operations until control returns to
79 // V8. When serialization is successful, |didThrow| is false.
80 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*);
81 static PassRefPtr<SerializedScriptValue> createFromWire(const String&);
82 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&);
83 static PassRefPtr<SerializedScriptValue> create(const String&);
84 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ;
85 static PassRefPtr<SerializedScriptValue> create();
86 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, WebBlobI nfoArray*, ExceptionState&, v8::Isolate*);
87
88 // Never throws exceptions.
89 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Isol ate*, v8::Handle<v8::Value>);
90 74
91 static PassRefPtr<SerializedScriptValue> nullValue(); 75 static PassRefPtr<SerializedScriptValue> nullValue();
92 76
93 String toWireString() const { return m_data; } 77 String toWireString() const { return m_data; }
94 void toWireBytes(Vector<char>&) const; 78 void toWireBytes(Vector<char>&) const;
95 79
96 // Deserializes the value (in the current context). Returns a null value in 80 // Deserializes the value (in the current context). Returns a null value in
97 // case of failure. 81 // case of failure.
98 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); 82 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0);
99 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const WebBlobInfoArray* = 0); 83 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const WebBlobInfoArray* = 0);
100 84
101 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray. 85 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray.
102 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 86 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3
103 // of the HTML5 spec and generates exceptions as appropriate. 87 // of the HTML5 spec and generates exceptions as appropriate.
104 // Returns true if the array was filled, or false if the passed value was no t of an appropriate type. 88 // Returns true if the array was filled, or false if the passed value was no t of an appropriate type.
105 static bool extractTransferables(v8::Isolate*, v8::Local<v8::Value>, int, Me ssagePortArray&, ArrayBufferArray&, ExceptionState&); 89 static bool extractTransferables(v8::Isolate*, v8::Local<v8::Value>, int, Me ssagePortArray&, ArrayBufferArray&, ExceptionState&);
106 90
107 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute 91 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute
108 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. 92 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM.
109 // Ok to invoke multiple times (only adds memory once). 93 // Ok to invoke multiple times (only adds memory once).
110 // The memory registration is revoked automatically in destructor. 94 // The memory registration is revoked automatically in destructor.
111 void registerMemoryAllocatedWithCurrentScriptContext(); 95 void registerMemoryAllocatedWithCurrentScriptContext();
112 96
113 private: 97 private:
98 // The followings are private, but used by SerializedScriptValueFactory.
114 enum StringDataMode { 99 enum StringDataMode {
115 StringValue, 100 StringValue,
116 WireData 101 WireData
117 }; 102 };
118 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; 103 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
119 104
120 SerializedScriptValue(); 105 SerializedScriptValue();
121 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, WebBlobInfoArray*, ExceptionState&, v8::Isolate*);
122 explicit SerializedScriptValue(const String& wireData); 106 explicit SerializedScriptValue(const String& wireData);
123 107
124 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(v8::Isolate *, ArrayBufferArray&, ExceptionState&); 108 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; }
109 String& data() { return m_data; }
110 void setData(const String& data) { m_data = data; }
111 void transferArrayBuffers(v8::Isolate*, ArrayBufferArray&, ExceptionState&);
112 ArrayBufferContentsArray* arrayBufferContentsArray() { return m_arrayBufferC ontentsArray.get(); }
125 113
114 static PassOwnPtr<ArrayBufferContentsArray> createArrayBuffers(v8::Isolate*, ArrayBufferArray&, ExceptionState&);
115
116 private:
126 String m_data; 117 String m_data;
127 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; 118 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray;
128 BlobDataHandleMap m_blobDataHandles; 119 BlobDataHandleMap m_blobDataHandles;
129 intptr_t m_externallyAllocatedMemory; 120 intptr_t m_externallyAllocatedMemory;
121
122 friend class SerializedScriptValueFactory;
130 }; 123 };
131 124
132 } // namespace blink 125 } // namespace blink
133 126
134 #endif // SerializedScriptValue_h 127 #endif // SerializedScriptValue_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/SerializationTag.h ('k') | Source/bindings/core/v8/SerializedScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698