rubyjs / therubyracer

Embed the V8 Javascript Interpreter into Ruby
1.67k stars 190 forks source link

Embed lambdas and procs into V8::Context #380

Closed cowboyd closed 8 years ago

cowboyd commented 8 years ago

This adds the ability embed basic Ruby code blocks into a javascript context and invoke it.

cxt = V8::Context.new cxt['twice'] = lambda {|str| "#{str}#{str}"} cxt.eval('twice("hi")') #=> "hihi"

Note that error handling is not accounted for yet. If an exception happens inside the called proc, it will cause terrible, awful things to happen because portions of the C++ stack will not be unwound leaving the Isolate in an indeterminate state.

They are very useful for testing though.