2012-05-25 15:53:13 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe V8::C::External do
|
2012-05-25 16:01:31 -05:00
|
|
|
|
2012-05-25 15:53:13 -05:00
|
|
|
it "can catch javascript exceptions" do
|
|
|
|
V8::C::V8::SetCaptureStackTraceForUncaughtExceptions(true, 99, V8::C::StackTrace::kDetailed)
|
|
|
|
V8::C::TryCatch() do |trycatch|
|
2012-06-05 08:00:04 -05:00
|
|
|
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
|
2012-05-25 15:53:13 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|