4 ms·
> Jump the the function/method definition for scripting languages, define a function as concatenated string in eval(), how could you find the function definiti
by est 15y ago
> Jump the the function/method definition
for scripting languages, define a function as concatenated string in eval(), how could you find the function definition, without actually run the script for once?
Even if you run the script once, what if there is a delete_file() function you accidently called?
So do we need to implement a sandboxed VM in order to find definition, theoretical perfectly speaking?
- tsandall 15y agosure, theoretically speaking you can't figure out everything until runtime, however even with 'scripting language' code you can still get quite far with basic static analysis.
- johns 15y agoOr just don't offer click navigation on functions defined in eval(). Acceptable trade off.
- rorrr 15y agoThat's such an edge case. I've never seen anybody defining functions in evals, especially as concatenated strings.
- agento 15y agoMaybe you should take a look at the Rails sourcecode.
- FooBarWidget 15y agoRails only does that to optimize certain function calls. eval() is used as a method to compile/inline certain functions. Most code in Rails does not use eval.
- drothlis 15y agohttps://github.com/rails/rails/blob/2-3-stable/actionpack/lib/action_controller/request.rb#L11 https://github.com/rails/rails/blob/2-3-stable/actionpack/li... Try getting your editor to find that definition of method "accept_language" or "cache_control". :-)
- TylerE 15y agoI've done it. Use case involves a class wrapping python's xml-rpc stuff to talk to Drupal. Drupal's xml-rpc interface is not the most pleasant thing to work with, as you have to pass in a session id and auth token on every request, and then all the "actual" parameters go in as an array. My wrapper class would query the remote interface for available methods, and then dynamically generate, via eval, a function object that used a closure to store the sess/auth tokens, and that took a variable number of arguments to pass as the 3rd array argument to the function. The eval'd function object was then bound as a method to the connection object. It also did a bit more magic, such as on error logging the arguments to a file. ALl in all it made writing web-service clients a lot more pleasant.