File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change 1
- ( function profileMethodCall ( ) {
2
- var object = window . primesApp ;
3
- console . assert ( object , 'cannot find object to profile' ) ;
1
+ ( function profileMethodCall ( root ) {
2
+ 'use strict' ;
4
3
4
+ var name = 'primesApp' ;
5
5
var methodName = 'findFirstPrimes' ;
6
+
7
+ var object = root [ name ] ;
8
+ console . assert ( object , 'cannot find object ' + name + ' to profile' ) ;
9
+
6
10
var originalMethod = object [ methodName ] ;
7
11
console . assert ( typeof originalMethod === 'function' , 'cannot find method ' + methodName ) ;
12
+
8
13
object [ methodName ] = function ( ) {
9
14
console . profile ( methodName ) ;
10
15
originalMethod . call ( object ) ;
11
16
console . profileEnd ( methodName ) ;
12
- // restore original methodName
17
+
13
18
object [ methodName ] = originalMethod ;
19
+ console . log ( 'restored the original method call' ) ;
14
20
} ;
15
- } ( ) ) ;
21
+ console . log ( 'wrapped' , name + '.' + methodName + ' in profiling calls' ) ;
22
+ } ( this ) ) ;
Original file line number Diff line number Diff line change 1
- ( function timeMethodCall ( ) {
2
- var object = window . primesApp ;
3
- console . assert ( object , 'cannot find object to profile' ) ;
1
+ ( function timeMethodCall ( root ) {
2
+ 'use strict' ;
4
3
4
+ var name = 'primesApp' ;
5
5
var methodName = 'findFirstPrimes' ;
6
+
7
+ var object = root [ name ] ;
8
+ console . assert ( object , 'cannot find object ' + name + ' to profile' ) ;
9
+
6
10
var originalMethod = object [ methodName ] ;
7
11
console . assert ( typeof originalMethod === 'function' , 'cannot find method ' + methodName ) ;
12
+
8
13
object [ methodName ] = function ( ) {
9
14
console . time ( methodName ) ;
10
15
originalMethod . call ( object ) ;
11
16
console . timeEnd ( methodName ) ;
12
- // restore original methodName
17
+
13
18
object [ methodName ] = originalMethod ;
19
+ console . log ( 'restored the original method call' ) ;
14
20
} ;
15
- } ( ) ) ;
21
+ console . log ( 'wrapped' , name + '.' + methodName + ' in timing calls' ) ;
22
+ } ( this ) ) ;
You can’t perform that action at this time.
0 commit comments