<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@lists.webkit.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>joepeck@webkit.org
</td>
</tr>
<tr>
<th>CC</th>
<td>cdumez@apple.com, sam@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:
<script>
let observer = new PerformanceObserver(function f(list, obs) {
console.log("this", this); // Expected `observer`, was `arguments.callee`
})
observer.observe({entryTypes: ["mark"]});
performance.mark("mark1");
</script>
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.
<body>
<div id="my-div"></div>
<script>
var target = document.getElementById("my-div");
var observer = new MutationObserver(function(mutations) {
console.log("this", this); // Expected `observer` but is `arguments.callee`
});
observer.observe(target, {childList: true});
target.appendChild( document.createElement("span") );
</script></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>