@@ -45,6 +45,41 @@ var assertFuzzyEquals = function(actual, expected, msg){
45
45
```
46
46
47
47
48
+ ### Checking user code
49
+
50
+ [ @slothpie ] [ gh-slothpie ] provided the following code to check the user's code
51
+ for forbidden functions:
52
+
53
+ [ gh-slothpie ] : https://github.com/slothpie
54
+
55
+ ``` javascript
56
+ Test .describe (" Reinforcement Test Cases:" , function () {
57
+ // get the code as text, (this also grabs test case code)
58
+ var dump = arguments .callee .caller .caller .caller .toString ();
59
+
60
+ // The length of our test case code.
61
+ const FIXED = arguments .callee .caller .caller .toString ().length ;
62
+
63
+ // Slice out our test case code so we just have users
64
+ const USER_CODE = dump .slice (0 ,dump .length - FIXED );
65
+
66
+ check_user_code_for_stuff (USER_CODE );
67
+ });
68
+ ```
69
+
70
+ However, there are two things you have to keep in mind:
71
+
72
+ 1 . ` USER_CODE ` does not contain actual user code, but the one returned by
73
+ babel.js. You never get access to the actual source code (until node
74
+ supports ES6 and gets updated on Codwars).
75
+ 2 . ` arguments.callee ` and ` arguments.caller ` only work if you don't run your
76
+ script in strict mode. A stray ` "use strict"; ` in the user's code will
77
+ lead to an error, even if the code is otherwise OK.
78
+
79
+ Other than that, it's an easy way to check whether the user uses any loops
80
+ or similar.
81
+
82
+
48
83
### Random tests
49
84
50
85
In [ August 2015] [ gitter-chat-quickcheck ] the [ ` node-quickeck ` ] [ node-quickeck ]
0 commit comments