From be827da9a1b11b79fc9855e9f5ed3f1282613116 Mon Sep 17 00:00:00 2001 From: Joone Hur Date: Wed, 18 Dec 2024 07:34:14 -0800 Subject: [PATCH] [LoAF] Set sourceCharPosition for the invoke-type resolve-promise 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 Commit-Queue: Joone Hur Reviewed-by: Nate Chapin Cr-Commit-Position: refs/heads/main@{#1397921} --- .../tentative/loaf-source-location-redirect.html | 2 +- .../tentative/loaf-source-location.html | 15 +++++++++++++++ .../resources/promise-generates-loaf-start-pos.js | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 long-animation-frame/tentative/resources/promise-generates-loaf-start-pos.js diff --git a/long-animation-frame/tentative/loaf-source-location-redirect.html b/long-animation-frame/tentative/loaf-source-location-redirect.html index 6d87b138350d52..139ab5227c24c6 100644 --- a/long-animation-frame/tentative/loaf-source-location-redirect.html +++ b/long-animation-frame/tentative/loaf-source-location-redirect.html @@ -63,7 +63,7 @@

Long Animation Frame: source location with cross-origin redirects

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}`); } diff --git a/long-animation-frame/tentative/loaf-source-location.html b/long-animation-frame/tentative/loaf-source-location.html index 65aaec7b8be074..b5982ea339e9c9 100644 --- a/long-animation-frame/tentative/loaf-source-location.html +++ b/long-animation-frame/tentative/loaf-source-location.html @@ -51,7 +51,22 @@

Long Animation Frame: source location extraction

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"); + diff --git a/long-animation-frame/tentative/resources/promise-generates-loaf-start-pos.js b/long-animation-frame/tentative/resources/promise-generates-loaf-start-pos.js new file mode 100644 index 00000000000000..f8b339eee2bf33 --- /dev/null +++ b/long-animation-frame/tentative/resources/promise-generates-loaf-start-pos.js @@ -0,0 +1,4 @@ +// The starting position of this code in the source file is 64. +fetch("/common/dummy.xml").then(() => { + generate_loaf_now(); +}); \ No newline at end of file