1
0
Fork 0
mirror of https://github.com/rubyjs/mini_racer synced 2023-03-27 23:21:28 -04:00

Implement #load (initial trivial implementation)

This commit is contained in:
Sam Saffron 2016-05-17 10:47:21 +10:00
parent 1adb2f9c6d
commit d6c173f533
3 changed files with 14 additions and 0 deletions

View file

@ -62,7 +62,11 @@ module MiniRacer
if options
@timeout = options[:timeout]
end
end
def load(filename)
# TODO do this native cause no need to allocate VALUE here
eval(File.read(filename))
end
def eval(str)

1
test/file.js Normal file
View file

@ -0,0 +1 @@
var hello = "world";

View file

@ -139,4 +139,13 @@ raise FooError, "I like foos"
end
end
def test_load
context = MiniRacer::Context.new
context.load(File.dirname(__FILE__) + "/file.js")
assert_equal "world", context.eval("hello")
assert_raises do
context.load(File.dirname(__FILE__) + "/missing.js")
end
end
end