ECMAScript® 2024 Language Specification

Draft ECMA-262 / February 15, 2024

29.6 Relations of Candidate Executions

29.6.1 agent-order

For a candidate execution execution, execution.[[AgentOrder]] is a Relation on events that satisfies the following.

  • For each pair (E, D) in EventSet(execution), execution.[[AgentOrder]] contains (E, D) if there is some Agent Events Record aer in execution.[[EventsRecords]] such that E and D are in aer.[[EventList]] and E is before D in List order of aer.[[EventList]].
Note

Each agent introduces events in a per-agent strict total order during the evaluation. This is the union of those strict total orders.

29.6.2 reads-bytes-from

For a candidate execution execution, execution.[[ReadsBytesFrom]] is a mathematical function mapping events in SharedDataBlockEventSet(execution) to Lists of events in SharedDataBlockEventSet(execution) that satisfies the following conditions.

29.6.3 reads-from

For a candidate execution execution, execution.[[ReadsFrom]] is the least Relation on events that satisfies the following.

  • For each pair (R, W) in SharedDataBlockEventSet(execution), execution.[[ReadsFrom]] contains (R, W) if execution.[[ReadsBytesFrom]](R) contains W.

29.6.4 host-synchronizes-with

For a candidate execution execution, execution.[[HostSynchronizesWith]] is a host-provided strict partial order on host-specific events that satisfies at least the following.

  • If execution.[[HostSynchronizesWith]] contains (E, D), E and D are in HostEventSet(execution).
  • There is no cycle in the union of execution.[[HostSynchronizesWith]] and execution.[[AgentOrder]].
Note 1

For two host-specific events E and D, E host-synchronizes-with D implies E happens-before D.

Note 2

The host-synchronizes-with relation allows the host to provide additional synchronization mechanisms, such as postMessage between HTML workers.

29.6.5 synchronizes-with

For a candidate execution execution, execution.[[SynchronizesWith]] is the least Relation on events that satisfies the following.

  • For each pair (R, W) in execution.[[ReadsFrom]], execution.[[SynchronizesWith]] contains (W, R) if R.[[Order]] is seq-cst, W.[[Order]] is seq-cst, and R and W have equal ranges.
  • For each element eventsRecord of execution.[[EventsRecords]], the following is true.
    • For each pair (S, Sw) in eventsRecord.[[AgentSynchronizesWith]], execution.[[SynchronizesWith]] contains (S, Sw).
  • For each pair (E, D) in execution.[[HostSynchronizesWith]], execution.[[SynchronizesWith]] contains (E, D).
Note 1

Owing to convention, write events synchronizes-with read events, instead of read events synchronizes-with write events.

Note 2

init events do not participate in synchronizes-with, and are instead constrained directly by happens-before.

Note 3

Not all seq-cst events related by reads-from are related by synchronizes-with. Only events that also have equal ranges are related by synchronizes-with.

Note 4

For Shared Data Block events R and W such that W synchronizes-with R, R may reads-from other writes than W.

29.6.6 happens-before

For a candidate execution execution, execution.[[HappensBefore]] is the least Relation on events that satisfies the following.

  • For each pair (E, D) in execution.[[AgentOrder]], execution.[[HappensBefore]] contains (E, D).
  • For each pair (E, D) in execution.[[SynchronizesWith]], execution.[[HappensBefore]] contains (E, D).
  • For each pair (E, D) in SharedDataBlockEventSet(execution), execution.[[HappensBefore]] contains (E, D) if E.[[Order]] is init and E and D have overlapping ranges.
  • For each pair (E, D) in EventSet(execution), execution.[[HappensBefore]] contains (E, D) if there is an event F such that the pairs (E, F) and (F, D) are in execution.[[HappensBefore]].
Note

Because happens-before is a superset of agent-order, candidate executions are consistent with the single-thread evaluation semantics of ECMAScript.