Ruby Crashes when Context set using :with => self (OSX rbenv ruby 1.9.3)

70 views
Skip to first unread message

rainkinz

unread,
Feb 16, 2013, 11:20:39 PM2/16/13
to therub...@googlegroups.com
Hi,

The following crashes ruby on machine. If I don't use a context referencing self it works fine.

Thanks
Brendan

require 'v8'
gem "therubyracer", :require => 'v8'

class Window

  def initialize
    @ctx = V8::Context.new(:with => self)
  end

  def eval
    @ctx.eval('7*8')
  end
end

puts Window.new.eval


➜  ruby test_ruby_racer.rb
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:62: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]

-- Control frame information -----------------------------------------------
c:0021 p:---- s:0060 b:0060 l:000059 d:000059 CFUNC  :New
c:0020 p:0049 s:0055 b:0055 l:001b38 d:000054 BLOCK  /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:62
c:0019 p:0028 s:0052 b:0052 l:001b60 d:000051 BLOCK  /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:235
c:0018 p:---- s:0050 b:0050 l:000049 d:000049 FINISH
c:0017 p:---- s:0048 b:0048 l:000047 d:000047 CFUNC  :call
c:0016 p:---- s:0046 b:0046 l:000045 d:000045 CFUNC  :HandleScope
c:0015 p:0017 s:0043 b:0043 l:001b60 d:0012b8 BLOCK  /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:232
c:0014 p:---- s:0041 b:0041 l:000040 d:000040 FINISH
c:0013 p:---- s:0039 b:0039 l:000038 d:000038 CFUNC  :call
c:0012 p:---- s:0037 b:0037 l:000036 d:000036 CFUNC  :Locker
c:0011 p:0053 s:0034 b:0034 l:001b60 d:001b60 METHOD /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:231
c:0010 p:0026 s:0030 b:0030 l:000029 d:000029 METHOD /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:191
c:0009 p:0076 s:0026 b:0026 l:001b38 d:001b38 METHOD /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:60
c:0008 p:---- s:0021 b:0021 l:000020 d:000020 FINISH
c:0007 p:---- s:0019 b:0019 l:000018 d:000018 CFUNC  :new
c:0006 p:0024 s:0015 b:0015 l:000014 d:000014 METHOD test_ruby_racer.rb:8
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC  :new
c:0003 p:0056 s:0007 b:0006 l:000188 d:000a58 EVAL   test_ruby_racer.rb:16
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000188 d:000188 TOP   

-- Ruby level backtrace information ----------------------------------------
test_ruby_racer.rb:16:in `<main>'
test_ruby_racer.rb:16:in `new'
test_ruby_racer.rb:8:in `initialize'
test_ruby_racer.rb:8:in `new'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:60:in `initialize'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:191:in `enter'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:231:in `lock_scope_and_enter'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:231:in `Locker'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:231:in `call'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:232:in `block in lock_scope_and_enter'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:232:in `HandleScope'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:232:in `call'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:235:in `block (2 levels) in lock_scope_and_enter'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:62:in `block in initialize'
/Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb:62:in `New'

-- C level backtrace information -------------------------------------------

   See Crash Report log file under ~/Library/Logs/CrashReporter or
   /Library/Logs/CrashReporter, for the more detail of.

-- Other runtime information -----------------------------------------------

* Loaded script: test_ruby_racer.rb

* Loaded features:

    0 enumerator.so
    1 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.4.0/enc/encdb.bundle
    2 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.4.0/enc/trans/transdb.bundle
    3 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/defaults.rb
    4 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.4.0/rbconfig.rb
    5 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/deprecate.rb
    6 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/exceptions.rb
    7 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
    8 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems.rb
    9 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/version.rb
   10 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb
   11 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb
   12 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb
   13 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/path_support.rb
   14 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb
   15 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/version.rb
   16 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ref-1.0.2/lib/ref.rb
   17 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ref-1.0.2/lib/ref/reference.rb
   18 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/thread.rb
   19 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ref-1.0.2/lib/ref/safe_monitor.rb
   20 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ref-1.0.2/lib/ref/weak_reference/pure_ruby.rb
   21 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ref-1.0.2/lib/ref/abstract_reference_value_map.rb
   22 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ref-1.0.2/lib/ref/weak_value_map.rb
   23 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/weak.rb
   24 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/init.bundle
   25 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/error.rb
   26 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/stack.rb
   27 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/fundamental.rb
   28 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/indentity.rb
   29 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/reference.rb
   30 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/primitive.rb
   31 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/code.rb
   32 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/class.rb
   33 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/object.rb
   34 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/time.rb
   35 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/hash.rb
   36 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/array.rb
   37 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/proc.rb
   38 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/method.rb
   39 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/symbol.rb
   40 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/string.rb
   41 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion/fixnum.rb
   42 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/conversion.rb
   43 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/set.rb
   44 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/access/names.rb
   45 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/access/indices.rb
   46 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/access/invocation.rb
   47 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/access.rb
   48 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.4.0/stringio.bundle
   49 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/context.rb
   50 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/object.rb
   51 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/array.rb
   52 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8/function.rb
   53 /Users/brendan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/therubyracer-0.11.3/lib/v8.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.

[1]    61621 abort      ruby test_ruby_racer.rb



rainkinz

unread,
Feb 16, 2013, 11:43:02 PM2/16/13
to therub...@googlegroups.com
I just saw this on GH: https://github.com/cowboyd/therubyracer/issues/238 and that made me thing that perhaps having the Context initialized in the initializer itself is the problem. Sure enough:

require 'v8'
# or if using bundler (as with Rails), add the following to your Gemfile
gem "therubyracer", :require => 'v8'

class Window

  def initialize
    # @ctx = V8::Context.new(:with => self)
  end

  def eval
    ctx.eval('7*8')
  end

  def ctx
    @ctx ||= V8::Context.new(:with => self)
  end
  
end

puts Window.new.eval 
=> 56
Reply all
Reply to author
Forward
0 new messages