Sha256: d6588afd4ab0e2e5edae06ec64250edff02c88e545fa6819300121e152bf9ac5

Contents?: true

Size: 1.31 KB

Versions: 10

Compression:

Stored size: 1.31 KB

Contents

require "#{File.dirname(__FILE__)}/../spec_helper.rb"

include V8

describe C::TryCatch do

  before {@cxt = C::Context::New()}
  after {@cxt.Dispose()}

  it "does not allow instance creation by default" do
    lambda {
     C::TryCatch.new 
    }.should raise_error
  end
  
  it "will do nothing if not passed a block" do
    C::TryCatch.try.should == nil
  end
  
  it "executes a block in the context of a C++ stack frame" do
    C::TryCatch.try do |catch|
      catch.HasCaught().should be(false)      
    end
  end
  
  it "raises an erro if you try to access it outside of its scope" do
    tc = C::TryCatch.try do |catch|
      catch.tap {}
    end
    lambda {
      tc.HasCaught()
    }.should raise_error(ScriptError)
  end

    it "doesn't segfault when an error is raised in a javascript function on a native prototype" do
      constructor = Class.new
      constructor.class_eval do
        def detonate(*a)
          raise "BOOM!"
        end
      end
      V8::Context.new do |cxt|
        cxt['Boom'] = constructor
        cxt['puts'] = method(:puts)
        danger = <<-JS
  Boom.prototype.boom = function() {
    this.detonate()
  }
  var go = new(Boom)()
  try {
    go.boom()
  } catch (e) {
  }
  go.boom()
  JS
        expect {cxt.eval(danger, 'danger.js')}.should raise_error(V8::JSError)
      end
    end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
therubyracer-0.9.2 spec/ext/try_catch_spec.rb
therubyracer-0.9.2beta1 spec/ext/try_catch_spec.rb
therubyracer-0.9.1 spec/ext/try_catch_spec.rb
therubyracer-0.9.1beta1 spec/ext/try_catch_spec.rb
therubyracer-0.9.0 spec/ext/try_catch_spec.rb
therubyracer-0.9.0beta7 spec/ext/try_catch_spec.rb
therubyracer-0.9.0beta6 spec/ext/try_catch_spec.rb
therubyracer-0.9.0beta5 spec/ext/try_catch_spec.rb
therubyracer-0.9.0beta4 spec/ext/try_catch_spec.rb
therubyracer-0.9.0beta3 spec/ext/try_catch_spec.rb