UNPKG

732 BJavaScriptView Raw
1function wrap (ctx) {
2 var map = Array.prototype.map
3
4 ctx.usedMap = false
5
6 Array.prototype.map = function () {
7
8 // $captureStack is a utility to capture a stacktrace array
9 var stack = ctx.$captureStack(Array.prototype.map)
10
11 // inspect the first callsite of the stacktrace and see if the
12 // filename matches the mainProgram we're running, if so, then
13 // the user has used Array#map!
14 // the substring() is necessary as the user doesn't have to provide
15 // a .js extension to make it work
16
17 if (stack[0].getFileName().substring(0, ctx.mainProgram.length) == ctx.mainProgram)
18 ctx.usedMap = true
19
20 // call the real Array#map
21
22 return map.apply(this, arguments)
23 }
24}
25
26
27module.exports = wrap
\No newline at end of file