Sha256: ec96f5ca2282cf78ff8e9c01195850676fb6d59b93b955b96e26c462b26358b3

Contents?: true

Size: 1.33 KB

Versions: 65

Compression:

Stored size: 1.33 KB

Contents

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

include V8

describe C::TryCatch do

  before {@lock = C::Locker.new;@cxt = C::Context::New();}
  after {@cxt.Dispose(); @lock.delete}

  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

65 entries across 65 versions & 5 rubygems

Version Path
classiccms-0.5.13 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.12 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.11 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.10 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.9 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.8 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.7 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
therubyracer-0.10.2 spec/ext/try_catch_spec.rb
therubyracer-0.10.2beta1 spec/ext/try_catch_spec.rb
classiccms-0.5.6 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.5 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.2 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.1 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.5.0 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.4.2 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.4.1 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.4.0 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
classiccms-0.3.9 vendor/bundle/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.10.1/spec/ext/try_catch_spec.rb