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

219
Visualizações
Execute js from string and get line number which failed

I am executing js which is stored as a string inside the db via:

let myScript = ` await Some()
lines()
of()
js()`

let result
try{
   result = await Object.getPrototypeOf(async function() {}).constructor(`return (async () => { ${myScript} })()`)()
} catch(e){
   result = 'Error occurred: '+e.message + ' stack: ' + e.stack
}

The problem is: The line numbers of e.stack are not correct. I think it's somehow also counting line numbers of the contextual code. For some js strings, I don't even get a stack.

Anyone knows what the problem is?

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

0

You need to add try-catch block in your string JS, I hope the answer to this Question will help you.

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