tario / evalhook Goto Github PK
View Code? Open in Web Editor NEWAlternate eval which hook all methods executed in the evaluated code
License: GNU General Public License v3.0
Alternate eval which hook all methods executed in the evaluated code
License: GNU General Public License v3.0
require "evalhook"
include EvalHook
to_run = <<-END
def puts_one_two_three()
print "one two\\n"
print "three\\n "
end
END
hh=HookHandler.new
hh.evalhook(to_run, binding)
puts_one_two_three
Expected: one two three
Got: one two
i.e:
class MyHook < HookHandler
def handle_xstr( sysstr )
end
end
evalhook/lib/evalhook/tree_processor.rb
Line 192 in 5664570
seems we are missing a hook_handler_reference here. Constant at global namespace couldn't be handled at all.
While I was working around #5 , I used a chained invocation to get one logical line. The workaround was broken by the fix for #5.
The following generates a syntax error:
require "shikashi"
class X
def foo
print "X#foo\n"
return self
end
def bar
print "X#bar\n"
return self
end
end
include Shikashi
to_run = <<-END
# Following 3 lines should do the same thing twice
X.new.foo().bar()
X.new.foo()
.bar()
END
s = Sandbox.new
priv = Privileges.new
priv.allow_method :print
priv.allow_const_read("X") # allow the access of X constant
priv.object(X).allow(:new)
priv.instances_of(X).allow_all
puts "Running block: #{to_run}"
s.run(priv, to_run, :no_base_namespace => true)
This is a minor bug for me, but chaining calls is useful for a DSL.
Code packet will be the new feature to avoid "compile" the same source code many times. Example:
include Shikashi
privileges = Privileges.new
privileges.allow_const_read "Kernel"
privileges.object(Kernel).allow_all
privileges.instances_of(Kernel).allow_all
Sandbox.new.run(privileges, "Kernel.sprintf('%d', 123)")
I been having problems with ArgumentErrors when invoking methods with multiple arguments. They above gives me: ArgumentError: too few arguments
In a different scenario, I created they above for pure testing, im calling this method in class Chat
def self.send_property user_name, name, value
like this
Chat.send_property "a","b","c"
and I am seeing this
ArgumentError: wrong number of arguments (1 for 3)
but when I call it like this
Chat.send_property "a","b"
I am seeing
ArgumentError: wrong number of arguments (2 for 3)
If I call the methods outside of the Sandbox all is fine.
Does this ring a bell? I am using 'ruby-1.9.3-p194'
i.e
class MyHook < HookHandler
def handle_colon3( inner )
...
end
end
require "evalhook"
ctx = EvalHook::HookHandler.new
p ctx.evalhook("(1..10).map{|to_s| 'a'.to_s}")
Returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Expected: ["a", "a", "a", "a", "a", "a", "a", "a", "a", "a"]
Copied from tario/shikashi#24:
"
Hello.
I am trying to eval code in shikashi sandbox in some long running process (single threaded). For each eval there is own sandbox + privileges objects. And according to ObjectSpace, none of these sandbox objects are cleared by garbage collector. There is also the same number of EvalhookHandler objects always exists.
Maybe I am just missed some kind of termination for sandbox?
"
RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.
via e.g.
spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']
Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.
There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.
I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!
Appendix:
If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies
p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.
I updated to the new gem version (with related dependencies) today.
The following code no longer works:
require "rubygems"
require "shikashi"
include Shikashi
module Sandboxer
extend self
end
sandbox = Sandbox.new
priv = Privileges.new
priv.allow_method :puts
priv.instances_of(Sandboxer).allow_all
sandbox.run(priv, '
def go()
puts "Printing a line!"
puts "Printing a line!"
end', :base_namespace => Sandboxer)
Sandboxer.method("go").call()
The output only shows "Printing a line!" once (note that the go method makes 2 calls to puts.)
However, using the old dependencies,
"partialruby", '= 0.2.3'
"ruby_parser", '= 2.3.1'
"evalhook", '= 0.5.5'
The output shows:
Printing a line!
Printing a line!
as expected.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.