Consider merging https://chromium.googlesource.com/chromium/blink/+/109e9896a406aa3e76350a733bd030e8eeacc4c4 The Encoding standard says that unpaired UTF-16 surrogates in JS strings should be converted into U+FFFD (replacement character) during encode operations. This is (optionally) done already in WTFString::utf8() but not handled in TextCodecUTF8.
I didn't find good test from Chromium patch but this is the place where this patch needs to be applied: Link - https://github.com/WebKit/WebKit/blob/4ddaf4f8c28e7795d0dae5f39fad1873a566067e/Source/WebCore/PAL/pal/text/TextCodecUTF8.cpp#L466 I don't if this is still needed or not. Appreciate if someone else can comment. Thanks!
WebKit passes all tests that were added with this Chromium commit.