Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

316
Visualizações
JavaScript: TextDecoder on SharedArrayBuffer

I am facing a problem with decode() on SharedArrayBuffer.

Code:

  var sharedArrayBuffer = new SharedArrayBuffer(2);
  var uint8Array = new Uint8Array(sharedArrayBuffer);
  uint8Array[0] = 20;
  var decoder = new TextDecoder();
  decoder.decode(uint8Array);

Error:

Failed to execute 'decode' on 'TextDecoder': The provided ArrayBufferView value must not be shared.

There is a specification here that warns developers about race-condition on this type of memory. Can I somehow force decoding? I am sure data will not be changed during decoding. Or is there a workaround for this?

Reasons: I want to create a single copy of Uint8Array and pass it without copying via postmessage (which copies by default if transferrable is not specified) to several(>3) IFrames(with sandbox tag). Maybe there are other possible solutions?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Looks like using ArrayBuffer works fine.

  var arrayBuffer = new ArrayBuffer(2);
  var uint8Array = new Uint8Array(arrayBuffer);
  uint8Array[0] = 20;
  var decoder = new TextDecoder();
  decoder.decode(uint8Array);
about 4 years ago · Juan Pablo Isaza Relatório

0

Js

var sharedArrayBuffer = new SharedArrayBuffer(32);
var ary = new Int32Array(sharedArrayBuffer);
ary[0] = 20;
var encoder = new TextEncoder();
var EncodedArray = encoder.encode(ary);
console.log("Encoded Array : ", EncodedArray)
var decoder = new TextDecoder();
var DecodedArray = decoder.decode(EncodedArray);
console.log("Decoded Array is : ", DecodedArray)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda