Skip to content

Commit

Permalink
alphabetized frozen supported entry types on the global, avoid moving…
Browse files Browse the repository at this point in the history
… Heap into Option
  • Loading branch information
pshaughn committed Feb 14, 2020
1 parent 4f36472 commit e0b768c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 49 deletions.
11 changes: 7 additions & 4 deletions components/script/dom/extendablemessageevent.rs
Expand Up @@ -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
}
Expand Down
32 changes: 31 additions & 1 deletion components/script/dom/globalscope.rs
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()),
}
}

Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 7 additions & 4 deletions components/script/dom/messageevent.rs
Expand Up @@ -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
}
Expand Down
22 changes: 16 additions & 6 deletions components/script/dom/performanceobserver.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/webidls/PerformanceObserver.webidl
Expand Up @@ -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;
};
@@ -1,4 +1,4 @@
[supported_navigation_type.window.html]
[supportedEntryTypes contains 'navigation'.]
expected: FAIL

expected: TIMEOUT
['navigation' entries should be observable.]
expected: TIMEOUT
6 changes: 0 additions & 6 deletions tests/wpt/metadata/performance-timeline/idlharness.any.js.ini
Expand Up @@ -11,9 +11,6 @@
[Test default toJSON operation of PerformanceMark]
expected: FAIL

[PerformanceObserver interface: attribute supportedEntryTypes]
expected: FAIL

[PerformanceMark interface: attribute detail]
expected: FAIL

Expand All @@ -31,9 +28,6 @@
[Test default toJSON operation of PerformanceMark]
expected: FAIL

[PerformanceObserver interface: attribute supportedEntryTypes]
expected: FAIL

[PerformanceMark interface: attribute detail]
expected: FAIL

Expand Down

This file was deleted.

This file was deleted.

0 comments on commit e0b768c

Please sign in to comment.