callsite
callsite copied to clipboard
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
When in strict mode (use strict at the top of the file) arguments.callee throws an error.
This came up for me because Babel's require-hook was transpiling this file - yes i know it probably shouldn't.
A nasty bug though because it occurs while the stack trace has been replaced, which makes it hard to find, printing an obscure message to the console.
The workarounds:
- configure Babel to blacklist
useStrictto avoid adding strict to the top of the file. - configure Babel to ignore
callsite.js.
Regardless I propose the following change to make sure the error gets thrown if for some reason use strict is placed at the top of this file:
module.exports = function(){
var orig = Error.prepareStackTrace;
var callee = arguments.callee; // <- access arguments.callee here which will throw a readable error if use strict is set.
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error;
Error.captureStackTrace(err, callee); // <- reference callee here.
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
};
this came up for me in trying to use node's --use_strict flag, long story short--you can't if you have any (direct or indirect) dependency on this project.