Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript eval limits

Tags:

javascript

Is there a limit to javascript's eval, like in lenght?

I'm trying to build an app where you can store JS code in the DB, which you can later load and eval in order to execute it, but i'm reaching a limit. First of all, the code has to all be in one line. Any multiline statements are not executed. Next, i'm reaching a limit in length (i guess). If i execute the code manually, it works, but put that same code in the db, load it via ajax, and try to execute it, and it fails.

Any ideas why?

like image 614
R0b0tn1k Avatar asked Apr 22 '10 18:04

R0b0tn1k


1 Answers

You don't need to use eval and its not exactly a good thing to use. You could just have it print out to the page and it will run.

Here is the accepted answer on why you should not use eval:

  1. Improper use of eval opens up your code for injection attacks
  2. Debugging can be more challenging (no line numbers, etc.)
  3. eval'd code executes more slowly (no opportunity to compile/cache eval'd code)
like image 148
Jonathan Czitkovics Avatar answered Sep 21 '22 02:09

Jonathan Czitkovics