0

Is there an API or package (built-in or third-party) which can take a string of javascript code (specifically a function for my case), profile the same and tell if there is any asynchronous operation or a callback in that method?

For example, if there is a function

function f1()
{
  console.log(arguments);
}

If I do f1.toString().split("\n").join( "\\n" ), I would get a string

"function f1()\n    {\n      console.log(arguments)\n    }"

I want to be able to profile the code and see if there was any asynchronous operation in this string. Is it possible?

Thanks.

gurvinder372
  • 66,980
  • 10
  • 72
  • 94
  • It's not really possible without actually parsing the Javascript with a real parser and then following the chain of all function calls that are made. You could, of course, look for certain specific things that might be in the function (async function names or async calling conventions), but even then you couldn't tell if it calls a function that is itself calling something async. Perhaps if you explain the real problem you're trying to solve, we might be able to offer better solutions. – jfriend00 Sep 15 '16 at 06:38
  • @jfriend00 I want to create an API which will take a string as an input and tell if this has any asynchronous operation. Unfortunately, this is the problem I am trying to solve ;( – gurvinder372 Sep 15 '16 at 06:42
  • Can't really reliably do it. You can likely detect some obvious async calling patterns or known async functions, but there are lots of ways you could not be able to detect things by just examining a string of code. – jfriend00 Sep 15 '16 at 06:47

0 Answers0