From 241d0805d4f939f7962bc6e6a25a868845db1200 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Wed, 1 Aug 2012 17:36:18 +0300 Subject: [PATCH] for clarity, move try and protect into error --- lib/v8.rb | 2 -- lib/v8/error.rb | 36 +++++++++++++++++++++++++++++++++++- lib/v8/error/protect.rb | 20 -------------------- lib/v8/error/try.rb | 15 --------------- 4 files changed, 35 insertions(+), 38 deletions(-) delete mode 100644 lib/v8/error/protect.rb delete mode 100644 lib/v8/error/try.rb diff --git a/lib/v8.rb b/lib/v8.rb index 46e549f..9cc590a 100644 --- a/lib/v8.rb +++ b/lib/v8.rb @@ -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' diff --git a/lib/v8/error.rb b/lib/v8/error.rb index 582891d..6681c58 100644 --- a/lib/v8/error.rb +++ b/lib/v8/error.rb @@ -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 \ No newline at end of file diff --git a/lib/v8/error/protect.rb b/lib/v8/error/protect.rb deleted file mode 100644 index 97273b1..0000000 --- a/lib/v8/error/protect.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/lib/v8/error/try.rb b/lib/v8/error/try.rb deleted file mode 100644 index 46a41d5..0000000 --- a/lib/v8/error/try.rb +++ /dev/null @@ -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 \ No newline at end of file