Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda