Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!