forked from rubyjs/therubyracer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
45 lines (39 loc) · 829 Bytes
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'v8'
def run_v8_gc
V8::C::V8::LowMemoryNotification()
while !V8::C::V8::IdleNotification() do
end
end
def rputs(msg)
puts "<pre>#{ERB::Util.h(msg)}</pre>"
$stdout.flush
end
module ExplicitScoper;end
module Autoscope
def instance_eval(*args, &block)
return super unless low_level_c_spec? && !explicitly_defines_scope?
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
def low_level_c_spec?
return false unless described_class
described_class.name =~ /^V8::C::/
end
def explicitly_defines_scope?
is_a?(ExplicitScoper)
end
end
RSpec.configure do |c|
c.before(:each) do
extend Autoscope
end
end