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

146
Vistas
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 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