2011-11-10 10:12:41 -06:00
|
|
|
require 'v8'
|
|
|
|
|
2012-05-08 15:11:50 -05:00
|
|
|
def run_v8_gc
|
2012-05-17 11:15:30 -05:00
|
|
|
while !V8::C::V8::IdleNotification() do
|
|
|
|
end
|
2012-05-08 15:11:50 -05:00
|
|
|
end
|
|
|
|
|
2011-11-10 10:12:41 -06:00
|
|
|
def rputs(msg)
|
|
|
|
puts "<pre>#{ERB::Util.h(msg)}</pre>"
|
|
|
|
$stdout.flush
|
|
|
|
end
|
2012-06-05 08:00:04 -05:00
|
|
|
|
|
|
|
module ExplicitScoper;end
|
|
|
|
module Autoscope
|
|
|
|
def instance_eval(*args, &block)
|
2012-06-06 03:10:20 -05:00
|
|
|
return super unless low_level_c_spec? && !explicitly_defines_scope?
|
2012-06-05 08:00:04 -05:00
|
|
|
V8::C::Locker() do
|
|
|
|
V8::C::HandleScope() do
|
|
|
|
@cxt = V8::C::Context::New()
|
|
|
|
begin
|
|
|
|
@cxt.Enter()
|
|
|
|
super(*args, &block)
|
|
|
|
ensure
|
|
|
|
@cxt.Exit()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-06 03:10:20 -05:00
|
|
|
|
|
|
|
def low_level_c_spec?
|
2012-06-06 03:55:10 -05:00
|
|
|
return false unless described_class
|
2012-06-08 08:32:30 -05:00
|
|
|
described_class.name =~ /^V8::C::/
|
2012-06-06 03:10:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def explicitly_defines_scope?
|
|
|
|
is_a?(ExplicitScoper)
|
|
|
|
end
|
2012-06-05 08:00:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |c|
|
|
|
|
c.before(:each) do
|
2012-06-06 03:10:20 -05:00
|
|
|
extend Autoscope
|
2012-06-05 08:00:04 -05:00
|
|
|
end
|
|
|
|
end
|