首页 > 解决方案 > 我发现 Chrome TextDecoder 错误了吗?

问题描述

测试: Linux 上的 Chrome 70.0.3538.110
错误:之前textDecoder.decode调用失败会导致后续调用失败。

const log = console.log
let string = 'Hello ♥ world! ♥'
let textEncoder = new TextEncoder()
let bytes = textEncoder.encode(string)
let textDecoder = new TextDecoder('utf-8', {fatal: true})
try {
  // Comment away this line and the code below will work
  log(textDecoder.decode(new DataView(bytes.buffer, 0, 19)))
} catch (e) {
  log('After this failed the next try will also fail')
}
log(textDecoder.decode(new DataView(bytes.buffer, 0, 20)))

标签: google-chrometextdecodedecoder

解决方案


推荐阅读