Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Performance object to Window and implement Performance::Now()
- Loading branch information
Showing
9 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 32 additions & 0 deletions
32
src/components/script/dom/webidls/PerformanceTiming.webidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; */ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
fb0c433
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from jdm
at https://github.com/gsingh93/servo/commit/fb0c433b701f19c52cafabc45f9469cbb9706de9
fb0c433
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging gsingh93/servo/master = fb0c433 into auto
fb0c433
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gsingh93/servo/master = fb0c433 merged ok, testing candidate = 86a6de2
fb0c433
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://servo-buildbot.pub.build.mozilla.org/builders/linux/builds/1372
success: http://servo-buildbot.pub.build.mozilla.org/builders/mac/builds/1326
fb0c433
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 86a6de2