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

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

Issue 2264403004: Blink-compatible serialization of ArrayBuffer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: review comments Created 4 years, 4 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 7a8978ea8369a625784fefa94b3c5cf426b7dd37..ca0c09f9bfce9e54cab7065cc01592f43711cf3b 100644
--- a/test/unittests/value-serializer-unittest.cc
+++ b/test/unittests/value-serializer-unittest.cc
@@ -1517,5 +1517,58 @@ TEST_F(ValueSerializerTest, RoundTripSetWithTrickyGetters) {
});
}
+TEST_F(ValueSerializerTest, RoundTripArrayBuffer) {
+ RoundTripTest("new ArrayBuffer()", [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsArrayBuffer());
+ EXPECT_EQ(0u, ArrayBuffer::Cast(*value)->ByteLength());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "Object.getPrototypeOf(result) === ArrayBuffer.prototype"));
+ });
+ RoundTripTest("new Uint8Array([0, 128, 255]).buffer",
+ [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsArrayBuffer());
+ EXPECT_EQ(3u, ArrayBuffer::Cast(*value)->ByteLength());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "new Uint8Array(result).toString() === '0,128,255'"));
+ });
+ RoundTripTest(
+ "({ a: new ArrayBuffer(), get b() { return this.a; }})",
+ [this](Local<Value> value) {
+ EXPECT_TRUE(
+ EvaluateScriptForResultBool("result.a instanceof ArrayBuffer"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
+ });
+}
+
+TEST_F(ValueSerializerTest, DecodeArrayBuffer) {
+ DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x42, 0x00},
+ [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsArrayBuffer());
+ EXPECT_EQ(0u, ArrayBuffer::Cast(*value)->ByteLength());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "Object.getPrototypeOf(result) === ArrayBuffer.prototype"));
+ });
+ DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x42, 0x03, 0x00, 0x80, 0xff, 0x00},
+ [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsArrayBuffer());
+ EXPECT_EQ(3u, ArrayBuffer::Cast(*value)->ByteLength());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "new Uint8Array(result).toString() === '0,128,255'"));
+ });
+ DecodeTest(
+ {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01,
+ 0x61, 0x3f, 0x01, 0x42, 0x00, 0x3f, 0x02, 0x53, 0x01,
+ 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00},
+ [this](Local<Value> value) {
+ EXPECT_TRUE(
+ EvaluateScriptForResultBool("result.a instanceof ArrayBuffer"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
+ });
+}
+
+TEST_F(ValueSerializerTest, DecodeInvalidArrayBuffer) {
+ InvalidDecodeTest({0xff, 0x09, 0x42, 0xff, 0xff, 0x00});
+}
+
} // namespace
} // namespace v8
« 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