From e7ee1171d8d3f4b61a47d043d3835c6c8ac9e460 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Fri, 20 Feb 2026 18:32:34 +0100 Subject: [PATCH] script: Remove some proprietary Servo-only testing methods from `Window` (#42728) These three methods date back from the very early history of Servo and are no longer necessary: 1. `Window.debug`: `console.log` is a better replacement for this method now. A manual test that tests the very basics of JavaScript used this. This test is removed as well. 2. `Window.gc`: This can be replaced with `TestUtils.gc`, which is part of a W3C specification. 3. `Window.js_backtrace`: This method is moved to `ServoTestUtils`. Testing: Tests are updated to reflect these changes. Signed-off-by: Martin Robinson --- .../script/dom/testing/servotestutils.rs | 7 +++++ components/script/dom/testing/testbinding.rs | 3 +- components/script/dom/window.rs | 31 +++++-------------- .../webidls/ServoTestUtils.webidl | 2 ++ .../script_bindings/webidls/Window.webidl | 10 ------ components/servo/tests/multiprocess.rs | 4 +-- tests/html/test-js.html | 25 --------------- tests/html/test.js | 1 - tests/wpt/mozilla/meta/MANIFEST.json | 12 +++---- .../tests/mozilla/media_query_list_gc.html | 4 +-- tests/wpt/mozilla/tests/mozilla/promise.html | 6 ++-- .../wpt/mozilla/tests/mozilla/prototypes.html | 4 +-- .../wpt/mozilla/tests/mozilla/trace_null.html | 4 +-- .../tests/mozilla/transitionend_safety.html | 4 +-- tests/wpt/mozilla/tests/mozilla/weakref.html | 6 ++-- 15 files changed, 41 insertions(+), 82 deletions(-) delete mode 100644 tests/html/test-js.html delete mode 100644 tests/html/test.js diff --git a/components/script/dom/testing/servotestutils.rs b/components/script/dom/testing/servotestutils.rs index c7bc063a090..c169a2b458a 100644 --- a/components/script/dom/testing/servotestutils.rs +++ b/components/script/dom/testing/servotestutils.rs @@ -4,6 +4,7 @@ // check-tidy: no specs after this line +use backtrace::Backtrace; use dom_struct::dom_struct; use layout_api::ReflowPhasesRun; use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods; @@ -57,6 +58,12 @@ impl ServoTestUtilsMethods for ServoTestUtils { LayoutResult::new(global, phases, can_gc) } + fn Js_backtrace(_: &GlobalScope) { + println!("Current JS stack:"); + let rust_stack = Backtrace::new(); + println!("Current Rust stack:\n{:?}", rust_stack); + } + fn Panic(_: &GlobalScope) { panic!("explicit panic from script") } diff --git a/components/script/dom/testing/testbinding.rs b/components/script/dom/testing/testbinding.rs index 215aebea591..5d686a15db5 100644 --- a/components/script/dom/testing/testbinding.rs +++ b/components/script/dom/testing/testbinding.rs @@ -17,7 +17,6 @@ use js::realm::CurrentRealm; use js::rust::{CustomAutoRooterGuard, HandleObject, HandleValue, MutableHandleValue}; use js::typedarray::{self, HeapUint8ClampedArray}; use script_bindings::cformat; -use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods; use script_bindings::interfaces::TestBindingHelpers; use script_bindings::record::Record; use servo_config::prefs; @@ -569,7 +568,7 @@ impl TestBindingMethods for TestBinding { &self, _dictionary: RootedTraceableBox, ) { - self.global().as_window().Gc(); + self.global().as_window().gc(); } fn ReceiveTestDictionaryWithSuccessOnKeyword(&self) -> RootedTraceableBox { RootedTraceableBox::new(TestDictionary { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index b9ffd1d8c53..27f2aba1f11 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -15,7 +15,6 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use app_units::Au; -use backtrace::Backtrace; use base::cross_process_instant::CrossProcessInstant; use base::generic_channel::{self, GenericCallback, GenericSender}; use base::id::{BrowsingContextId, PipelineId, WebViewId}; @@ -942,6 +941,13 @@ impl Window { }), } } + + #[expect(unsafe_code)] + pub(crate) fn gc(&self) { + unsafe { + JS_GC(*self.get_cx(), GCReason::API); + } + } } #[derive(Debug)] @@ -1771,27 +1777,6 @@ impl WindowMethods for Window { } // check-tidy: no specs after this line - fn Debug(&self, message: DOMString) { - debug!("{}", message); - } - - #[expect(unsafe_code)] - fn Gc(&self) { - unsafe { - JS_GC(*self.get_cx(), GCReason::API); - } - } - - #[expect(unsafe_code)] - fn Js_backtrace(&self) { - unsafe { - println!("Current JS stack:"); - dump_js_stack(*self.get_cx()); - let rust_stack = Backtrace::new(); - println!("Current Rust stack:\n{:?}", rust_stack); - } - } - fn WebdriverCallback(&self, realm: &mut CurrentRealm, value: HandleValue) { let webdriver_script_sender = self.webdriver_script_chan.borrow_mut().take(); if let Some(webdriver_script_sender) = webdriver_script_sender { @@ -3358,7 +3343,7 @@ impl Window { // GC any unreachable objects generated by user script, // or unattached DOM nodes. Attached DOM nodes can't be GCd yet, // as the document might be reactivated later. - self.Gc(); + self.gc(); } pub(crate) fn resume(&self, can_gc: CanGc) { diff --git a/components/script_bindings/webidls/ServoTestUtils.webidl b/components/script_bindings/webidls/ServoTestUtils.webidl index a876fab2cfe..7fc6f9281f9 100644 --- a/components/script_bindings/webidls/ServoTestUtils.webidl +++ b/components/script_bindings/webidls/ServoTestUtils.webidl @@ -17,6 +17,8 @@ namespace ServoTestUtils { [Exposed=Window] LayoutResult forceLayout(); + undefined js_backtrace(); + undefined panic(); }; diff --git a/components/script_bindings/webidls/Window.webidl b/components/script_bindings/webidls/Window.webidl index eafa38d408e..166b639f577 100644 --- a/components/script_bindings/webidls/Window.webidl +++ b/components/script_bindings/webidls/Window.webidl @@ -135,16 +135,6 @@ partial interface Window { [Replaceable] readonly attribute double devicePixelRatio; }; -// Proprietary extensions. -partial interface Window { - [Pref="dom_servo_helpers_enabled"] - undefined debug(DOMString arg); - [Pref="dom_servo_helpers_enabled"] - undefined gc(); - [Pref="dom_servo_helpers_enabled"] - undefined js_backtrace(); -}; - // WebDriver extensions partial interface Window { // Shouldn't be public, but just to make things work for now diff --git a/components/servo/tests/multiprocess.rs b/components/servo/tests/multiprocess.rs index 748b915ad6d..826a4422cf5 100644 --- a/components/servo/tests/multiprocess.rs +++ b/components/servo/tests/multiprocess.rs @@ -29,7 +29,7 @@ fn test_multiprocess_preference_observer() { .delegate(delegate.clone()) .build(); - let result = evaluate_javascript(&servo_test, webview.clone(), "window.gc"); + let result = evaluate_javascript(&servo_test, webview.clone(), "window.ServoTestUtils"); assert_eq!(result, Ok(JSValue::Undefined)); let mut prefs = prefs::get().clone(); @@ -40,7 +40,7 @@ fn test_multiprocess_preference_observer() { webview.reload(); servo_test.spin(move || !delegate.load_status_changed.get()); - let result = evaluate_javascript(&servo_test, webview.clone(), "window.gc"); + let result = evaluate_javascript(&servo_test, webview.clone(), "window.ServoTestUtils"); assert!(matches!(result, Ok(JSValue::Object(..)))); } diff --git a/tests/html/test-js.html b/tests/html/test-js.html deleted file mode 100644 index 40f94281e07..00000000000 --- a/tests/html/test-js.html +++ /dev/null @@ -1,25 +0,0 @@ -
- -
- -
-
- diff --git a/tests/html/test.js b/tests/html/test.js deleted file mode 100644 index 262c1b4f1b0..00000000000 --- a/tests/html/test.js +++ /dev/null @@ -1 +0,0 @@ -debug("Hello, world!"); diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 5176ba04767..8af2ae89f40 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -14226,7 +14226,7 @@ ] ], "media_query_list_gc.html": [ - "36c13b5305e79f216375c384594374f2606797ea", + "c24500e1674b802883e4a33bdfa7823a218c81b9", [ null, {} @@ -14510,14 +14510,14 @@ ] ], "promise.html": [ - "5925047287175f291c07ee88075359ed92a86e6a", + "c4ce6b3ae93bbe78749f7304a2a966e5888ddd71", [ null, {} ] ], "prototypes.html": [ - "478b89a6fb876477711c19e392d7e4d190bff7a0", + "1d145bdd0f8540a68015fead0c93189edee157ad", [ null, {} @@ -14735,7 +14735,7 @@ ] ], "trace_null.html": [ - "bb4f8c1fc52af604a16bf01b198e5ba2857fdbe9", + "6a1eae5b741b13efff8bbced5a36b9f52558979d", [ null, {} @@ -14749,7 +14749,7 @@ ] ], "transitionend_safety.html": [ - "b72766c357af9553f1f7411b8d27c404f1e3fcde", + "c993fbc61cd4d604b5dde050d308884bd409ff79", [ null, {} @@ -14793,7 +14793,7 @@ ] ], "weakref.html": [ - "4deccbe1e26a3f921eea85a4395394a55cc88be4", + "091ff3e67e2999c54fc6e9ee95f7fd331f94501a", [ null, {} diff --git a/tests/wpt/mozilla/tests/mozilla/media_query_list_gc.html b/tests/wpt/mozilla/tests/mozilla/media_query_list_gc.html index 36c13b5305e..c24500e1674 100644 --- a/tests/wpt/mozilla/tests/mozilla/media_query_list_gc.html +++ b/tests/wpt/mozilla/tests/mozilla/media_query_list_gc.html @@ -4,10 +4,10 @@ diff --git a/tests/wpt/mozilla/tests/mozilla/promise.html b/tests/wpt/mozilla/tests/mozilla/promise.html index 59250472871..c4ce6b3ae93 100644 --- a/tests/wpt/mozilla/tests/mozilla/promise.html +++ b/tests/wpt/mozilla/tests/mozilla/promise.html @@ -52,13 +52,15 @@ }); }, 'Native reject callback gets argument'); - promise_test(function(test) { + promise_test(async function(test) { var t = new TestBinding; var resolved; var p = new Promise(function() {}); var start = Date.now(); t.resolvePromiseDelayed(p, 'success', 100); - test.step_timeout(function() { window.gc() }, 0); + + await TestUtils.gc(); + return p.then(function(v) { var end = Date.now(); assert_greater_than_equal(end - start, 100); diff --git a/tests/wpt/mozilla/tests/mozilla/prototypes.html b/tests/wpt/mozilla/tests/mozilla/prototypes.html index 478b89a6fb8..1d145bdd0f8 100644 --- a/tests/wpt/mozilla/tests/mozilla/prototypes.html +++ b/tests/wpt/mozilla/tests/mozilla/prototypes.html @@ -7,9 +7,9 @@ foo diff --git a/tests/wpt/mozilla/tests/mozilla/transitionend_safety.html b/tests/wpt/mozilla/tests/mozilla/transitionend_safety.html index b72766c357a..c993fbc61cd 100644 --- a/tests/wpt/mozilla/tests/mozilla/transitionend_safety.html +++ b/tests/wpt/mozilla/tests/mozilla/transitionend_safety.html @@ -15,10 +15,10 @@ t.step_timeout(function() { elem.style.color = 'red'; - t.step_timeout(function() { + t.step_timeout(async function() { document.body.removeChild(elem); elem = null; - window.gc(); + await TestUtils.gc(); t.step_timeout(t.step_func_done(), 100); }, 0); }, 0); diff --git a/tests/wpt/mozilla/tests/mozilla/weakref.html b/tests/wpt/mozilla/tests/mozilla/weakref.html index 4deccbe1e26..091ff3e67e2 100644 --- a/tests/wpt/mozilla/tests/mozilla/weakref.html +++ b/tests/wpt/mozilla/tests/mozilla/weakref.html @@ -4,7 +4,7 @@