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

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

Issue 2308053002: Handle errors in v8::ValueDeserializer by throwing exceptions. (Closed)
Patch Set: minor cleanup Created 4 years, 3 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 | « 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 template <typename OutputFunctor> 89 template <typename OutputFunctor>
90 void DecodeTest(const std::vector<uint8_t>& data, 90 void DecodeTest(const std::vector<uint8_t>& data,
91 const OutputFunctor& output_functor) { 91 const OutputFunctor& output_functor) {
92 Local<Context> context = deserialization_context(); 92 Local<Context> context = deserialization_context();
93 Context::Scope scope(context); 93 Context::Scope scope(context);
94 TryCatch try_catch(isolate()); 94 TryCatch try_catch(isolate());
95 ValueDeserializer deserializer(isolate(), &data[0], 95 ValueDeserializer deserializer(isolate(), &data[0],
96 static_cast<int>(data.size())); 96 static_cast<int>(data.size()));
97 deserializer.SetSupportsLegacyWireFormat(true); 97 deserializer.SetSupportsLegacyWireFormat(true);
98 BeforeDecode(&deserializer); 98 BeforeDecode(&deserializer);
99 ASSERT_TRUE(deserializer.ReadHeader().FromMaybe(false)); 99 ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false));
100 Local<Value> result; 100 Local<Value> result;
101 ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result)); 101 ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result));
102 ASSERT_FALSE(result.IsEmpty()); 102 ASSERT_FALSE(result.IsEmpty());
103 ASSERT_FALSE(try_catch.HasCaught()); 103 ASSERT_FALSE(try_catch.HasCaught());
104 ASSERT_TRUE( 104 ASSERT_TRUE(
105 context->Global() 105 context->Global()
106 ->CreateDataProperty(context, StringFromUtf8("result"), result) 106 ->CreateDataProperty(context, StringFromUtf8("result"), result)
107 .FromMaybe(false)); 107 .FromMaybe(false));
108 output_functor(result); 108 output_functor(result);
109 ASSERT_FALSE(try_catch.HasCaught()); 109 ASSERT_FALSE(try_catch.HasCaught());
110 } 110 }
111 111
112 template <typename OutputFunctor> 112 template <typename OutputFunctor>
113 void DecodeTestForVersion0(const std::vector<uint8_t>& data, 113 void DecodeTestForVersion0(const std::vector<uint8_t>& data,
114 const OutputFunctor& output_functor) { 114 const OutputFunctor& output_functor) {
115 Local<Context> context = deserialization_context(); 115 Local<Context> context = deserialization_context();
116 Context::Scope scope(context); 116 Context::Scope scope(context);
117 TryCatch try_catch(isolate()); 117 TryCatch try_catch(isolate());
118 ValueDeserializer deserializer(isolate(), &data[0], 118 ValueDeserializer deserializer(isolate(), &data[0],
119 static_cast<int>(data.size())); 119 static_cast<int>(data.size()));
120 deserializer.SetSupportsLegacyWireFormat(true); 120 deserializer.SetSupportsLegacyWireFormat(true);
121 BeforeDecode(&deserializer); 121 BeforeDecode(&deserializer);
122 ASSERT_TRUE(deserializer.ReadHeader().FromMaybe(false)); 122 ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false));
123 ASSERT_EQ(0, deserializer.GetWireFormatVersion()); 123 ASSERT_EQ(0, deserializer.GetWireFormatVersion());
124 Local<Value> result; 124 Local<Value> result;
125 ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result)); 125 ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result));
126 ASSERT_FALSE(result.IsEmpty()); 126 ASSERT_FALSE(result.IsEmpty());
127 ASSERT_FALSE(try_catch.HasCaught()); 127 ASSERT_FALSE(try_catch.HasCaught());
128 ASSERT_TRUE( 128 ASSERT_TRUE(
129 context->Global() 129 context->Global()
130 ->CreateDataProperty(context, StringFromUtf8("result"), result) 130 ->CreateDataProperty(context, StringFromUtf8("result"), result)
131 .FromMaybe(false)); 131 .FromMaybe(false));
132 output_functor(result); 132 output_functor(result);
133 ASSERT_FALSE(try_catch.HasCaught()); 133 ASSERT_FALSE(try_catch.HasCaught());
134 } 134 }
135 135
136 void InvalidDecodeTest(const std::vector<uint8_t>& data) { 136 void InvalidDecodeTest(const std::vector<uint8_t>& data) {
137 Local<Context> context = deserialization_context(); 137 Local<Context> context = deserialization_context();
138 Context::Scope scope(context); 138 Context::Scope scope(context);
139 TryCatch try_catch(isolate()); 139 TryCatch try_catch(isolate());
140 ValueDeserializer deserializer(isolate(), &data[0], 140 ValueDeserializer deserializer(isolate(), &data[0],
141 static_cast<int>(data.size())); 141 static_cast<int>(data.size()));
142 deserializer.SetSupportsLegacyWireFormat(true); 142 deserializer.SetSupportsLegacyWireFormat(true);
143 BeforeDecode(&deserializer); 143 BeforeDecode(&deserializer);
144 Maybe<bool> header_result = deserializer.ReadHeader(); 144 Maybe<bool> header_result = deserializer.ReadHeader(context);
145 if (header_result.IsNothing()) return; 145 if (header_result.IsNothing()) {
146 EXPECT_TRUE(try_catch.HasCaught());
147 return;
148 }
146 ASSERT_TRUE(header_result.ToChecked()); 149 ASSERT_TRUE(header_result.ToChecked());
147 ASSERT_TRUE(deserializer.ReadValue(context).IsEmpty()); 150 ASSERT_TRUE(deserializer.ReadValue(context).IsEmpty());
151 EXPECT_TRUE(try_catch.HasCaught());
148 } 152 }
149 153
150 Local<Value> EvaluateScriptForInput(const char* utf8_source) { 154 Local<Value> EvaluateScriptForInput(const char* utf8_source) {
151 Local<String> source = StringFromUtf8(utf8_source); 155 Local<String> source = StringFromUtf8(utf8_source);
152 Local<Script> script = 156 Local<Script> script =
153 Script::Compile(serialization_context_, source).ToLocalChecked(); 157 Script::Compile(serialization_context_, source).ToLocalChecked();
154 return script->Run(serialization_context_).ToLocalChecked(); 158 return script->Run(serialization_context_).ToLocalChecked();
155 } 159 }
156 160
157 bool EvaluateScriptForResultBool(const char* utf8_source) { 161 bool EvaluateScriptForResultBool(const char* utf8_source) {
(...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 } 1994 }
1991 1995
1992 TEST_F(ValueSerializerTestWithSharedArrayBufferTransfer, 1996 TEST_F(ValueSerializerTestWithSharedArrayBufferTransfer,
1993 SharedArrayBufferMustBeTransferred) { 1997 SharedArrayBufferMustBeTransferred) {
1994 // A SharedArrayBuffer which was not marked for transfer should fail encoding. 1998 // A SharedArrayBuffer which was not marked for transfer should fail encoding.
1995 InvalidEncodeTest("new SharedArrayBuffer(32)"); 1999 InvalidEncodeTest("new SharedArrayBuffer(32)");
1996 } 2000 }
1997 2001
1998 } // namespace 2002 } // namespace
1999 } // namespace v8 2003 } // 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