@@ -29,6 +29,7 @@ this callback, logging callback calls.
29
29
This task can be divided into a few steps.
30
30
2 . Remove ` setTimeout ` example from ` application.js ` and replace it with the
31
31
following code:
32
+
32
33
``` JavaScript
33
34
var fileName = ' ./README.md' ;
34
35
console .log (' Application going to read ' + fileName);
@@ -43,6 +44,7 @@ length.
43
44
3 . Next step is preparing function ` cloneInterface(interfaceName) ` for cloning
44
45
all keys from given library into new interface. So we can pass its result
45
46
(cloned ` fs ` ) to sandbox instead of ` fs ` . Clonning function example:
47
+
46
48
``` JavaScript
47
49
function cloneInterface (anInterface ) {
48
50
var clone = {};
@@ -58,6 +60,7 @@ closure function. Closure `wrapper` is a newly created function with the help
58
60
of functional inheritance, so it will see ` fnName ` , ` fn ` in its context. Thus
59
61
we can pass all arguments from wrapper into original function as you see in
60
62
example:
63
+
61
64
``` JavaScript
62
65
function wrapFunction (fnName , fn ) {
63
66
return function wrapper () {
@@ -69,6 +72,7 @@ example:
69
72
}
70
73
}
71
74
```
75
+
72
76
5 . Now should detect do we have ` callback ` argument as a last argument of
73
77
function call, we can do that by ` typeof() ` comparing to ` function ` . If we have
74
78
` callback ` , we need to wrap it too, so pass ours function instead of ` callback `
@@ -79,14 +83,14 @@ try to run wrapped code.
79
83
we will model a real application random file system access. Then we can collect
80
84
some statistics from ` framework.js ` and print it every 30 seconds. For example,
81
85
you can collect following parameters:
82
- - number of function calls,
83
- - number of callbacks,
84
- - average function completion speed,
85
- - average return rate of callbacks,
86
- - total amount of data read from the disk,
87
- - total amount of recorded data,
88
- - average read and write speed,
89
- etc.
86
+ - number of function calls,
87
+ - number of callbacks,
88
+ - average function completion speed,
89
+ - average return rate of callbacks,
90
+ - total amount of data read from the disk,
91
+ - total amount of recorded data,
92
+ - average read and write speed,
93
+ etc.
90
94
91
95
Save your results to github, we will need it in next labs, for example we can
92
96
transfer overriden wrapped calls (fs operations) to another process and another
0 commit comments