Does there exist a string s such that
(new Function(s))();
and
eval(s);
behave differently? I’m trying to “detect” how a string is being evaluated.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Check for the
argumentsobject. If it exists, you’re in the function. If it doesn’t it has beenevaled.Note that you’ll have to put the check for
argumentsin atry...catchblock like this:Demo
Solution to
nnnnnn‘s concern. For this, I’ve edited the eval function itself: