Curriculum
Module 43 // Core JavaScript
ECMAScript Internals
Module Objective
Execution contexts, realms, jobs, abstract operations
Mental Model Realtime Simulation
INTERACTIVE_CANVASEditor_Pane
Loading...
Console_Output
Waiting for output...
Practical Code Examples
// Example 1
// 1. Internal Slots
const obj = {};
// We can't access [[Prototype]] directly,
// but we use getPrototypeOf()
console.log(Object.getPrototypeOf(obj));💡 Internal slots are bracketed in the spec (like `[[Value]]`). They are hidden data fields within an object that only the engine can manipulate directly.
// Example 2
// 2. Abstract Operations
// When you run obj.prop, the engine triggers [[Get]]
const val = obj.prop;
// When you call a function, the engine triggers [[Call]]
myFunc();💡 The spec defines algorithms (Abstract Operations) for every action. For example, `[[Get]]` defines how the engine walks the prototype chain.
// Example 3
// 3. Different Realms (Iframes)
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
const IframeArray = iframe.contentWindow.Array;
console.log([] instanceof IframeArray); // false!💡 Realms are isolated execution environments with their own global objects and built-ins. An array from one realm is not an `instanceof` the constructor from another realm.
Engine & Memory Architecture
Inside the Specification
1. Internal Slots:
- Stored in a reserved area of the object's memory in the Heap.
- Not accessible via standard property iteration.
2. Agents & Jobs:
- An Agent is a thread plus the Event Loop.
- The engine uses Job Queues (like the Microtask queue) to manage pending operations defined by the spec.
3. Execution Context Stack:
- The spec defines exactly how contexts are pushed/popped on the RAM.
- It tracks the LexicalEnvironment and VariableEnvironment as physical pointers in the stack frame.