raw
current commit
261004.7 · deps: update V8 to 15.2.124.38

LookupIterator Architecture

This document explains the design and functionality of the LookupIterator in V8, which is the central mechanism for resolving property accesses on JavaScript objects.

Overview

The LookupIterator (src/objects/lookup.h) is a stateful iterator used to implement the ECMAScript specification’s property lookup rules. It abstracts away the differences between:

Whenever V8 needs to get, set, or delete a property and cannot do it via a fast Inline Cache (IC) hit, it falls back to the LookupIterator.

The State Machine

The iterator operates as a state machine. Calling Next() advances the iterator to the next state or the next object in the prototype chain. States include:

Configuration

The iterator can be configured via LookupIterator::Configuration, which consists of bit flags and convenience combinations:

Convenience combinations:

Deep Dive: The Lookup Process

The core logic of LookupIterator is implemented in src/objects/lookup.cc. Let’s examine the key phases:

1. Start()

When the iterator is created, it calls Start().

2. LookupInHolder()

This method checks the current holder (the object currently being inspected in the chain) for the property.

3. Next() and NextInternal()

If the property is not found in the current holder, Next() is called to move up the prototype chain.

4. Property Modification and Transitions

The LookupIterator is not just for reading; it also prepares for writes.

Elements vs. Properties

The LookupIterator handles both named properties and indexed elements by templating key methods with a bool is_element parameter.

ConcurrentLookupIterator

V8 also provides a ConcurrentLookupIterator (src/objects/lookup.h) for concurrent accesses from a background thread. Despite the name, it is currently an all-static class and not a stateful iterator. It implements safe lookups for specific cases like own data property lookup on fixed COW arrays, strings, and property cells in global objects, handling concurrency issues defensively.

File Structure