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

166
Visualizações
Can't redirect target of freeze operation via preventExtensions trap

Code:

(function () {
    "use strict";

    var proxy;
    var realTarget;
    var target;

    realTarget = {};
    target = {};

    proxy = new Proxy(target, {
        isExtensible: function (target) {
            return Reflect.isExtensible(realTarget);
        },
        preventExtensions: function (target) {
            return Reflect.preventExtensions(realTarget);
        }
    });

    Object.freeze(proxy);
})();

Resulting error message:

[error] Line 20: Uncaught TypeError: 'preventExtensions' on proxy: trap returned truish but the proxy target is extensible

Why is this an error? What's the point of a proxy if I can't redirect this operation?

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

0

Proxy traps have a set of so-called invariants they have to conform to.

One of these is that the preventExtensions trap may only return true if [[IsExtensible]] of the proxy's target returns false (i.e. if the target is really made inextensible).

You can work around this by returning false (signaling that making the object inextensible has failed):

preventExtensions: function (target) {
    Reflect.preventExtensions(realTarget);
    return false
}
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