<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Invoking callback should allow setting the `this` object"
   href="https://bugs.webkit.org/show_bug.cgi?id=167549">167549</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Invoking callback should allow setting the `this` object
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>WebKit Nightly Build
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>WebCore Misc.
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>joepeck&#64;webkit.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>cdumez&#64;apple.com, sam&#64;webkit.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Summary:
Invoking callback should allow setting the `this` object.

Cases like IntersectionObserver, PerformanceObserver and MutationObserver.

For example PerformanceObserver:

    &lt;script&gt;
    let observer = new PerformanceObserver(function f(list, obs) {
        console.log(&quot;this&quot;, this); // Expected `observer`, was `arguments.callee`
    })
    observer.observe({entryTypes: [&quot;mark&quot;]});
    performance.mark(&quot;mark1&quot;);
    &lt;/script&gt;

The callbacks and their interface are autogenerated from WebIDL and have a handleEvent method. Seems we need a way to the `this` object in some cases. (Probably not all, requestAnimationFrame for example prolly doesn't have the same constraints).

Currently this works with MutationObserver, which has a custom implementation of the callback (not generated). See JSMutationCallback.

    &lt;body&gt;
    &lt;div id=&quot;my-div&quot;&gt;&lt;/div&gt;
    &lt;script&gt;
    var target = document.getElementById(&quot;my-div&quot;);
    var observer = new MutationObserver(function(mutations) {
        console.log(&quot;this&quot;, this); // Expected `observer` but is `arguments.callee`
    });
    observer.observe(target, {childList: true});
    target.appendChild( document.createElement(&quot;span&quot;) );
    &lt;/script&gt;</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>