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

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

Issue 2870743004: [value-serializer] Ensure deserialized JSRegExp flags are valid (Closed)
Patch Set: Add a unit test Created 3 years, 7 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 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 // RegExp containing a Latin-1 string. 1596 // RegExp containing a Latin-1 string.
1597 DecodeTest( 1597 DecodeTest(
1598 {0xff, 0x0c, 0x52, 0x22, 0x06, 'Q', 'u', 0xe9, 'b', 'e', 'c', 0x02}, 1598 {0xff, 0x0c, 0x52, 0x22, 0x06, 'Q', 'u', 0xe9, 'b', 'e', 'c', 0x02},
1599 [this](Local<Value> value) { 1599 [this](Local<Value> value) {
1600 ASSERT_TRUE(value->IsRegExp()); 1600 ASSERT_TRUE(value->IsRegExp());
1601 EXPECT_TRUE(EvaluateScriptForResultBool( 1601 EXPECT_TRUE(EvaluateScriptForResultBool(
1602 "result.toString() === '/Qu\\xe9bec/i'")); 1602 "result.toString() === '/Qu\\xe9bec/i'"));
1603 }); 1603 });
1604 } 1604 }
1605 1605
1606 // Tests that invalid flags are not accepted by the deserializer. In particular,
1607 // the dotAll flag ('s') is only valid when the corresponding flag is enabled.
1608 TEST_F(ValueSerializerTest, DecodeRegExpDotAll) {
1609 i::FLAG_harmony_regexp_dotall = false;
1610 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x1f},
1611 [this](Local<Value> value) {
1612 ASSERT_TRUE(value->IsRegExp());
1613 EXPECT_TRUE(EvaluateScriptForResultBool(
1614 "Object.getPrototypeOf(result) === RegExp.prototype"));
1615 EXPECT_TRUE(EvaluateScriptForResultBool(
1616 "result.toString() === '/foo/gimuy'"));
1617 });
1618 InvalidDecodeTest(
1619 {0xff, 0x09, 0x3f, 0x00, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x3f});
1620 InvalidDecodeTest(
1621 {0xff, 0x09, 0x3f, 0x00, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x7f});
1622
1623 i::FLAG_harmony_regexp_dotall = true;
1624 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x1f},
1625 [this](Local<Value> value) {
1626 ASSERT_TRUE(value->IsRegExp());
1627 EXPECT_TRUE(EvaluateScriptForResultBool(
1628 "Object.getPrototypeOf(result) === RegExp.prototype"));
1629 EXPECT_TRUE(EvaluateScriptForResultBool(
1630 "result.toString() === '/foo/gimuy'"));
1631 });
1632 DecodeTest({0xff, 0x09, 0x3f, 0x00, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x3f},
1633 [this](Local<Value> value) {
1634 ASSERT_TRUE(value->IsRegExp());
1635 EXPECT_TRUE(EvaluateScriptForResultBool(
1636 "Object.getPrototypeOf(result) === RegExp.prototype"));
1637 EXPECT_TRUE(EvaluateScriptForResultBool(
1638 "result.toString() === '/foo/gimsuy'"));
1639 });
1640 InvalidDecodeTest(
1641 {0xff, 0x09, 0x3f, 0x00, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x7f});
1642 }
1643
1606 TEST_F(ValueSerializerTest, RoundTripMap) { 1644 TEST_F(ValueSerializerTest, RoundTripMap) {
1607 RoundTripTest( 1645 RoundTripTest(
1608 "(() => { var m = new Map(); m.set(42, 'foo'); return m; })()", 1646 "(() => { var m = new Map(); m.set(42, 'foo'); return m; })()",
1609 [this](Local<Value> value) { 1647 [this](Local<Value> value) {
1610 ASSERT_TRUE(value->IsMap()); 1648 ASSERT_TRUE(value->IsMap());
1611 EXPECT_TRUE(EvaluateScriptForResultBool( 1649 EXPECT_TRUE(EvaluateScriptForResultBool(
1612 "Object.getPrototypeOf(result) === Map.prototype")); 1650 "Object.getPrototypeOf(result) === Map.prototype"));
1613 EXPECT_TRUE(EvaluateScriptForResultBool("result.size === 1")); 1651 EXPECT_TRUE(EvaluateScriptForResultBool("result.size === 1"));
1614 EXPECT_TRUE(EvaluateScriptForResultBool("result.get(42) === 'foo'")); 1652 EXPECT_TRUE(EvaluateScriptForResultBool("result.get(42) === 'foo'"));
1615 }); 1653 });
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after
3002 InvalidDecodeTest(raw); 3040 InvalidDecodeTest(raw);
3003 } 3041 }
3004 3042
3005 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { 3043 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) {
3006 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); 3044 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00});
3007 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); 3045 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f});
3008 } 3046 }
3009 3047
3010 } // namespace 3048 } // namespace
3011 } // namespace v8 3049 } // 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