Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    max length of eval expression

    using eval function i am executing a lengthy string expression...in fact i am framing some string which contains the commands of creating elements using dom2...this is very very lengthy string

    Is there any limitation for that

    eval(exp);
    here what is max length(limitation) of exp ?

    thanks
    Sudhakar

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    No max length limit except for that placed on string length....
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    But why are you using eval in the first place? Can you post the code? I'm 99.9% sure eval is unnecessary.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're making an XMLHttpRequest and what your server returns is JavaScript, you have to eval() the response to get it to run.

    Which is why I recommend not writing scripts that do this - don't return JS directly from the server, just return the data you need and process it in the original script.

    That may not be the case in this case though - just making the point that this is a situation I'm aware of where it becomes 'necessary' to eval() a large amount of code.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #5
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Even if the server returns javascript, you could still create a script element and append a textnode with the value of the ajax response. I've used this process in the past to remove the need to use eval on long strings, sure the script engine needs to process the remote output, but it's the same as dynamically including another js file.

    Just an idea

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    By the way... I am trying to find a reasonable way to avoid

    eval('2+2')// or any other math oprations or stuff like that

    Any ideeas?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor
    By the way... I am trying to find a reasonable way to avoid

    eval('2+2')// or any other math oprations or stuff like that

    Any ideeas?
    None that are any better, unless you can re-evaulate the format in which you're storing the original equation - why store it as a string, not (say) an array of numbers and operators?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by martin_narg
    Even if the server returns javascript, you could still create a script element and append a textnode with the value of the ajax response. I've used this process in the past
    Does that work x-browser though? I may be out of date, but last time I tried anything like that it was strictly Moz/IE only..?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #9
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by brothercake
    None that are any better, unless you can re-evaulate the format in which you're storing the original equation - why store it as a string, not (say) an array of numbers and operators?
    No, it's too intricate. It looks like this is a case in wich eval() is to be used...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #10
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by Kor
    No, it's too intricate. It looks like this is a case in wich eval() is to be used...
    I wrote an expression parser to do that sort of thing a while ago. I'm not entirely sure if it is significantly faster than running eval() (I needed it to generate an expression tree), but from an expression tree, it's really easy to evaluate the expression numerically.
    http://www.jasonkarldavis.com/math/eval/test.xhtml
    In retrospect, I never fully finished the script. Oh well.

  • #11
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    nice job... I'll study and might continue it, if time...
    In retrospect, I never fully finished the script. Oh well.
    There are fewer stars in the Universe than this kind of projects (started for fun or only to check some theoretical issues) I have started and left them somewhere an 3/4 from the end point...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #12
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    As a genuine Aries as I am, I started with a lot of enthusiasm many interesting projects, (several on the same time) and, when finding the general road to the end, get bored, let the project unfinished and looking for other new interesting affairs... Like the Englishmen say about Bridge. "It's a game where the Lords do the bid, while the Jacks do the rest of the play" (if you know Bridge, you will know what that means) I do need some Jacks from time to time...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #13
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Kor: Have you tried messing around with regexes? If the expressions all take the look of (loperand operator roperand) you could create a regex that captures the three subpatterns. Then use a String.prototype.replace call with a callback function looking like this:
    Code:
    function(m,lod,op,rod){
        return oOps[op](lod,rod);
    }
    What is oOps? It's an object looking like this:
    Code:
    var
        oOps={
            '+':function(lod,rod){return (Number(lod)+Number(rod));},
            '-':function(lod,rod){return (Number(lod)-Number(rod));},
            '*':function(lod,rod){return (Number(lod)*Number(rod));},
            '/':function(lod,rod){return (Number(lod)/Number(rod));},
            '%':function(lod,rod){return (Number(lod)%Number(rod));},
            '^':function(lod,rod){return Math.pow(Number(lod),Number(rod));}};
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #14
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    hm... quite interesting approach. Never thought about that...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #15
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Except that for a long expression I must return the result and recall the function with the next term and so on... If an intricate and long math expresion I have to do that as linear as possible. Not impossible, as long as anyway I am used to linearize everything .. Tx, interesting.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •