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

147
Visualizações
Difference between calling eval with and without promise

I have a question. I saw in spec operation HostMakeJobCallback, it describes two cases with non-null and null active script. Also there are two examples with code:

  • active script is non-null
    Promise.resolve('import(`./example.mjs`)').then(eval);
    
  • active script is null
    <button onclick="Promise.resolve('import(`./example.mjs`)').then(eval)">Click me</button>
    

I am interested in first one example. Imagine the following structure:

  • index.html
  • modules/
    • a.js
    • example.js

index.html

<script type="module" src="modules/a.js"></script>

example.js

console.log("example.js is included")

a.js (don't run with all cases together)

/// case 1
eval('import(`./example.js`)'); 

/// case 2
Promise.resolve("import('./example.js')").then(eval)

In case 1: eval won't throw an error and it will print "example.js is included". That I think will be correct because import gets GetActiveScriptOrModule() that will be Module Record

In case 2: then(eval) will throw the error. And for some reason this code will think that baseURL is "http://127.0.0.1:5501/" but not the "http://127.0.0.1:5501/modules"

Why these cases are different? Doesn't HostMakeJobCallback save active script for the future restoration with his baseURL from module script?

eval('import("./example.js")'); enter image description here

Promise.resolve("import('./example.js')").then(eval) enter image description here

about 4 years ago · Santiago Trujillo
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