@@ -1551,7 +1551,7 @@ TEST_P(JSITest, UTF8ExceptionTest) {
1551
1551
}
1552
1552
1553
1553
/* [Windows #14185
1554
- TEST_P(JSITest, UTF16Test ) {
1554
+ TEST_P(JSITest, UTF16ConversionTest ) {
1555
1555
// This Runtime Decorator is used to test the conversion from UTF-8 to UTF-16
1556
1556
// in the default utf16 method for runtimes that do not provide their own
1557
1557
// utf16 implementation.
@@ -1614,6 +1614,50 @@ TEST_P(JSITest, UTF16Test) {
1614
1614
rd.utf8Str = "\xea\x7a";
1615
1615
EXPECT_EQ(str.utf16(rd), u"\uFFFD\u007A");
1616
1616
}
1617
+
1618
+ TEST_P(JSITest, CreateFromUtf16Test) {
1619
+ // This Runtime Decorator is used to test the default createStringFromUtf16
1620
+ // and createPropNameIDFromUtf16 implementation for VMs that do not provide
1621
+ // their own implementation
1622
+ class RD : public RuntimeDecorator<Runtime, Runtime> {
1623
+ public:
1624
+ RD(Runtime& rt) : RuntimeDecorator(rt) {}
1625
+
1626
+ String createStringFromUtf16(const char16_t* utf16, size_t length)
1627
+ override {
1628
+ return Runtime::createStringFromUtf16(utf16, length);
1629
+ }
1630
+
1631
+ PropNameID createPropNameIDFromUtf16(const char16_t* utf16, size_t length)
1632
+ override {
1633
+ return Runtime::createPropNameIDFromUtf16(utf16, length);
1634
+ }
1635
+ };
1636
+
1637
+ RD rd = RD(rt);
1638
+ std::u16string utf16 = u"foobar";
1639
+
1640
+ auto jsString = String::createFromUtf16(rd, utf16);
1641
+ EXPECT_EQ(jsString.utf16(rd), utf16);
1642
+ auto prop = PropNameID::forUtf16(rd, utf16);
1643
+ EXPECT_EQ(prop.utf16(rd), utf16);
1644
+
1645
+ // 👋 in UTF-16 encoding is 0xd83d 0xdc4b
1646
+ utf16 = u"hello!\xd83d\xdc4b";
1647
+ jsString = String::createFromUtf16(rd, utf16.data(), utf16.length());
1648
+ EXPECT_EQ(jsString.utf16(rd), utf16);
1649
+ prop = PropNameID::forUtf16(rd, utf16);
1650
+ EXPECT_EQ(prop.utf16(rd), utf16);
1651
+
1652
+ utf16 = u"\xd83d";
1653
+ jsString = String::createFromUtf16(rd, utf16.data(), utf16.length());
1654
+ /// We need to use charCodeAt instead of UTF16 because the default
1655
+ /// implementation of UTF16 converts to UTF8, then to UTF16, so we will lose
1656
+ /// the lone surrogate value.
1657
+ rd.global().setProperty(rd, "loneSurrogate", jsString);
1658
+ auto cp = eval("loneSurrogate.charCodeAt(0)").getNumber();
1659
+ EXPECT_EQ(cp, 55357); // 0xD83D in decimal
1660
+ }
1617
1661
Windows] */
1618
1662
1619
1663
/*
0 commit comments