code: function utf8CheckExtraBytes(self, buf, p) {
    if ((buf[0] & 0xC0) !== 0x80) {
      self.lastNeed = 0;
      return '\ufffd'.repeat(p);
    }
    if (self.lastNeed > 1 && buf.length > 1) {
      if ((buf[1] & 0xC0) !== 0x80) {
        self.lastNeed = 1;
        return '\ufffd'.repeat(p + 1);
      }
      if (self.lastNeed > 2 && buf.length > 2) {
        if ((buf[2] & 0xC0) !== 0x80) {
          self.lastNeed = 2;
          return '\ufffd'.repeat(p + 2);
        }
      }
    }
  }
docs: Validates as many continuation bytes for a multi-byte UTF-8 character as needed or are available. If we see a non-continuation byte where we expect one, we "replace" the validated continuation bytes we've seen so far with UTF-8 replacement characters ('\ufffd'), to match v8's UTF-8 decoding behavior. The continuation byte check is included three times in the case where all of the continuation bytes for a character exist in the same buffer. It is also done this way as a slight performance increase instead of using a loop.