alphabetized frozen supported entry types on the global, avoid moving Heap into Option

This commit is contained in:
Patrick Shaughnessy 2020-02-05 18:32:42 -05:00
parent 4f36472b6f
commit e0b768c6cc
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;
};

View file

@ -1,4 +1,4 @@
[supported_navigation_type.window.html]
[supportedEntryTypes contains 'navigation'.]
expected: FAIL
expected: TIMEOUT
['navigation' entries should be observable.]
expected: TIMEOUT

View file

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

View file

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

View file

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