loaf-source-location.html (3551B)
1 <!DOCTYPE HTML> 2 <meta charset=utf-8> 3 <title>Long Animation Frame Timing: source location extraction</title> 4 <meta name="timeout" content="long"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="resources/utils.js"></script> 8 9 <body> 10 <h1>Long Animation Frame: source location extraction</h1> 11 <div id="log"></div> 12 <script> 13 14 promise_test(async t => { 15 const [entry, script] = await expect_long_frame_with_script((t, busy_wait) => { 16 requestAnimationFrame(function non_bound_function() { 17 busy_wait(); 18 }); 19 }, script => script.invoker === "FrameRequestCallback", t); 20 assert_equals(script.sourceURL, location.href); 21 assert_equals(script.sourceFunctionName, "non_bound_function"); 22 assert_greater_than(script.sourceCharPosition, 0); 23 assert_greater_than(script.sourceLine, 0); 24 assert_greater_than(script.sourceColumn, 0); 25 }, "Source location should be extracted from non-bound functions"); 26 27 promise_test(async t => { 28 const [entry, script] = await expect_long_frame_with_script((t, busy_wait) => { 29 const object = {}; 30 requestAnimationFrame((function my_bound_function() { 31 busy_wait(); 32 }).bind(object)); 33 }, script => script.invoker === "FrameRequestCallback", t); 34 assert_equals(script.sourceURL, location.href); 35 assert_equals(script.sourceFunctionName, "my_bound_function"); 36 assert_greater_than(script.sourceCharPosition, 0); 37 assert_greater_than(script.sourceLine, 0); 38 assert_greater_than(script.sourceColumn, 0); 39 }, "Source location should be extracted from bound functions"); 40 41 promise_test(async t => { 42 const [entry, script] = await expect_long_frame_with_script((t, busy_wait) => { 43 t.step_timeout(function my_timeout() { 44 busy_wait(); 45 }); 46 }, script => script.invoker === "TimerHandler:setTimeout" && script.sourceURL, t ); 47 assert_true(script.sourceURL.includes("testharness.js")); 48 }, "Source location should be extracted for setTimeout"); 49 50 promise_test(async t => { 51 const scriptLocation = new URL("resources/promise-generates-loaf.js", location.href); 52 const [entry, script] = await expect_long_frame_with_script((t, busy_wait) => { 53 const scriptElement = document.createElement("script"); 54 scriptElement.src = scriptLocation; 55 document.body.appendChild(scriptElement); 56 }, script => script.invoker === "Window.fetch.then", t); 57 assert_true(script.sourceURL.includes("promise-generates-loaf.js")); 58 assert_equals(script.sourceCharPosition, 0); 59 assert_equals(script.sourceLine, 1); 60 assert_equals(script.sourceColumn, 1); 61 }, "Source location should be extracted for promises"); 62 63 // This test verifies that script entries of type "promise-resolve" correctly return 64 // the sourceCharPosition value. It ensures that the reported position matches the 65 // expected starting character position in the source code. 66 promise_test(async t => { 67 const scriptLocation = new URL("resources/promise-generates-loaf-start-pos.js", location.href); 68 const [entry, script] = await expect_long_frame_with_script((t, busy_wait) => { 69 const scriptElement = document.createElement("script"); 70 scriptElement.src = scriptLocation; 71 document.body.appendChild(scriptElement); 72 }, script => script.invoker === "Window.fetch.then", t); 73 assert_true(script.sourceURL.includes("promise-generates-loaf-start-pos.js")); 74 assert_equals(script.sourceCharPosition, 64); 75 assert_equals(script.sourceLine, 2); 76 assert_equals(script.sourceColumn, 1); 77 }, "SourceCharPosition should be 64 for promises"); 78 79 </script> 80 </body>