fix(test): AngularProfiler should check before using modern APIs

This commit is contained in:
Marc Laval
2015-09-09 12:23:04 +02:00
parent 55290b9b21
commit abc4ef31e2
6 changed files with 41 additions and 7 deletions

View File

@ -474,6 +474,10 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
cancelAnimationFrame(id) {
window.cancelAnimationFrame(id);
}
num performanceNow() {
return window.performance.now();
}
}
var baseElement = null;

View File

@ -1,5 +1,11 @@
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 {GenericBrowserDomAdapter} from './generic_browser_adapter';
@ -322,6 +328,15 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
setGlobalVar(path: string, value: any) { setValueOnPath(global, path, value); }
requestAnimationFrame(callback): number { return window.requestAnimationFrame(callback); }
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());
}
}
}

View File

@ -138,4 +138,5 @@ export class DomAdapter {
setGlobalVar(name: string, value: any) { throw _abstract(); }
requestAnimationFrame(callback): number { throw _abstract(); }
cancelAnimationFrame(id) { throw _abstract(); }
performanceNow(): number { throw _abstract(); }
}

View File

@ -431,4 +431,8 @@ class Html5LibDomAdapter implements DomAdapter {
cancelAnimationFrame(id) {
throw 'not implemented';
}
performanceNow() {
throw 'not implemented';
}
}

View File

@ -9,7 +9,13 @@ var url = require('url');
import {MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
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 {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); }
requestAnimationFrame(callback): number { return setTimeout(callback, 0); }
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