Bug 167549
Summary: | Invoking generated callback should allow setting the `this` object | ||
---|---|---|---|
Product: | WebKit | Reporter: | Joseph Pecoraro <joepeck> |
Component: | WebCore Misc. | Assignee: | Nobody <webkit-unassigned> |
Status: | NEW | ||
Severity: | Normal | CC: | ahmad.saleem792, ap, bfulgham, cdumez, joepeck, rniwa, sam |
Priority: | P2 | ||
Version: | WebKit Nightly Build | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Joseph Pecoraro
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>
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Ahmad Saleem
JSFiddle - https://jsfiddle.net/79xqnct6/
*** Chrome Canary 107 ***
"this", [object PerformanceObserver] {
disconnect: function disconnect() { [native code] },
observe: function observe() { [native code] },
takeRecords: function takeRecords() { [native code] }
}
*** Firefox Nightly 106 ***
"this", [object PerformanceObserver] {
disconnect: function disconnect() {
[native code]
},
observe: function observe() {
[native code]
},
takeRecords: function takeRecords() {
[native code]
}
}
*** Safari Technology Preview 152 ***
"this", [object PerformanceObserver] {
disconnect: function disconnect() {
[native code]
},
observe: function observe() {
[native code]
},
takeRecords: function takeRecords() {
[native code]
}
}
_________________
Is anything needed here? Thanks!