Sha256: 0eaa2c162bfa63c2a69664fe10e03aa9b60fb63eb0eaebf75bfa8c3c9529b794

Contents?: true

Size: 1.71 KB

Versions: 34

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

describe V8::C::External do

  it "can catch javascript exceptions" do
    V8::C::V8::SetCaptureStackTraceForUncaughtExceptions(true, 99, V8::C::StackTrace::kDetailed)
    V8::C::TryCatch() do |trycatch|
      source = V8::C::String::New(<<-JS)
      function one() {
        two()
      }
      function two() {
        three()
      }
      function three() {
        boom()
      }
      function boom() {
        throw new Error('boom!')
      }
      eval('one()')
      JS
      filename = V8::C::String::New("<eval>")
      script = V8::C::Script::New(source, filename)
      result = script.Run()
      trycatch.HasCaught().should be_true
      trycatch.CanContinue().should be_true
      exception = trycatch.Exception()
      exception.should_not be_nil
      exception.IsNativeError().should be_true
      trycatch.StackTrace().Utf8Value().should match /boom.*three.*two.*one/m
      message = trycatch.Message();
      message.should_not be_nil
      message.Get().Utf8Value().should eql "Uncaught Error: boom!"
      message.GetSourceLine().Utf8Value().should eql "        throw new Error('boom!')"
      message.GetScriptResourceName().Utf8Value().should eql "<eval>"
      message.GetLineNumber().should eql 11
      stack = message.GetStackTrace()
      stack.should_not be_nil
      stack.GetFrameCount().should eql 6
      frame = stack.GetFrame(0)
      frame.GetLineNumber().should eql 11
      frame.GetColumn().should eql 15
      frame.GetScriptName().Utf8Value().should eql "<eval>"
      frame.GetScriptNameOrSourceURL().Utf8Value().should eql "<eval>"
      frame.IsEval().should be_false
      stack.GetFrame(4).IsEval().should be_true
      frame.IsConstructor().should be_false
    end
  end
end

Version data entries

34 entries across 34 versions & 7 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/therubyracer-0.12.2/spec/c/trycatch_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/therubyracer-0.11.4/spec/c/trycatch_spec.rb
therubyracer-tmpfork-0.12.2 spec/c/trycatch_spec.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/therubyracer-0.12.2/spec/c/trycatch_spec.rb
therubyracer-0.12.2 spec/c/trycatch_spec.rb
therubyracer-0.12.1 spec/c/trycatch_spec.rb
therubyracer-discourse-0.12.0 spec/c/trycatch_spec.rb
therubyracer-0.12.0 spec/c/trycatch_spec.rb
therubyracer-0.11.4 spec/c/trycatch_spec.rb
therubyracer-0.11.3 spec/c/trycatch_spec.rb
therubyracer-0.11.2 spec/c/trycatch_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.11.0/spec/c/trycatch_spec.rb
therubyracer-0.11.1 spec/c/trycatch_spec.rb
therubyracer-0.11.1beta1 spec/c/trycatch_spec.rb
therubyracer-0.11.0 spec/c/trycatch_spec.rb
therubyracer-0.11.0beta8-x86-freebsd-9 spec/c/trycatch_spec.rb
therubyracer-0.11.0beta8-x86_64-linux spec/c/trycatch_spec.rb
therubyracer-0.11.0beta8-x86-linux spec/c/trycatch_spec.rb
therubyracer-0.11.0beta8 spec/c/trycatch_spec.rb
therubyracer-0.11.0beta7-x86_64-linux spec/c/trycatch_spec.rb