diff options
9 files changed, 66 insertions, 49 deletions
diff --git a/components/script/dom/extendablemessageevent.rs b/components/script/dom/extendablemessageevent.rs index ff9903fc1a6..ce9539d091f 100644 --- a/components/script/dom/extendablemessageevent.rs +++ b/components/script/dom/extendablemessageevent.rs @@ -159,10 +159,13 @@ impl ExtendableMessageEventMethods for ExtendableMessageEvent { .collect(); let frozen_ports = to_frozen_array(ports.as_slice(), cx); - // Cache the Js value. - let heap_val = Heap::default(); - heap_val.set(frozen_ports); - *self.frozen_ports.borrow_mut() = Some(heap_val); + // Safety: need to create the Heap value in its final memory location before setting it. + *self.frozen_ports.borrow_mut() = Some(Heap::default()); + self.frozen_ports + .borrow() + .as_ref() + .unwrap() + .set(frozen_ports); frozen_ports } diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index f96f1101bca..a773ac3c7c7 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -16,6 +16,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::settings_stack::{entry_global, incumbent_global, AutoEntryScript}; use crate::dom::bindings::str::DOMString; use crate::dom::bindings::structuredclone; +use crate::dom::bindings::utils::to_frozen_array; use crate::dom::bindings::weakref::{DOMTracker, WeakRef}; use crate::dom::blob::Blob; use crate::dom::crypto::Crypto; @@ -31,6 +32,7 @@ use crate::dom::messageevent::MessageEvent; use crate::dom::messageport::MessagePort; use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope; use crate::dom::performance::Performance; +use crate::dom::performanceobserver::VALID_ENTRY_TYPES; use crate::dom::promise::Promise; use crate::dom::window::Window; use crate::dom::workerglobalscope::WorkerGlobalScope; @@ -63,7 +65,7 @@ use js::jsapi::JSObject; use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal}; use js::jsapi::{HandleObject, Heap}; use js::jsapi::{JSAutoRealm, JSContext}; -use js::jsval::UndefinedValue; +use js::jsval::{JSVal, UndefinedValue}; use js::panic::maybe_resume_unwind; use js::rust::wrappers::EvaluateUtf8; use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime}; @@ -222,6 +224,10 @@ pub struct GlobalScope { #[ignore_malloc_size_of = "defined in wgpu"] gpu_id_hub: RefCell<Identities>, + + // https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute + #[ignore_malloc_size_of = "mozjs"] + frozen_supported_performance_entry_types: DomRefCell<Option<Heap<JSVal>>>, } /// A wrapper for glue-code between the ipc router and the event-loop. @@ -513,6 +519,7 @@ impl GlobalScope { is_headless, user_agent, gpu_id_hub: RefCell::new(Identities::new()), + frozen_supported_performance_entry_types: DomRefCell::new(Default::default()), } } @@ -2087,6 +2094,29 @@ impl GlobalScope { unreachable!(); } + // https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute + pub fn supported_performance_entry_types(&self, cx: SafeJSContext) -> JSVal { + if let Some(types) = &*self.frozen_supported_performance_entry_types.borrow() { + return types.get(); + } + + let types: Vec<DOMString> = VALID_ENTRY_TYPES + .iter() + .map(|t| DOMString::from(t.to_string())) + .collect(); + let frozen_types = to_frozen_array(types.as_slice(), cx); + + // Safety: need to create the Heap value in its final memory location before setting it. + *self.frozen_supported_performance_entry_types.borrow_mut() = Some(Heap::default()); + self.frozen_supported_performance_entry_types + .borrow() + .as_ref() + .unwrap() + .set(frozen_types); + + frozen_types + } + pub fn is_headless(&self) -> bool { self.is_headless } diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs index 62d7789e7e5..447c2f3ccd1 100644 --- a/components/script/dom/messageevent.rs +++ b/components/script/dom/messageevent.rs @@ -255,10 +255,13 @@ impl MessageEventMethods for MessageEvent { .collect(); let frozen_ports = to_frozen_array(ports.as_slice(), cx); - // Cache the Js value. - let heap_val = Heap::default(); - heap_val.set(frozen_ports); - *self.frozen_ports.borrow_mut() = Some(heap_val); + // Safety: need to create the Heap value in its final memory location before setting it. + *self.frozen_ports.borrow_mut() = Some(Heap::default()); + self.frozen_ports + .borrow() + .as_ref() + .unwrap() + .set(frozen_ports); frozen_ports } diff --git a/components/script/dom/performanceobserver.rs b/components/script/dom/performanceobserver.rs index e107c4a08d9..2b52c86e4f2 100644 --- a/components/script/dom/performanceobserver.rs +++ b/components/script/dom/performanceobserver.rs @@ -18,19 +18,21 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::performance::PerformanceEntryList; use crate::dom::performanceentry::PerformanceEntry; use crate::dom::performanceobserverentrylist::PerformanceObserverEntryList; +use crate::script_runtime::JSContext; use dom_struct::dom_struct; +use js::jsval::JSVal; use std::cell::Cell; use std::rc::Rc; -/// List of allowed performance entry types. -const VALID_ENTRY_TYPES: &'static [&'static str] = &[ +/// List of allowed performance entry types, in alphabetical order. +pub const VALID_ENTRY_TYPES: &'static [&'static str] = &[ + // "frame", //TODO Frame Timing API "mark", // User Timing API "measure", // User Timing API - "resource", // Resource Timing API "navigation", // Navigation Timing API - // "frame", //TODO Frame Timing API - // "server", XXX Server Timing API - "paint", // Paint Timing API + "paint", // Paint Timing API + "resource", // Resource Timing API + // "server", XXX Server Timing API ]; #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] @@ -110,6 +112,14 @@ impl PerformanceObserver { pub fn set_entries(&self, entries: DOMPerformanceEntryList) { *self.entries.borrow_mut() = entries; } + + // https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute + #[allow(non_snake_case)] + pub fn SupportedEntryTypes(cx: JSContext, global: &GlobalScope) -> JSVal { + // While this is exposed through a method of PerformanceObserver, + // it is specified as associated with the global scope. + global.supported_performance_entry_types(cx) + } } impl PerformanceObserverMethods for PerformanceObserver { diff --git a/components/script/dom/webidls/PerformanceObserver.webidl b/components/script/dom/webidls/PerformanceObserver.webidl index dd3a66b299d..db511a7b4b7 100644 --- a/components/script/dom/webidls/PerformanceObserver.webidl +++ b/components/script/dom/webidls/PerformanceObserver.webidl @@ -21,5 +21,6 @@ interface PerformanceObserver { void observe(optional PerformanceObserverInit options = {}); void disconnect(); PerformanceEntryList takeRecords(); - // [SameObject] static readonly attribute FrozenArray<DOMString> supportedEntryTypes; + // codegen doesn't like SameObject+static and doesn't know FrozenArray + /*[SameObject]*/ static readonly attribute /*FrozenArray<DOMString>*/ any supportedEntryTypes; }; diff --git a/tests/wpt/metadata/navigation-timing/supported_navigation_type.window.js.ini b/tests/wpt/metadata/navigation-timing/supported_navigation_type.window.js.ini index e528a82215c..d8d3623bff6 100644 --- a/tests/wpt/metadata/navigation-timing/supported_navigation_type.window.js.ini +++ b/tests/wpt/metadata/navigation-timing/supported_navigation_type.window.js.ini @@ -1,4 +1,4 @@ [supported_navigation_type.window.html] - [supportedEntryTypes contains 'navigation'.] - expected: FAIL - + expected: TIMEOUT + ['navigation' entries should be observable.] + expected: TIMEOUT diff --git a/tests/wpt/metadata/performance-timeline/idlharness.any.js.ini b/tests/wpt/metadata/performance-timeline/idlharness.any.js.ini index 73206303830..c303b715daa 100644 --- a/tests/wpt/metadata/performance-timeline/idlharness.any.js.ini +++ b/tests/wpt/metadata/performance-timeline/idlharness.any.js.ini @@ -11,9 +11,6 @@ [Test default toJSON operation of PerformanceMark] expected: FAIL - [PerformanceObserver interface: attribute supportedEntryTypes] - expected: FAIL - [PerformanceMark interface: attribute detail] expected: FAIL @@ -31,9 +28,6 @@ [Test default toJSON operation of PerformanceMark] expected: FAIL - [PerformanceObserver interface: attribute supportedEntryTypes] - expected: FAIL - [PerformanceMark interface: attribute detail] expected: FAIL diff --git a/tests/wpt/metadata/performance-timeline/supportedEntryTypes.any.js.ini b/tests/wpt/metadata/performance-timeline/supportedEntryTypes.any.js.ini deleted file mode 100644 index 7a4c5914b17..00000000000 --- a/tests/wpt/metadata/performance-timeline/supportedEntryTypes.any.js.ini +++ /dev/null @@ -1,15 +0,0 @@ -[supportedEntryTypes.any.html] - [supportedEntryTypes exists and returns entries in alphabetical order] - expected: FAIL - - [supportedEntryTypes caches result] - expected: FAIL - - -[supportedEntryTypes.any.worker.html] - [supportedEntryTypes exists and returns entries in alphabetical order] - expected: FAIL - - [supportedEntryTypes caches result] - expected: FAIL - diff --git a/tests/wpt/metadata/resource-timing/supported_resource_type.any.js.ini b/tests/wpt/metadata/resource-timing/supported_resource_type.any.js.ini deleted file mode 100644 index 5ff8c59cc26..00000000000 --- a/tests/wpt/metadata/resource-timing/supported_resource_type.any.js.ini +++ /dev/null @@ -1,9 +0,0 @@ -[supported_resource_type.any.html] - [supportedEntryTypes contains 'resource'.] - expected: FAIL - - -[supported_resource_type.any.worker.html] - [supportedEntryTypes contains 'resource'.] - expected: FAIL - |