this Question About ECMAScript Specification(ECMA-262 8th edition)
These Days, I'm little confused about Job and Job Queue.
Here is Some Questions.
1: In ECMA-262, There is two kinds of Job Queue. one is ScriptJobs
the other is PromiseJobs
. So, Witch one have preference?
2: In ECMA-262, There is only definition of RunJobs
abstract operation. I want to know when and where the RunJobs
execute?
3.I executed code blow, In FF 60.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
window.addEventListener('DOMContentLoaded', () => {
let x = document.createElement('script');
x.innerHTML = 'console.log(3);';
console.log('script start');
document.body.appendChild(x);
setTimeout(() => console.log(1), 0);
Promise.resolve(2).then(console.log);
console.log('script is end');
});
</script>
</head>
<body>
</body>
</html>
and it logs :
script start
3
script end
2
1
Why script
element execute on excution context that created dynamically?
c. Let nextQueue be a non‐empty Job Queue chosen in an implementation‐defined manner. If all Job Queues are empty, the result is implementation‐defined.
forked from ECMA-262 RunJobs. How HTML spec define implementation‐defined manner?
@Bergi like this? PromiseJobs : [] , ScriptJobs : []
ScriptJobs.push(something);
// pop and run by Event loop
// blow will happens while `something` runs
PromiseJobs.push(anotherOne);
ScriptJobs.push(theother);
//end of `something`
//and in here, PromiseJobs will pop?