Chromium Code Reviews| Index: src/value-serializer.cc |
| diff --git a/src/value-serializer.cc b/src/value-serializer.cc |
| index 066d4250a88e734abe5f77bb727d8b4afb233d07..88b9d2b0c245a7adfc17b3623be918cb6c50922a 100644 |
| --- a/src/value-serializer.cc |
| +++ b/src/value-serializer.cc |
| @@ -90,6 +90,8 @@ enum class SerializationTag : uint8_t { |
| kBeginJSSet = '\'', |
| // End of a JS set. length:uint32_t. |
| kEndJSSet = ',', |
| + // Array buffer. byteLength:uint32_t, then draw data. |
|
Jakob Kummerow
2016/08/25 08:59:36
nit: s/draw/raw/?
|
| + kArrayBuffer = 'B', |
| }; |
| ValueSerializer::ValueSerializer(Isolate* isolate) |
| @@ -158,6 +160,11 @@ void ValueSerializer::WriteTwoByteString(Vector<const uc16> chars) { |
| reinterpret_cast<const uint8_t*>(chars.end())); |
| } |
| +void ValueSerializer::WriteRawBytes(const void* source, size_t length) { |
| + const uint8_t* begin = reinterpret_cast<const uint8_t*>(source); |
| + buffer_.insert(buffer_.end(), begin, begin + length); |
| +} |
| + |
| uint8_t* ValueSerializer::ReserveRawBytes(size_t bytes) { |
| if (!bytes) return nullptr; |
| auto old_size = buffer_.size(); |
| @@ -301,6 +308,8 @@ Maybe<bool> ValueSerializer::WriteJSReceiver(Handle<JSReceiver> receiver) { |
| return WriteJSMap(Handle<JSMap>::cast(receiver)); |
| case JS_SET_TYPE: |
| return WriteJSSet(Handle<JSSet>::cast(receiver)); |
| + case JS_ARRAY_BUFFER_TYPE: |
| + return WriteJSArrayBuffer(JSArrayBuffer::cast(*receiver)); |
| default: |
| UNIMPLEMENTED(); |
| break; |
| @@ -490,6 +499,17 @@ Maybe<bool> ValueSerializer::WriteJSSet(Handle<JSSet> set) { |
| return Just(true); |
| } |
| +Maybe<bool> ValueSerializer::WriteJSArrayBuffer(JSArrayBuffer* array_buffer) { |
| + if (array_buffer->was_neutered()) return Nothing<bool>(); |
| + double byte_length = array_buffer->byte_length()->Number(); |
| + if (byte_length > std::numeric_limits<uint32_t>::max()) |
| + return Nothing<bool>(); |
|
Jakob Kummerow
2016/08/25 08:59:36
nit: {}
|
| + WriteTag(SerializationTag::kArrayBuffer); |
| + WriteVarint<uint32_t>(byte_length); |
| + WriteRawBytes(array_buffer->backing_store(), byte_length); |
| + return Just(true); |
| +} |
| + |
| Maybe<uint32_t> ValueSerializer::WriteJSObjectProperties( |
| Handle<JSObject> object, Handle<FixedArray> keys) { |
| uint32_t properties_written = 0; |
| @@ -683,6 +703,8 @@ MaybeHandle<Object> ValueDeserializer::ReadObject() { |
| return ReadJSMap(); |
| case SerializationTag::kBeginJSSet: |
| return ReadJSSet(); |
| + case SerializationTag::kArrayBuffer: |
| + return ReadJSArrayBuffer(); |
| default: |
| return MaybeHandle<Object>(); |
| } |
| @@ -951,6 +973,24 @@ MaybeHandle<JSSet> ValueDeserializer::ReadJSSet() { |
| return scope.CloseAndEscape(set); |
| } |
| +MaybeHandle<JSArrayBuffer> ValueDeserializer::ReadJSArrayBuffer() { |
| + uint32_t id = next_id_++; |
| + uint32_t byte_length; |
| + Vector<const uint8_t> bytes; |
| + if (!ReadVarint<uint32_t>().To(&byte_length) || |
| + byte_length > static_cast<size_t>(end_ - position_)) { |
| + return MaybeHandle<JSArrayBuffer>(); |
| + } |
| + const bool should_initialize = false; |
| + Handle<JSArrayBuffer> array_buffer = isolate_->factory()->NewJSArrayBuffer(); |
| + JSArrayBuffer::SetupAllocatingData(array_buffer, isolate_, byte_length, |
| + should_initialize); |
| + memcpy(array_buffer->backing_store(), position_, byte_length); |
| + position_ += byte_length; |
| + AddObjectWithID(id, array_buffer); |
| + return array_buffer; |
| +} |
| + |
| Maybe<uint32_t> ValueDeserializer::ReadJSObjectProperties( |
| Handle<JSObject> object, SerializationTag end_tag) { |
| for (uint32_t num_properties = 0;; num_properties++) { |