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

Side by Side Diff: test/unittests/value-serializer-unittest.cc

Issue 2492943002: ValueSerializer: Replace use of std::vector with a delegate-allocated buffer. (Closed)
Patch Set: correct comment Created 4 years, 1 month 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 | « src/value-serializer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/value-serializer.h" 5 #include "src/value-serializer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "include/v8.h" 10 #include "include/v8.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 Maybe<std::vector<uint8_t>> DoEncode(Local<Value> value) { 105 Maybe<std::vector<uint8_t>> DoEncode(Local<Value> value) {
106 Local<Context> context = serialization_context(); 106 Local<Context> context = serialization_context();
107 ValueSerializer serializer(isolate(), GetSerializerDelegate()); 107 ValueSerializer serializer(isolate(), GetSerializerDelegate());
108 BeforeEncode(&serializer); 108 BeforeEncode(&serializer);
109 serializer.WriteHeader(); 109 serializer.WriteHeader();
110 if (!serializer.WriteValue(context, value).FromMaybe(false)) { 110 if (!serializer.WriteValue(context, value).FromMaybe(false)) {
111 return Nothing<std::vector<uint8_t>>(); 111 return Nothing<std::vector<uint8_t>>();
112 } 112 }
113 AfterEncode(); 113 AfterEncode();
114 return Just(serializer.ReleaseBuffer()); 114 std::pair<uint8_t*, size_t> buffer = serializer.Release();
115 std::vector<uint8_t> result(buffer.first, buffer.first + buffer.second);
116 free(buffer.first);
117 return Just(std::move(result));
115 } 118 }
116 119
117 template <typename InputFunctor, typename EncodedDataFunctor> 120 template <typename InputFunctor, typename EncodedDataFunctor>
118 void EncodeTest(const InputFunctor& input_functor, 121 void EncodeTest(const InputFunctor& input_functor,
119 const EncodedDataFunctor& encoded_data_functor) { 122 const EncodedDataFunctor& encoded_data_functor) {
120 Context::Scope scope(serialization_context()); 123 Context::Scope scope(serialization_context());
121 TryCatch try_catch(isolate()); 124 TryCatch try_catch(isolate());
122 Local<Value> input_value = input_functor(); 125 Local<Value> input_value = input_functor();
123 std::vector<uint8_t> buffer; 126 std::vector<uint8_t> buffer;
124 ASSERT_TRUE(DoEncode(input_value).To(&buffer)); 127 ASSERT_TRUE(DoEncode(input_value).To(&buffer));
(...skipping 2399 matching lines...) Expand 10 before | Expand all | Expand 10 after
2524 InvalidDecodeTest(raw); 2527 InvalidDecodeTest(raw);
2525 } 2528 }
2526 2529
2527 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { 2530 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) {
2528 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); 2531 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00});
2529 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); 2532 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f});
2530 } 2533 }
2531 2534
2532 } // namespace 2535 } // namespace
2533 } // namespace v8 2536 } // namespace v8
OLDNEW
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698