2015-03-20 20:47:57 +00:00
|
|
|
require 'v8/init'
|
|
|
|
|
|
|
|
module V8ContextHelpers
|
|
|
|
module GroupMethods
|
|
|
|
def requires_v8_context
|
|
|
|
around(:each) do |example|
|
|
|
|
bootstrap_v8_context(&example)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bootstrap_v8_context
|
2015-04-04 14:03:06 +00:00
|
|
|
@isolate = V8::C::Isolate.New
|
2015-03-21 20:27:06 +00:00
|
|
|
|
2015-04-04 14:03:06 +00:00
|
|
|
V8::C::HandleScope(@isolate) do
|
2015-04-04 18:23:23 +00:00
|
|
|
@ctx = V8::C::Context::New(@isolate)
|
2015-04-04 14:03:06 +00:00
|
|
|
begin
|
2015-04-04 18:23:23 +00:00
|
|
|
@ctx.Enter
|
2015-04-04 14:03:06 +00:00
|
|
|
yield
|
|
|
|
ensure
|
2015-04-04 18:23:23 +00:00
|
|
|
@ctx.Exit
|
2015-03-21 20:27:06 +00:00
|
|
|
end
|
2015-03-20 20:47:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |c|
|
|
|
|
c.include V8ContextHelpers
|
|
|
|
c.extend V8ContextHelpers::GroupMethods
|
|
|
|
end
|