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:
parent
44af6d65f7
commit
241d0805d4
4 changed files with 35 additions and 38 deletions
|
@ -4,8 +4,6 @@ require 'ref'
|
||||||
require 'v8/init'
|
require 'v8/init'
|
||||||
require 'v8/util/weakcell'
|
require 'v8/util/weakcell'
|
||||||
require 'v8/error'
|
require 'v8/error'
|
||||||
require 'v8/error/protect'
|
|
||||||
require 'v8/error/try'
|
|
||||||
require 'v8/conversion/fundamental'
|
require 'v8/conversion/fundamental'
|
||||||
require 'v8/conversion/indentity'
|
require 'v8/conversion/indentity'
|
||||||
require 'v8/conversion/reference'
|
require 'v8/conversion/reference'
|
||||||
|
|
|
@ -5,8 +5,41 @@ module V8
|
||||||
super(message)
|
super(message)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
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
|
end
|
||||||
const_set :JSError, Error
|
|
||||||
|
|
||||||
def self.Error(exception)
|
def self.Error(exception)
|
||||||
value = exception.to_ruby
|
value = exception.to_ruby
|
||||||
|
@ -22,4 +55,5 @@ module V8
|
||||||
raise V8::Error.new(exception.ToString().to_ruby, value)
|
raise V8::Error.new(exception.ToString().to_ruby, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
const_set :JSError, Error
|
||||||
end
|
end
|
|
@ -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
|
|
|
@ -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
|
|
Loading…
Add table
Reference in a new issue