1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

for clarity, move try and protect into error

This commit is contained in:
Charles Lowell 2012-08-01 17:36:18 +03:00
parent 44af6d65f7
commit 241d0805d4
4 changed files with 35 additions and 38 deletions

View file

@ -4,8 +4,6 @@ require 'ref'
require 'v8/init'
require 'v8/util/weakcell'
require 'v8/error'
require 'v8/error/protect'
require 'v8/error/try'
require 'v8/conversion/fundamental'
require 'v8/conversion/indentity'
require 'v8/conversion/reference'

View file

@ -5,8 +5,41 @@ module V8
super(message)
@value = value
end
module Try
def try
context = V8::Context.current
V8::C::TryCatch() do |trycatch|
result = yield
if trycatch.HasCaught()
V8::Error(trycatch.Exception())
else
result
end
end
end
end
module Protect
def protect
yield
rescue Football => e
e.kickoff!
rescue Exception => e
e.extend Football
e.kickoff!
end
end
module Football
def kickoff!
error = V8::C::Exception::Error(message)
error.SetHiddenValue("rr::Football", V8::C::External::New(self))
V8::C::ThrowException(error)
end
end
end
const_set :JSError, Error
def self.Error(exception)
value = exception.to_ruby
@ -22,4 +55,5 @@ module V8
raise V8::Error.new(exception.ToString().to_ruby, value)
end
end
const_set :JSError, Error
end

View file

@ -1,20 +0,0 @@
class V8::Error
module Protect
def protect
yield
rescue Football => e
e.kickoff!
rescue Exception => e
e.extend Football
e.kickoff!
end
end
module Football
def kickoff!
error = V8::C::Exception::Error(message)
error.SetHiddenValue("rr::Football", V8::C::External::New(self))
V8::C::ThrowException(error)
end
end
end

View file

@ -1,15 +0,0 @@
class V8::Error
module Try
def try
context = V8::Context.current
V8::C::TryCatch() do |trycatch|
result = yield
if trycatch.HasCaught()
V8::Error(trycatch.Exception())
else
result
end
end
end
end
end