
committed by
Kara Erickson

parent
7b3bcc23af
commit
5eb7426216
57
packages/zone.js/test/performance/promise.js
Normal file
57
packages/zone.js/test/performance/promise.js
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
(function(_global) {
|
||||
var mark = _global['__zone_symbol__mark'];
|
||||
var measure = _global['__zone_symbol__measure'];
|
||||
var testRunner = _global['__zone_symbol__testRunner'];
|
||||
var zone = _global['__zone_symbol__callbackZone'];
|
||||
var nativePromise = _global['__zone_symbol__Promise'];
|
||||
var resolved = Promise.resolve(1);
|
||||
var nativeResolved = nativePromise.resolve(1);
|
||||
var testTarget = {
|
||||
title: 'Promise',
|
||||
times: 10,
|
||||
before: function() {
|
||||
_global['__zone_symbol__callbackContext'].measureName = 'Promise_callback';
|
||||
_global['__zone_symbol__callbackContext'].type = 'microTask';
|
||||
_global['__zone_symbol__callbackContext'].source = 'Promise.then';
|
||||
},
|
||||
apis: [
|
||||
{
|
||||
supportClear: false,
|
||||
isAsync: true,
|
||||
method: 'Promise',
|
||||
nativeMethod: 'native_Promise',
|
||||
run: function() { return resolved.then(function() {}); },
|
||||
nativeRun: function() { return nativeResolved['__zone_symbol__then'](function() {}); },
|
||||
},
|
||||
{
|
||||
isCallback: true,
|
||||
isAsync: true,
|
||||
supportClear: false,
|
||||
method: 'Promise_callback',
|
||||
nativeMethod: 'native_Promise_callback',
|
||||
run: function() {
|
||||
return zone.run(function() {
|
||||
return Promise.resolve(1).then(function(v) { return v; });
|
||||
});
|
||||
},
|
||||
nativeRun: function() {
|
||||
var func = function() {};
|
||||
return _global['__zone_symbol__Promise'].resolve(1)['__zone_symbol__then'](function() {
|
||||
mark('native_Promise_callback');
|
||||
var result = func.apply(this, arguments);
|
||||
measure('native_Promise_callback', 'native_Promise_callback');
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
],
|
||||
};
|
||||
return testRunner(testTarget);
|
||||
}(typeof window === 'undefined' ? global : window));
|
Reference in New Issue
Block a user