title: How promise chains reference the next error handler
body: <p>I am wondering if anyone knows how promise chains reference the next error handler - for example:</p>
  
  <pre><code>  const p = new Promise(resolve =&gt; resolve(5))
     .then(v =&gt; 5*v)
     .then(v =&gt; { throw 'foo' });
  
    p.then(v =&gt; v/4)
     .then(v =&gt; v+3)
     .catch(e =&gt; console.error('first catch:', e));
  
    p.then(v =&gt; v/4)
     .then(v =&gt; v+3)
     .catch(e =&gt; console.error('second catch:', e));
  </code></pre>
  
  <p>If you run that you will get:</p>
  
  <pre><code>first catch: foo
  second catch: foo
  </code></pre>
  
  <p>to my knowledge, every time <code>Promise.prototype.then</code> is a called, a new promise is created and returned. The only way I can think of for the promise to be able to find the <em>next error handler</em> for each chain, is to have an array of references to the children. So if a Promise is rejected, it would go through all the children and find the closest rejection handlers in each child chain.</p>
  
  <p>Does anyone know how this is implemented?</p>