JS RuntimeBaseline · Widely

Prototype Chain Lookup and Delegation

Mental Model

When an object lacks an own property, JavaScript walks its internal [[Prototype]] pointer chain until it finds the key or hits null. Methods keep this bound to the original receiver inside the new Execution Context, while V8 Inline Caches memorize stable chains.

Interactive Simulator

[[Prototype]] Chain Lookup & IC Fast-Path

Trace how V8 resolves obj.method() across own properties, prototype hops, and null termination.

widget (own)
Widget.prototype
Object.prototype
Step 1 / 3: 1. Own Property Check

Engine inspects instance Hidden Class for key 'render'. Not found on own descriptor table.

widget.render();
Internal State / Memory
target
widget
ownKeys
[ "id", "label" ]
found
false

Under the Hood

When [[Get]] misses on an object's own property map, V8 walks its internal [[Prototype]] pointer chain until it finds a matching descriptor or reaches null. V8 Hidden Classes guard hot prototype lookups with validity cells, so mutating any ancestor prototype invalidates every downstream Inline Cache.

  1. Own Descriptor Check: [[Get]] inspects the receiver's own property map first.
  2. Chain Traversal: On a miss, the engine reads [[GetPrototypeOf]]() and repeats the lookup up to Object.prototype.
  3. Prototype Validity Cells: V8 Hidden Classes guard cached prototype lookups with validity cells; mutating any ancestor prototype invalidates every downstream IC.
  4. Shadowing Trap: Assigning obj.x = 1 creates an own property on obj rather than mutating a prototype data property.
JS
const proto = { role: 'viewer' };
const user = Object.create(proto);
const dict = Object.create(null); // No Object.prototype

console.log(user.role);     // 'viewer' (1 hop)
console.log(dict.toString); // undefined (safe from pollution)

Problem Genealogy

  • 1995 (__proto__ & Constructor .prototype): Delegation bolted onto Java-like new syntax without a standard Object.create.
  • 2015 (ES6 class & Reflect.getPrototypeOf): Standardized syntax over the same [[Prototype]] delegation model.
  • 2022 (Object.hasOwn): Replaced the error-prone Object.prototype.hasOwnProperty.call(obj, key) boilerplate.

Production Pitfalls

Production Pitfall
  • Runtime Object.setPrototypeOf: Swapping prototypes on live objects destroys V8's prototype validity cells and forces slow dictionary lookups.
  • Prototype Pollution: Deep-merging untrusted JSON containing "__proto__" keys mutates Object.prototype across the entire realm.
When Not to Use
  • When not to use plain {} as a map: Never index arbitrary user keys (like "constructor" or "toString") on {}; use Map or Object.create(null).

Connections & Logical Next Steps

Seen in Architecture Autopsies