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

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

Issue 2665653004: ValueSerializer: Share string encoding code with String and RegExp objects. (Closed)
Patch Set: Created 3 years, 10 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 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 EXPECT_TRUE(EvaluateScriptForResultBool("result.length === 2")); 1494 EXPECT_TRUE(EvaluateScriptForResultBool("result.length === 2"));
1495 }); 1495 });
1496 DecodeTest( 1496 DecodeTest(
1497 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 1497 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01,
1498 0x61, 0x3f, 0x01, 0x73, 0x00, 0x3f, 0x02, 0x53, 0x01, 1498 0x61, 0x3f, 0x01, 0x73, 0x00, 0x3f, 0x02, 0x53, 0x01,
1499 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00}, 1499 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00},
1500 [this](Local<Value> value) { 1500 [this](Local<Value> value) {
1501 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof String")); 1501 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof String"));
1502 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1502 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1503 }); 1503 });
1504
1505 // String object containing a Latin-1 string.
1506 DecodeTest({0xff, 0x0c, 0x73, 0x22, 0x06, 'Q', 'u', 0xe9, 'b', 'e', 'c'},
1507 [this](Local<Value> value) {
1508 EXPECT_TRUE(EvaluateScriptForResultBool(
1509 "Object.getPrototypeOf(result) === String.prototype"));
1510 EXPECT_TRUE(EvaluateScriptForResultBool(
1511 "result.valueOf() === 'Qu\\xe9bec'"));
1512 EXPECT_TRUE(EvaluateScriptForResultBool("result.length === 6"));
1513 });
1504 } 1514 }
1505 1515
1506 TEST_F(ValueSerializerTest, RoundTripRegExp) { 1516 TEST_F(ValueSerializerTest, RoundTripRegExp) {
1507 RoundTripTest("/foo/g", [this](Local<Value> value) { 1517 RoundTripTest("/foo/g", [this](Local<Value> value) {
1508 ASSERT_TRUE(value->IsRegExp()); 1518 ASSERT_TRUE(value->IsRegExp());
1509 EXPECT_TRUE(EvaluateScriptForResultBool( 1519 EXPECT_TRUE(EvaluateScriptForResultBool(
1510 "Object.getPrototypeOf(result) === RegExp.prototype")); 1520 "Object.getPrototypeOf(result) === RegExp.prototype"));
1511 EXPECT_TRUE(EvaluateScriptForResultBool("result.toString() === '/foo/g'")); 1521 EXPECT_TRUE(EvaluateScriptForResultBool("result.toString() === '/foo/g'"));
1512 }); 1522 });
1513 RoundTripTest("new RegExp('Qu\\xe9bec', 'i')", [this](Local<Value> value) { 1523 RoundTripTest("new RegExp('Qu\\xe9bec', 'i')", [this](Local<Value> value) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 "result.toString() === '/\\ud83d\\udc4a/gu'")); 1563 "result.toString() === '/\\ud83d\\udc4a/gu'"));
1554 }); 1564 });
1555 DecodeTest( 1565 DecodeTest(
1556 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61, 1566 {0xff, 0x09, 0x3f, 0x00, 0x6f, 0x3f, 0x01, 0x53, 0x01, 0x61,
1557 0x3f, 0x01, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x03, 0x3f, 0x02, 1567 0x3f, 0x01, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x03, 0x3f, 0x02,
1558 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00}, 1568 0x53, 0x01, 0x62, 0x3f, 0x02, 0x5e, 0x01, 0x7b, 0x02, 0x00},
1559 [this](Local<Value> value) { 1569 [this](Local<Value> value) {
1560 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof RegExp")); 1570 EXPECT_TRUE(EvaluateScriptForResultBool("result.a instanceof RegExp"));
1561 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b")); 1571 EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
1562 }); 1572 });
1573
1574 // RegExp containing a Latin-1 string.
1575 DecodeTest(
1576 {0xff, 0x0c, 0x52, 0x22, 0x06, 'Q', 'u', 0xe9, 'b', 'e', 'c', 0x02},
1577 [this](Local<Value> value) {
1578 ASSERT_TRUE(value->IsRegExp());
1579 EXPECT_TRUE(EvaluateScriptForResultBool(
1580 "result.toString() === '/Qu\\xe9bec/i'"));
1581 });
1563 } 1582 }
1564 1583
1565 TEST_F(ValueSerializerTest, RoundTripMap) { 1584 TEST_F(ValueSerializerTest, RoundTripMap) {
1566 RoundTripTest( 1585 RoundTripTest(
1567 "(() => { var m = new Map(); m.set(42, 'foo'); return m; })()", 1586 "(() => { var m = new Map(); m.set(42, 'foo'); return m; })()",
1568 [this](Local<Value> value) { 1587 [this](Local<Value> value) {
1569 ASSERT_TRUE(value->IsMap()); 1588 ASSERT_TRUE(value->IsMap());
1570 EXPECT_TRUE(EvaluateScriptForResultBool( 1589 EXPECT_TRUE(EvaluateScriptForResultBool(
1571 "Object.getPrototypeOf(result) === Map.prototype")); 1590 "Object.getPrototypeOf(result) === Map.prototype"));
1572 EXPECT_TRUE(EvaluateScriptForResultBool("result.size === 1")); 1591 EXPECT_TRUE(EvaluateScriptForResultBool("result.size === 1"));
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 InvalidDecodeTest(raw); 2683 InvalidDecodeTest(raw);
2665 } 2684 }
2666 2685
2667 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { 2686 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) {
2668 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); 2687 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00});
2669 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); 2688 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f});
2670 } 2689 }
2671 2690
2672 } // namespace 2691 } // namespace
2673 } // namespace v8 2692 } // 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