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

Unified Diff: test/unittests/value-serializer-unittest.cc

Issue 2386233002: ValueSerializer: Expose reading/writing doubles to embedder. (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/value-serializer-unittest.cc
diff --git a/test/unittests/value-serializer-unittest.cc b/test/unittests/value-serializer-unittest.cc
index d01eba7382888dc0ba031155340dc0966a5acfc5..d88d60a3e6a6c1a217d1c1476c51e91d6ec7073c 100644
--- a/test/unittests/value-serializer-unittest.cc
+++ b/test/unittests/value-serializer-unittest.cc
@@ -2264,6 +2264,44 @@ TEST_F(ValueSerializerTestWithHostObject, RoundTripUint64) {
});
}
+TEST_F(ValueSerializerTestWithHostObject, RoundTripDouble) {
+ // The host can serialize data as double.
+ EXPECT_CALL(serializer_delegate_, WriteHostObject(isolate(), _))
+ .WillRepeatedly(Invoke([this](Isolate*, Local<Object> object) {
+ double value = 0;
+ EXPECT_TRUE(object->GetInternalField(0)
+ ->NumberValue(serialization_context())
+ .To(&value));
+ WriteExampleHostObjectTag();
+ serializer_->WriteDouble(value);
+ return Just(true);
+ }));
+ EXPECT_CALL(deserializer_delegate_, ReadHostObject(isolate()))
+ .WillRepeatedly(Invoke([this](Isolate*) {
+ EXPECT_TRUE(ReadExampleHostObjectTag());
+ double value = 0;
+ EXPECT_TRUE(deserializer_->ReadDouble(&value));
+ Local<Value> argv[] = {Number::New(isolate(), value)};
+ return NewHostObject(deserialization_context(), arraysize(argv), argv);
+ }));
+ RoundTripTest("new ExampleHostObject(-3.5)", [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsObject());
+ ASSERT_TRUE(Object::Cast(*value)->InternalFieldCount());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "Object.getPrototypeOf(result) === ExampleHostObject.prototype"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.value === -3.5"));
+ });
+ RoundTripTest("new ExampleHostObject(NaN)", [this](Local<Value> value) {
+ EXPECT_TRUE(EvaluateScriptForResultBool("Number.isNaN(result.value)"));
+ });
+ RoundTripTest("new ExampleHostObject(Infinity)", [this](Local<Value> value) {
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.value === Infinity"));
+ });
+ RoundTripTest("new ExampleHostObject(-0)", [this](Local<Value> value) {
+ EXPECT_TRUE(EvaluateScriptForResultBool("1/result.value === -Infinity"));
+ });
+}
+
TEST_F(ValueSerializerTestWithHostObject, RoundTripRawBytes) {
// The host can serialize arbitrary raw bytes.
const struct {
« 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