diff --git a/test/unittests/value-serializer-unittest.cc b/test/unittests/value-serializer-unittest.cc index 06d38bbe4c..3a997b62ec 100644 --- a/test/unittests/value-serializer-unittest.cc +++ b/test/unittests/value-serializer-unittest.cc @@ -87,36 +87,27 @@ class ValueSerializerTest : public TestWithIsolate { } virtual void BeforeDecode(ValueDeserializer*) {} - template - void RoundTripTest(const InputFunctor& input_functor, - const OutputFunctor& output_functor) { - EncodeTest(input_functor, - [this, &output_functor](const std::vector& data) { - DecodeTest(data, output_functor); - }); + Local RoundTripTest(Local input_value) { + std::vector encoded = EncodeTest(input_value); + return DecodeTest(encoded); } // Variant for the common case where a script is used to build the original // value. - template - void RoundTripTest(const char* source, const OutputFunctor& output_functor) { - RoundTripTest([this, source]() { return EvaluateScriptForInput(source); }, - output_functor); + Local RoundTripTest(const char* source) { + return RoundTripTest(EvaluateScriptForInput(source)); } // Variant which uses JSON.parse/stringify to check the result. void RoundTripJSON(const char* source) { - RoundTripTest( - [this, source]() { - return JSON::Parse(serialization_context_, StringFromUtf8(source)) - .ToLocalChecked(); - }, - [this, source](Local value) { - ASSERT_TRUE(value->IsObject()); - EXPECT_EQ(source, Utf8Value(JSON::Stringify(deserialization_context_, - value.As()) - .ToLocalChecked())); - }); + Local input_value = + JSON::Parse(serialization_context_, StringFromUtf8(source)) + .ToLocalChecked(); + Local result = RoundTripTest(input_value); + ASSERT_TRUE(result->IsObject()); + EXPECT_EQ(source, Utf8Value(JSON::Stringify(deserialization_context_, + result.As()) + .ToLocalChecked())); } Maybe> DoEncode(Local value) { @@ -134,41 +125,33 @@ class ValueSerializerTest : public TestWithIsolate { return Just(std::move(result)); } - template - void EncodeTest(const InputFunctor& input_functor, - const EncodedDataFunctor& encoded_data_functor) { + std::vector EncodeTest(Local input_value) { Context::Scope scope(serialization_context()); TryCatch try_catch(isolate()); - Local input_value = input_functor(); std::vector buffer; - ASSERT_TRUE(DoEncode(input_value).To(&buffer)); - ASSERT_FALSE(try_catch.HasCaught()); - encoded_data_functor(buffer); + // Ideally we would use GTest's ASSERT_* macros here and below. However, + // those only work in functions returning {void}, and they only terminate + // the current function, but not the entire current test (so we would need + // additional manual checks whether it is okay to proceed). Given that our + // test driver starts a new process for each test anyway, it is acceptable + // to just use a CHECK (which would kill the process on failure) instead. + CHECK(DoEncode(input_value).To(&buffer)); + CHECK(!try_catch.HasCaught()); + return buffer; } - template - void InvalidEncodeTest(const InputFunctor& input_functor, - const MessageFunctor& functor) { + v8::Local InvalidEncodeTest(Local input_value) { Context::Scope scope(serialization_context()); TryCatch try_catch(isolate()); - Local input_value = input_functor(); - ASSERT_TRUE(DoEncode(input_value).IsNothing()); - functor(try_catch.Message()); + CHECK(DoEncode(input_value).IsNothing()); + return try_catch.Message(); } - template - void InvalidEncodeTest(const char* source, const MessageFunctor& functor) { - InvalidEncodeTest( - [this, source]() { return EvaluateScriptForInput(source); }, functor); + v8::Local InvalidEncodeTest(const char* source) { + return InvalidEncodeTest(EvaluateScriptForInput(source)); } - void InvalidEncodeTest(const char* source) { - InvalidEncodeTest(source, [](Local) {}); - } - - template - void DecodeTest(const std::vector& data, - const OutputFunctor& output_functor) { + Local DecodeTest(const std::vector& data) { Local context = deserialization_context(); Context::Scope scope(context); TryCatch try_catch(isolate()); @@ -178,22 +161,19 @@ class ValueSerializerTest : public TestWithIsolate { deserializer.SetSupportsLegacyWireFormat(true); deserializer.SetExpectInlineWasm(ExpectInlineWasm()); BeforeDecode(&deserializer); - ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false)); + CHECK(deserializer.ReadHeader(context).FromMaybe(false)); Local result; - ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result)); - ASSERT_FALSE(result.IsEmpty()); - ASSERT_FALSE(try_catch.HasCaught()); - ASSERT_TRUE( - context->Global() - ->CreateDataProperty(context, StringFromUtf8("result"), result) - .FromMaybe(false)); - output_functor(result); - ASSERT_FALSE(try_catch.HasCaught()); + CHECK(deserializer.ReadValue(context).ToLocal(&result)); + CHECK(!result.IsEmpty()); + CHECK(!try_catch.HasCaught()); + CHECK(context->Global() + ->CreateDataProperty(context, StringFromUtf8("result"), result) + .FromMaybe(false)); + CHECK(!try_catch.HasCaught()); + return result; } - template - void DecodeTestForVersion0(const std::vector& data, - const OutputFunctor& output_functor) { + Local DecodeTestForVersion0(const std::vector& data) { Local context = deserialization_context(); Context::Scope scope(context); TryCatch try_catch(isolate()); @@ -203,18 +183,17 @@ class ValueSerializerTest : public TestWithIsolate { deserializer.SetSupportsLegacyWireFormat(true); deserializer.SetExpectInlineWasm(ExpectInlineWasm()); BeforeDecode(&deserializer); - ASSERT_TRUE(deserializer.ReadHeader(context).FromMaybe(false)); - ASSERT_EQ(0u, deserializer.GetWireFormatVersion()); + CHECK(deserializer.ReadHeader(context).FromMaybe(false)); + CHECK_EQ(0u, deserializer.GetWireFormatVersion()); Local result; - ASSERT_TRUE(deserializer.ReadValue(context).ToLocal(&result)); - ASSERT_FALSE(result.IsEmpty()); - ASSERT_FALSE(try_catch.HasCaught()); - ASSERT_TRUE( - context->Global() - ->CreateDataProperty(context, StringFromUtf8("result"), result) - .FromMaybe(false)); - output_functor(result); - ASSERT_FALSE(try_catch.HasCaught()); + CHECK(deserializer.ReadValue(context).ToLocal(&result)); + CHECK(!result.IsEmpty()); + CHECK(!try_catch.HasCaught()); + CHECK(context->Global() + ->CreateDataProperty(context, StringFromUtf8("result"), result) + .FromMaybe(false)); + CHECK(!try_catch.HasCaught()); + return result; } void InvalidDecodeTest(const std::vector& data) { @@ -232,24 +211,26 @@ class ValueSerializerTest : public TestWithIsolate { EXPECT_TRUE(try_catch.HasCaught()); return; } - ASSERT_TRUE(header_result.ToChecked()); - ASSERT_TRUE(deserializer.ReadValue(context).IsEmpty()); + CHECK(header_result.ToChecked()); + CHECK(deserializer.ReadValue(context).IsEmpty()); EXPECT_TRUE(try_catch.HasCaught()); } Local EvaluateScriptForInput(const char* utf8_source) { + Context::Scope scope(serialization_context_); Local source = StringFromUtf8(utf8_source); Local