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

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

Issue 2262013002: Blink-compatible serialization of RegExp objects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@vs-value
Patch Set: Merge branch 'vs-value' into vs-regexp 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 96aba398a74a96b369c216ec317d519389d8bbb8..2db9776683ea0f53d96e42dc20fcc51ec235a533 100644
--- a/test/unittests/value-serializer-unittest.cc
+++ b/test/unittests/value-serializer-unittest.cc
@@ -1263,5 +1263,64 @@ TEST_F(ValueSerializerTest, DecodeValueObjects) {
});
}
+TEST_F(ValueSerializerTest, RoundTripRegExp) {
+ RoundTripTest("/foo/g", [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsRegExp());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "Object.getPrototypeOf(result) === RegExp.prototype"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.toString() === '/foo/g'"));
+ });
+ RoundTripTest("new RegExp('Qu\\xe9bec', 'i')", [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsRegExp());
+ EXPECT_TRUE(
+ EvaluateScriptForResultBool("result.toString() === '/Qu\\xe9bec/i'"));
+ });
+ RoundTripTest("new RegExp('\\ud83d\\udc4a', 'ug')",
+ [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsRegExp());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "result.toString() === '/\\ud83d\\udc4a/gu'"));
+ });
+ RoundTripTest(
+ "({ a: /foo/gi, get b() { return this.a; }})",
+ [this](Local<Value> value) {
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof RegExp"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
+ });
+}
+
+TEST_F(ValueSerializerTest, DecodeRegExp) {
+ DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x01},
+ [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsRegExp());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "Object.getPrototypeOf(result) === RegExp.prototype"));
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "result.toString() === '/foo/g'"));
+ });
+ DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x52, 0x07, 0x51, 0x75, 0xc3, 0xa9, 0x62,
+ 0x65, 0x63, 0x02},
+ [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsRegExp());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "result.toString() === '/Qu\\xe9bec/i'"));
+ });
+ DecodeTest(
+ {0xff, 0x09, 0x3f, 0x00, 0x52, 0x04, 0xf0, 0x9f, 0x91, 0x8a, 0x11, 0x00},
+ [this](Local<Value> value) {
+ ASSERT_TRUE(value->IsRegExp());
+ EXPECT_TRUE(EvaluateScriptForResultBool(
+ "result.toString() === '/\\ud83d\\udc4a/gu'"));
+ });
+ DecodeTest(
+ {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61,
+ 0x3f, 0x01, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x03, 0x3f, 0x02,
+ 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00},
+ [this](Local<Value> value) {
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof RegExp"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
+ });
+}
+
} // 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