Skip to content

Commit

Permalink
[LoAF] Set sourceCharPosition for the invoke-type resolve-promise
Browse files Browse the repository at this point in the history
The script entries of LoAF for the promise-resolve invoker type do not
provide sourceCharPosition. This CL enables the provision of the source
position.

- Introduced CapturePartialSourceLocationFromStack(v8::Isolate*) to
  retrieve both URL and starting character position of the currently
  executing script.
- Added LongAnimationFrameSourceCharPosition runtime flag.

Bug: 381529126
Test:
- external/wpt/long-animation-frame/tentative/loaf-source-
location.html
- external/wpt/long-animation-frame/tentative/loaf-source-location-redirect.html

Change-Id: I481a62d8eb4a5649fdddcff5b657d442335e8725
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6060398
Reviewed-by: Noam Rosenthal <[email protected]>
Commit-Queue: Joone Hur <[email protected]>
Reviewed-by: Nate Chapin <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1397921}
  • Loading branch information
Joone Hur authored and chromium-wpt-export-bot committed Dec 18, 2024
1 parent 6417320 commit be827da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h1>Long Animation Frame: source location with cross-origin redirects</h1>
assert_not_equals(result, "empty", "CORS-ok scripts should expose sourceLocation");
} else {
assert_equals(result, "pre-redirect", "No-CORS classic scripts should expose pre-redirect URL");
assert_equals(script.sourceCharPosition, type === "script-block" ? 0 : -1, "No-CORS classic scripts should not expose character index");
assert_equals(script.sourceCharPosition, type === "script-block" || type === "resolve-promise" ? 0 : -1, "No-CORS classic scripts should not expose character index");
}
}, `Test ${type} with ${scriptType}`);
}
Expand Down
15 changes: 15 additions & 0 deletions long-animation-frame/tentative/loaf-source-location.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,22 @@ <h1>Long Animation Frame: source location extraction</h1>
document.body.appendChild(scriptElement);
}, script => script.invoker === "Window.fetch.then", t);
assert_true(script.sourceURL.includes("promise-generates-loaf.js"));
assert_equals(script.sourceCharPosition, 0);
}, "Source location should be extracted for promises");

// This test verifies that script entries of type "promise-resolve" correctly return
// the sourceCharPosition value. It ensures that the reported position matches the
// expected starting character position in the source code.
promise_test(async t => {
const scriptLocation = new URL("resources/promise-generates-loaf-start-pos.js", location.href);
const [entry, script] = await expect_long_frame_with_script((t, busy_wait) => {
const scriptElement = document.createElement("script");
scriptElement.src = scriptLocation;
document.body.appendChild(scriptElement);
}, script => script.invoker === "Window.fetch.then", t);
assert_true(script.sourceURL.includes("promise-generates-loaf-start-pos.js"));
assert_equals(script.sourceCharPosition, 64);
}, "SourceCharPosition should be 64 for promises");

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// The starting position of this code in the source file is 64.
fetch("/common/dummy.xml").then(() => {
generate_loaf_now();
});

0 comments on commit be827da

Please sign in to comment.