update readme
This commit is contained in:
parent
7327c81155
commit
25c58e31a3
59
README.md
59
README.md
|
@ -1,9 +1,66 @@
|
|||
# MiniRacer
|
||||
|
||||
Minimal embedded V8 for Ruby
|
||||
Minimal, modern embedded V8 for Ruby.
|
||||
|
||||
MiniRacer provides a minimal complete bridge to the V8 JavaScript engine from Ruby.
|
||||
|
||||
It was created as an alternative to the excellent [therubyracer](https://github.com/cowboyd/therubyracer). Unlike therubyracer, mini_racer only implements a minimal (yet complete) bridge. This reduces the surface area making upgrading v8 much simpler and exahustive testing simpler.
|
||||
|
||||
## Features
|
||||
|
||||
### Simple eval for JavaScript
|
||||
|
||||
You can simply eval one or many JavaScript snippets in a shared context
|
||||
|
||||
```ruby
|
||||
context = MiniRacer::Context.new
|
||||
context.eval 'var adder = (a,b)=>a+b;'
|
||||
puts context.eval 'adder(20,22)'
|
||||
# => 42
|
||||
```
|
||||
|
||||
### Attach global Ruby function to your JavaScript context
|
||||
|
||||
You can attach one or many ruby proc that can be accessed via JavaScript
|
||||
|
||||
```ruby
|
||||
context = MiniRacer::Context.new
|
||||
context.attach("adder", proc{|a,b| a+b})
|
||||
puts context.eval 'adder(20,22)'
|
||||
# => 42
|
||||
```
|
||||
|
||||
### GIL free JavaScript execution
|
||||
|
||||
The Ruby Global interpreter lock is released when scripts are executing
|
||||
|
||||
```ruby
|
||||
context = MiniRacer::Context.new
|
||||
Thread.new do
|
||||
sleep 1
|
||||
context.stop
|
||||
end
|
||||
context.eval 'while(true){}'
|
||||
# => exception is raised
|
||||
```
|
||||
|
||||
This allows you to execute multiple scripts in parallel.
|
||||
|
||||
### Timeout support
|
||||
|
||||
Contexts can specify a default timeout for scripts
|
||||
|
||||
```ruby
|
||||
# times out after 1 second (1000 ms)
|
||||
context = MiniRacer::Context.new(timeout: 1000)
|
||||
context.eval 'while(true){}'
|
||||
# => exception is raised
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
**Currently gem is in alpha development and can not be installed until libv8 is released**
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
|
|
|
@ -70,7 +70,7 @@ class MiniRacerTest < Minitest::Test
|
|||
|
||||
def test_es6_arrow_functions
|
||||
context = MiniRacer::Context.new
|
||||
assert_equal 42, context.eval('a=()=>42; a();')
|
||||
assert_equal 42, context.eval('adder=(x,y)=>x+y; adder(21,21);')
|
||||
end
|
||||
|
||||
def test_attached_exceptions
|
||||
|
|
Loading…
Reference in New Issue