Auto merge of #25697 - pshaughn:supportedentrytypes, r=jdm

PerformanceObserver.supportedEntryTypes

<!-- Please describe your changes on the following line: -->
It felt odd to cache these directly in GlobalScope, but they need to be [SameObject] and the global scope is where the spec implies they go.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25587

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-02-14 19:02:51 -05:00 committed by GitHub
commit 1987061a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 66 additions and 49 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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 {

View file

@ -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;
};