fix(test): AngularProfiler should check before using modern APIs
This commit is contained in:
parent
55290b9b21
commit
abc4ef31e2
|
@ -474,6 +474,10 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||||
cancelAnimationFrame(id) {
|
cancelAnimationFrame(id) {
|
||||||
window.cancelAnimationFrame(id);
|
window.cancelAnimationFrame(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
num performanceNow() {
|
||||||
|
return window.performance.now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseElement = null;
|
var baseElement = null;
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
|
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
|
||||||
import {isBlank, isPresent, global, setValueOnPath} from 'angular2/src/core/facade/lang';
|
import {
|
||||||
|
isBlank,
|
||||||
|
isPresent,
|
||||||
|
global,
|
||||||
|
setValueOnPath,
|
||||||
|
DateWrapper
|
||||||
|
} from 'angular2/src/core/facade/lang';
|
||||||
import {setRootDomAdapter} from './dom_adapter';
|
import {setRootDomAdapter} from './dom_adapter';
|
||||||
import {GenericBrowserDomAdapter} from './generic_browser_adapter';
|
import {GenericBrowserDomAdapter} from './generic_browser_adapter';
|
||||||
|
|
||||||
|
@ -322,6 +328,15 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||||
setGlobalVar(path: string, value: any) { setValueOnPath(global, path, value); }
|
setGlobalVar(path: string, value: any) { setValueOnPath(global, path, value); }
|
||||||
requestAnimationFrame(callback): number { return window.requestAnimationFrame(callback); }
|
requestAnimationFrame(callback): number { return window.requestAnimationFrame(callback); }
|
||||||
cancelAnimationFrame(id: number) { window.cancelAnimationFrame(id); }
|
cancelAnimationFrame(id: number) { window.cancelAnimationFrame(id); }
|
||||||
|
performanceNow(): number {
|
||||||
|
// performance.now() is not available in all browsers, see
|
||||||
|
// http://caniuse.com/#search=performance.now
|
||||||
|
if (isPresent(window.performance) && isPresent(window.performance.now)) {
|
||||||
|
return window.performance.now();
|
||||||
|
} else {
|
||||||
|
return DateWrapper.toMillis(DateWrapper.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -138,4 +138,5 @@ export class DomAdapter {
|
||||||
setGlobalVar(name: string, value: any) { throw _abstract(); }
|
setGlobalVar(name: string, value: any) { throw _abstract(); }
|
||||||
requestAnimationFrame(callback): number { throw _abstract(); }
|
requestAnimationFrame(callback): number { throw _abstract(); }
|
||||||
cancelAnimationFrame(id) { throw _abstract(); }
|
cancelAnimationFrame(id) { throw _abstract(); }
|
||||||
|
performanceNow(): number { throw _abstract(); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,4 +431,8 @@ class Html5LibDomAdapter implements DomAdapter {
|
||||||
cancelAnimationFrame(id) {
|
cancelAnimationFrame(id) {
|
||||||
throw 'not implemented';
|
throw 'not implemented';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
performanceNow() {
|
||||||
|
throw 'not implemented';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,13 @@ var url = require('url');
|
||||||
|
|
||||||
import {MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
import {MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
||||||
import {DomAdapter, setRootDomAdapter} from './dom_adapter';
|
import {DomAdapter, setRootDomAdapter} from './dom_adapter';
|
||||||
import {isPresent, isBlank, global, setValueOnPath} from 'angular2/src/core/facade/lang';
|
import {
|
||||||
|
isPresent,
|
||||||
|
isBlank,
|
||||||
|
global,
|
||||||
|
setValueOnPath,
|
||||||
|
DateWrapper
|
||||||
|
} from 'angular2/src/core/facade/lang';
|
||||||
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
||||||
import {SelectorMatcher, CssSelector} from 'angular2/src/core/render/dom/compiler/selector';
|
import {SelectorMatcher, CssSelector} from 'angular2/src/core/render/dom/compiler/selector';
|
||||||
|
|
||||||
|
@ -545,6 +551,7 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
setGlobalVar(path: string, value: any) { setValueOnPath(global, path, value); }
|
setGlobalVar(path: string, value: any) { setValueOnPath(global, path, value); }
|
||||||
requestAnimationFrame(callback): number { return setTimeout(callback, 0); }
|
requestAnimationFrame(callback): number { return setTimeout(callback, 0); }
|
||||||
cancelAnimationFrame(id: number) { clearTimeout(id); }
|
cancelAnimationFrame(id: number) { clearTimeout(id); }
|
||||||
|
performanceNow(): number { return DateWrapper.toMillis(DateWrapper.now()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: build a proper list, this one is all the keys of a HTMLInputElement
|
// TODO: build a proper list, this one is all the keys of a HTMLInputElement
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {ApplicationRef, LifeCycle} from 'angular2/angular2';
|
import {ApplicationRef, LifeCycle} from 'angular2/angular2';
|
||||||
import {isPresent, NumberWrapper} from 'angular2/src/core/facade/lang';
|
import {isPresent, NumberWrapper} from 'angular2/src/core/facade/lang';
|
||||||
import {performance, window} from 'angular2/src/core/facade/browser';
|
import {performance, window} from 'angular2/src/core/facade/browser';
|
||||||
|
import {DOM} from 'angular2/src/core/dom/dom_adapter';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point for all Angular debug tools. This object corresponds to the `ng`
|
* Entry point for all Angular debug tools. This object corresponds to the `ng`
|
||||||
|
@ -40,17 +41,19 @@ export class AngularProfiler {
|
||||||
timeChangeDetection(config: any) {
|
timeChangeDetection(config: any) {
|
||||||
var record = isPresent(config) && config['record'];
|
var record = isPresent(config) && config['record'];
|
||||||
var profileName = 'Change Detection';
|
var profileName = 'Change Detection';
|
||||||
if (record) {
|
// Profiler is not available in Android browsers, nor in IE 9 without dev tools opened
|
||||||
|
var isProfilerAvailable = isPresent(window.console.profile);
|
||||||
|
if (record && isProfilerAvailable) {
|
||||||
window.console.profile(profileName);
|
window.console.profile(profileName);
|
||||||
}
|
}
|
||||||
var start = window.performance.now();
|
var start = DOM.performanceNow();
|
||||||
var numTicks = 0;
|
var numTicks = 0;
|
||||||
while (numTicks < 5 || (window.performance.now() - start) < 500) {
|
while (numTicks < 5 || (DOM.performanceNow() - start) < 500) {
|
||||||
this.lifeCycle.tick();
|
this.lifeCycle.tick();
|
||||||
numTicks++;
|
numTicks++;
|
||||||
}
|
}
|
||||||
var end = window.performance.now();
|
var end = DOM.performanceNow();
|
||||||
if (record) {
|
if (record && isProfilerAvailable) {
|
||||||
// need to cast to <any> because type checker thinks there's no argument
|
// need to cast to <any> because type checker thinks there's no argument
|
||||||
// while in fact there is:
|
// while in fact there is:
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue