mirror of
https://github.com/servo/servo.git
synced 2025-06-15 11:54:28 +00:00
Add Performance object to Window and implement Performance::Now()
This commit is contained in:
parent
0ab3444af9
commit
fb0c433b70
9 changed files with 223 additions and 1 deletions
|
@ -41,6 +41,8 @@ DOMInterfaces = {
|
||||||
'Navigator': {},
|
'Navigator': {},
|
||||||
'Node': {},
|
'Node': {},
|
||||||
'NodeList': {},
|
'NodeList': {},
|
||||||
|
'Performance': {},
|
||||||
|
'PerformanceTiming': {},
|
||||||
'UIEvent': {},
|
'UIEvent': {},
|
||||||
'ValidityState': {},
|
'ValidityState': {},
|
||||||
'Window': {
|
'Window': {
|
||||||
|
|
59
src/components/script/dom/performance.rs
Normal file
59
src/components/script/dom/performance.rs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::BindingDeclarations::PerformanceBinding;
|
||||||
|
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||||
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
|
use dom::performancetiming::{PerformanceTiming, PerformanceTimingMethods};
|
||||||
|
use dom::window::Window;
|
||||||
|
|
||||||
|
use time;
|
||||||
|
|
||||||
|
pub type DOMHighResTimeStamp = f64;
|
||||||
|
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
pub struct Performance {
|
||||||
|
pub reflector_: Reflector,
|
||||||
|
pub timing: JS<PerformanceTiming>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Performance {
|
||||||
|
fn new_inherited(window: &JSRef<Window>) -> Performance {
|
||||||
|
Performance {
|
||||||
|
reflector_: Reflector::new(),
|
||||||
|
timing: PerformanceTiming::new(window).root().root_ref().unrooted(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(window: &JSRef<Window>) -> Temporary<Performance> {
|
||||||
|
let performance = Performance::new_inherited(window);
|
||||||
|
reflect_dom_object(~performance, window, PerformanceBinding::Wrap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait PerformanceMethods {
|
||||||
|
fn Timing(&self) -> Temporary<PerformanceTiming>;
|
||||||
|
fn Now(&self) -> DOMHighResTimeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> PerformanceMethods for JSRef<'a, Performance> {
|
||||||
|
fn Timing(&self) -> Temporary<PerformanceTiming> {
|
||||||
|
Temporary::new(self.timing.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn Now(&self) -> DOMHighResTimeStamp {
|
||||||
|
let navStart = self.timing.root().NavigationStartPrecise() as f64;
|
||||||
|
(time::precise_time_s() - navStart) as DOMHighResTimeStamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reflectable for Performance {
|
||||||
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
|
&self.reflector_
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
|
||||||
|
&mut self.reflector_
|
||||||
|
}
|
||||||
|
}
|
57
src/components/script/dom/performancetiming.rs
Normal file
57
src/components/script/dom/performancetiming.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::BindingDeclarations::PerformanceTimingBinding;
|
||||||
|
use dom::bindings::js::{JSRef, Temporary};
|
||||||
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
|
use dom::window::Window;
|
||||||
|
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
pub struct PerformanceTiming {
|
||||||
|
pub reflector_: Reflector,
|
||||||
|
pub navigationStart: u64,
|
||||||
|
pub navigationStartPrecise: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PerformanceTiming {
|
||||||
|
pub fn new_inherited(navStart: u64, navStartPrecise: f64)
|
||||||
|
-> PerformanceTiming {
|
||||||
|
PerformanceTiming {
|
||||||
|
reflector_: Reflector::new(),
|
||||||
|
navigationStart: navStart,
|
||||||
|
navigationStartPrecise: navStartPrecise,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(window: &JSRef<Window>) -> Temporary<PerformanceTiming> {
|
||||||
|
let timing = PerformanceTiming::new_inherited(window.navigationStart,
|
||||||
|
window.navigationStartPrecise);
|
||||||
|
reflect_dom_object(~timing, window, PerformanceTimingBinding::Wrap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait PerformanceTimingMethods {
|
||||||
|
fn NavigationStart(&self) -> u64;
|
||||||
|
fn NavigationStartPrecise(&self) -> f64;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> PerformanceTimingMethods for JSRef<'a, PerformanceTiming> {
|
||||||
|
fn NavigationStart(&self) -> u64 {
|
||||||
|
self.navigationStart
|
||||||
|
}
|
||||||
|
|
||||||
|
fn NavigationStartPrecise(&self) -> f64 {
|
||||||
|
self.navigationStartPrecise
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reflectable for PerformanceTiming {
|
||||||
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
|
&self.reflector_
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
|
||||||
|
&mut self.reflector_
|
||||||
|
}
|
||||||
|
}
|
19
src/components/script/dom/webidls/Performance.webidl
Normal file
19
src/components/script/dom/webidls/Performance.webidl
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* The origin of this IDL file is
|
||||||
|
* https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html#sec-window.performance-attribute
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef double DOMHighResTimeStamp;
|
||||||
|
|
||||||
|
interface Performance {
|
||||||
|
readonly attribute PerformanceTiming timing;
|
||||||
|
/* readonly attribute PerformanceNavigation navigation; */
|
||||||
|
};
|
||||||
|
|
||||||
|
partial interface Performance {
|
||||||
|
DOMHighResTimeStamp now();
|
||||||
|
};
|
32
src/components/script/dom/webidls/PerformanceTiming.webidl
Normal file
32
src/components/script/dom/webidls/PerformanceTiming.webidl
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* The origin of this IDL file is
|
||||||
|
* https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html#sec-navigation-timing-interface
|
||||||
|
*/
|
||||||
|
|
||||||
|
interface PerformanceTiming {
|
||||||
|
readonly attribute unsigned long long navigationStart;
|
||||||
|
/* readonly attribute unsigned long long unloadEventStart;
|
||||||
|
readonly attribute unsigned long long unloadEventEnd;
|
||||||
|
readonly attribute unsigned long long redirectStart;
|
||||||
|
readonly attribute unsigned long long redirectEnd;
|
||||||
|
readonly attribute unsigned long long fetchStart;
|
||||||
|
readonly attribute unsigned long long domainLookupStart;
|
||||||
|
readonly attribute unsigned long long domainLookupEnd;
|
||||||
|
readonly attribute unsigned long long connectStart;
|
||||||
|
readonly attribute unsigned long long connectEnd;
|
||||||
|
readonly attribute unsigned long long secureConnectionStart;
|
||||||
|
readonly attribute unsigned long long requestStart;
|
||||||
|
readonly attribute unsigned long long responseStart;
|
||||||
|
readonly attribute unsigned long long responseEnd;
|
||||||
|
readonly attribute unsigned long long domLoading;
|
||||||
|
readonly attribute unsigned long long domInteractive;
|
||||||
|
readonly attribute unsigned long long domContentLoadedEventStart;
|
||||||
|
readonly attribute unsigned long long domContentLoadedEventEnd;
|
||||||
|
readonly attribute unsigned long long domComplete;
|
||||||
|
readonly attribute unsigned long long loadEventStart;
|
||||||
|
readonly attribute unsigned long long loadEventEnd; */
|
||||||
|
};
|
|
@ -13,7 +13,7 @@
|
||||||
[Unforgeable] readonly attribute Window window;
|
[Unforgeable] readonly attribute Window window;
|
||||||
[Replaceable] readonly attribute Window self;
|
[Replaceable] readonly attribute Window self;
|
||||||
[Unforgeable] readonly attribute Document document;
|
[Unforgeable] readonly attribute Document document;
|
||||||
attribute DOMString name;
|
attribute DOMString name;
|
||||||
/* [PutForwards=href, Unforgeable] */ readonly attribute Location location;
|
/* [PutForwards=href, Unforgeable] */ readonly attribute Location location;
|
||||||
/* readonly attribute History history;
|
/* readonly attribute History history;
|
||||||
[Replaceable] readonly attribute BarProp locationbar;
|
[Replaceable] readonly attribute BarProp locationbar;
|
||||||
|
@ -56,6 +56,11 @@
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html
|
||||||
|
partial interface Window {
|
||||||
|
[Replaceable] readonly attribute Performance performance;
|
||||||
|
};
|
||||||
|
|
||||||
// Not part of any spec
|
// Not part of any spec
|
||||||
partial interface Window {
|
partial interface Window {
|
||||||
// web developer niceties
|
// web developer niceties
|
||||||
|
|
|
@ -13,6 +13,7 @@ use dom::eventtarget::{EventTarget, WindowTypeId};
|
||||||
use dom::console::Console;
|
use dom::console::Console;
|
||||||
use dom::location::Location;
|
use dom::location::Location;
|
||||||
use dom::navigator::Navigator;
|
use dom::navigator::Navigator;
|
||||||
|
use dom::performance::Performance;
|
||||||
|
|
||||||
use layout_interface::{ReflowForDisplay, DocumentDamageLevel};
|
use layout_interface::{ReflowForDisplay, DocumentDamageLevel};
|
||||||
use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan};
|
use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan};
|
||||||
|
@ -32,6 +33,8 @@ use std::hash::{Hash, sip};
|
||||||
use std::io::timer::Timer;
|
use std::io::timer::Timer;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use time;
|
||||||
|
|
||||||
use serialize::{Encoder, Encodable};
|
use serialize::{Encoder, Encodable};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -71,6 +74,9 @@ pub struct Window {
|
||||||
pub compositor: Untraceable<~ScriptListener>,
|
pub compositor: Untraceable<~ScriptListener>,
|
||||||
pub browser_context: Option<BrowserContext>,
|
pub browser_context: Option<BrowserContext>,
|
||||||
pub page: Rc<Page>,
|
pub page: Rc<Page>,
|
||||||
|
pub performance: Option<JS<Performance>>,
|
||||||
|
pub navigationStart: u64,
|
||||||
|
pub navigationStartPrecise: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
@ -131,6 +137,7 @@ pub trait WindowMethods {
|
||||||
fn ClearInterval(&mut self, handle: i32);
|
fn ClearInterval(&mut self, handle: i32);
|
||||||
fn Window(&self) -> Temporary<Window>;
|
fn Window(&self) -> Temporary<Window>;
|
||||||
fn Self(&self) -> Temporary<Window>;
|
fn Self(&self) -> Temporary<Window>;
|
||||||
|
fn Performance(&mut self) -> Temporary<Performance>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> WindowMethods for JSRef<'a, Window> {
|
impl<'a> WindowMethods for JSRef<'a, Window> {
|
||||||
|
@ -248,6 +255,14 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
||||||
fn Self(&self) -> Temporary<Window> {
|
fn Self(&self) -> Temporary<Window> {
|
||||||
self.Window()
|
self.Window()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn Performance(&mut self) -> Temporary<Performance> {
|
||||||
|
if self.performance.is_none() {
|
||||||
|
let performance = Performance::new(self);
|
||||||
|
self.performance.assign(Some(performance));
|
||||||
|
}
|
||||||
|
Temporary::new(self.performance.get_ref().clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reflectable for Window {
|
impl Reflectable for Window {
|
||||||
|
@ -355,6 +370,9 @@ impl Window {
|
||||||
active_timers: ~HashMap::new(),
|
active_timers: ~HashMap::new(),
|
||||||
next_timer_handle: 0,
|
next_timer_handle: 0,
|
||||||
browser_context: None,
|
browser_context: None,
|
||||||
|
performance: None,
|
||||||
|
navigationStart: time::get_time().sec as u64,
|
||||||
|
navigationStartPrecise: time::precise_time_s(),
|
||||||
};
|
};
|
||||||
|
|
||||||
WindowBinding::Wrap(cx, win)
|
WindowBinding::Wrap(cx, win)
|
||||||
|
|
|
@ -154,6 +154,8 @@ pub mod dom {
|
||||||
pub mod node;
|
pub mod node;
|
||||||
pub mod nodelist;
|
pub mod nodelist;
|
||||||
pub mod processinginstruction;
|
pub mod processinginstruction;
|
||||||
|
pub mod performance;
|
||||||
|
pub mod performancetiming;
|
||||||
pub mod uievent;
|
pub mod uievent;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
pub mod validitystate;
|
pub mod validitystate;
|
||||||
|
|
28
src/test/content/test_window_performance.html
Normal file
28
src/test/content/test_window_performance.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
<script src="harness.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
is_not(window.performance, undefined);
|
||||||
|
is_a(window.performance, Performance);
|
||||||
|
|
||||||
|
is_not(window.performance.timing, undefined);
|
||||||
|
is_a(window.performance.timing, PerformanceTiming);
|
||||||
|
|
||||||
|
gt(window.performance.timing.navigationStart, 0);
|
||||||
|
|
||||||
|
var last = window.performance.now();
|
||||||
|
gt(last, 0);
|
||||||
|
|
||||||
|
// Check that window.performance.now() is monotonically increasing
|
||||||
|
for (var i = 0; i < 100; i++) {
|
||||||
|
var next = window.performance.now();
|
||||||
|
gt(next, last);
|
||||||
|
last = next;
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue