-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LoAF: support approximate source locations for promise resolvers
Attribute the source location of a promise resolver that contributed to LoAF to the script that created it, e.g. the script that called fetch(). Getting the exact source location of the promise resolver itself would require capturing a stack trace, which might be too much overhead, so this is the next best thing. We can revise in the future whether a shallow stack trace is something we're OK with in some circumstances. Note that it's impossible to get the location of the actual then(), as that's a microtask that's batched together with all the rest of the microtasks (e.g. other then()s of the same promise). The animation frame monitor maintains a weak map between the promise resolver and the source location of the event listener/script-block/callback that was responsible for creating it. This source location is then used when a promise is resolved and the resolution task is a long script that contributes to the LoAF. Bug: 1392685 Change-Id: I268ebbbf035b0800a5d1bd61cd939e46533fe064 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4783320 Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Commit-Queue: Noam Rosenthal <nrosenthal@chromium.org> Cr-Commit-Position: refs/heads/main@{#1186486}
- Loading branch information
Showing
9 changed files
with
115 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ts/external/wpt/long-animation-frame/tentative/loaf-source-location-promise-resolver.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE HTML> | ||
<meta charset=utf-8> | ||
<title>Long Animation Frame Timing: source location extraction for promise resolvers</title> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/utils.js"></script> | ||
|
||
<body> | ||
<h1>Long Animation Frame: source location extraction for promise resolvers</h1> | ||
<div id="log"></div> | ||
<script> | ||
|
||
function create_promise_resolver_with_loaf() { | ||
fetch("/common/dummy.xml").then(() => { | ||
busy_wait(very_long_frame_duration); | ||
}) | ||
} | ||
|
||
promise_test(async t => { | ||
const [entry, script] = await expect_long_frame_with_script(() => { | ||
setTimeout(create_promise_resolver_with_loaf); | ||
}, script => script.name === "Window.fetch.then", t); | ||
assert_true(script.sourceLocation?.startsWith("create_promise_resolver_with_loaf")); | ||
}, "promise-resolver source location is attributed to callback who created the resolver"); | ||
|
||
promise_test(async t => { | ||
const [entry, script] = await expect_long_frame_with_script(() => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "/common/dummy.xml"); | ||
xhr.addEventListener("load", create_promise_resolver_with_loaf); | ||
xhr.send(); | ||
}, script => script.name === "Window.fetch.then", t); | ||
assert_true(script.sourceLocation?.startsWith("create_promise_resolver_with_loaf")); | ||
}, "promise-resolver source location is attributed to event listener who created the resolver"); | ||
|
||
promise_test(async t => { | ||
const [entry, script] = await expect_long_frame_with_script(() => { | ||
const script_tag = document.createElement("script"); | ||
t.add_cleanup(() => script_tag.remove()); | ||
script_tag.src = "resources/busy_in_promise.js"; | ||
document.body.append(script_tag); | ||
}, script => script.name === "Window.fetch.then", t); | ||
assert_true(script.sourceLocation?.includes("busy_in_promise.js")); | ||
}, "promise-resolver source location is attributed to script block who created the resolver"); | ||
|
||
|
||
</script> | ||
</body> |
6 changes: 6 additions & 0 deletions
6
.../blink/web_tests/external/wpt/long-animation-frame/tentative/resources/busy_in_promise.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fetch("/common/dummy.xml").then(() => { | ||
const deadline = performance.now() + 360; | ||
while (performance.now() < deadline) { | ||
|
||
} | ||
}); |