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

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

Issue 2755383004: Encapsulate optional SerializedScriptValue serialize/deserialize parameters. (Closed)
Patch Set: fuzzer 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 20 matching lines...) Expand all
31 #ifndef SerializedScriptValue_h 31 #ifndef SerializedScriptValue_h
32 #define SerializedScriptValue_h 32 #define SerializedScriptValue_h
33 33
34 #include <memory> 34 #include <memory>
35 35
36 #include "bindings/core/v8/NativeValueTraits.h" 36 #include "bindings/core/v8/NativeValueTraits.h"
37 #include "bindings/core/v8/ScriptValue.h" 37 #include "bindings/core/v8/ScriptValue.h"
38 #include "bindings/core/v8/Transferables.h" 38 #include "bindings/core/v8/Transferables.h"
39 #include "core/CoreExport.h" 39 #include "core/CoreExport.h"
40 #include "v8/include/v8.h" 40 #include "v8/include/v8.h"
41 #include "wtf/Allocator.h"
41 #include "wtf/HashMap.h" 42 #include "wtf/HashMap.h"
42 #include "wtf/ThreadSafeRefCounted.h" 43 #include "wtf/ThreadSafeRefCounted.h"
43 #include "wtf/allocator/Partitions.h" 44 #include "wtf/allocator/Partitions.h"
44 #include "wtf/typed_arrays/ArrayBufferContents.h" 45 #include "wtf/typed_arrays/ArrayBufferContents.h"
45 46
46 namespace blink { 47 namespace blink {
47 48
48 class BlobDataHandle; 49 class BlobDataHandle;
49 class Transferables; 50 class Transferables;
50 class ExceptionState; 51 class ExceptionState;
(...skipping 18 matching lines...) Expand all
69 // Version 7: Extended File serialization with user visibility. 70 // Version 7: Extended File serialization with user visibility.
70 // Version 8: File.lastModified in milliseconds (seconds-based in earlier 71 // Version 8: File.lastModified in milliseconds (seconds-based in earlier
71 // versions.) 72 // versions.)
72 // Version 9: Added Map and Set support. 73 // Version 9: Added Map and Set support.
73 static const uint32_t wireFormatVersion = 9; 74 static const uint32_t wireFormatVersion = 9;
74 75
75 // VarInt encoding constants. 76 // VarInt encoding constants.
76 static const int varIntShift = 7; 77 static const int varIntShift = 7;
77 static const int varIntMask = (1 << varIntShift) - 1; 78 static const int varIntMask = (1 << varIntShift) - 1;
78 79
80 struct SerializeOptions {
81 STACK_ALLOCATED();
82 Transferables* transferables = nullptr;
83 WebBlobInfoArray* blobInfo = nullptr;
84 };
79 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, 85 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*,
80 v8::Local<v8::Value>, 86 v8::Local<v8::Value>,
81 Transferables*, 87 const SerializeOptions&,
82 WebBlobInfoArray*,
83 ExceptionState&); 88 ExceptionState&);
84 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions( 89 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions(
85 v8::Isolate*, 90 v8::Isolate*,
86 v8::Local<v8::Value>); 91 v8::Local<v8::Value>);
87 92
88 static PassRefPtr<SerializedScriptValue> create(); 93 static PassRefPtr<SerializedScriptValue> create();
89 static PassRefPtr<SerializedScriptValue> create(const String&); 94 static PassRefPtr<SerializedScriptValue> create(const String&);
90 static PassRefPtr<SerializedScriptValue> create(const char* data, 95 static PassRefPtr<SerializedScriptValue> create(const char* data,
91 size_t length); 96 size_t length);
92 97
93 ~SerializedScriptValue(); 98 ~SerializedScriptValue();
94 99
95 static PassRefPtr<SerializedScriptValue> nullValue(); 100 static PassRefPtr<SerializedScriptValue> nullValue();
96 101
97 String toWireString() const; 102 String toWireString() const;
98 void toWireBytes(Vector<char>&) const; 103 void toWireBytes(Vector<char>&) const;
99 104
100 // Deserializes the value (in the current context). Returns a null value in 105 // Deserializes the value (in the current context). Returns a null value in
101 // case of failure. 106 // case of failure.
102 v8::Local<v8::Value> deserialize(v8::Isolate*, 107 struct DeserializeOptions {
103 MessagePortArray* = 0, 108 STACK_ALLOCATED();
104 const WebBlobInfoArray* = 0); 109 MessagePortArray* messagePorts = nullptr;
110 const WebBlobInfoArray* blobInfo = nullptr;
111 };
112 v8::Local<v8::Value> deserialize(v8::Isolate* isolate) {
113 return deserialize(isolate, DeserializeOptions());
114 }
115 v8::Local<v8::Value> deserialize(v8::Isolate*, const DeserializeOptions&);
105 116
106 // Helper function which pulls the values out of a JS sequence and into a 117 // Helper function which pulls the values out of a JS sequence and into a
107 // MessagePortArray. Also validates the elements per sections 4.1.13 and 118 // MessagePortArray. Also validates the elements per sections 4.1.13 and
108 // 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec and generates 119 // 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec and generates
109 // exceptions as appropriate. 120 // exceptions as appropriate.
110 // Returns true if the array was filled, or false if the passed value was not 121 // Returns true if the array was filled, or false if the passed value was not
111 // of an appropriate type. 122 // of an appropriate type.
112 static bool extractTransferables(v8::Isolate*, 123 static bool extractTransferables(v8::Isolate*,
113 v8::Local<v8::Value>, 124 v8::Local<v8::Value>,
114 int, 125 int,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 bool m_transferablesNeedExternalAllocationRegistration; 203 bool m_transferablesNeedExternalAllocationRegistration;
193 }; 204 };
194 205
195 template <> 206 template <>
196 struct NativeValueTraits<SerializedScriptValue> 207 struct NativeValueTraits<SerializedScriptValue>
197 : public NativeValueTraitsBase<SerializedScriptValue> { 208 : public NativeValueTraitsBase<SerializedScriptValue> {
198 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue( 209 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue(
199 v8::Isolate* isolate, 210 v8::Isolate* isolate,
200 v8::Local<v8::Value> value, 211 v8::Local<v8::Value> value,
201 ExceptionState& exceptionState) { 212 ExceptionState& exceptionState) {
202 return SerializedScriptValue::serialize(isolate, value, nullptr, nullptr, 213 return SerializedScriptValue::serialize(
203 exceptionState); 214 isolate, value, SerializedScriptValue::SerializeOptions(),
215 exceptionState);
204 } 216 }
205 }; 217 };
206 218
207 } // namespace blink 219 } // namespace blink
208 220
209 #endif // SerializedScriptValue_h 221 #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