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

simplify memoization logic

replace some `if defined?` statements with a 
memoized if-statement.
This commit is contained in:
Charles Lowell 2012-05-21 08:26:06 -05:00
parent 346262e1b3
commit 41f5c85bb2

View file

@ -14,39 +14,30 @@ module Rhino
# most likely a Rhino::JS::JavaScriptException
def cause
return @cause if defined?(@cause)
@cause = begin
if @native.respond_to?(:cause) && @native.cause
@cause ||= if @native.respond_to?(:cause) && @native.cause
@native.cause
else
@native.is_a?(JS::RhinoException) ? @native : nil
end
end
end
def value
return @value if defined?(@value)
if cause.respond_to?(:value) # e.g. JavaScriptException.getValue
@value = cause.value
@value ||= if cause.respond_to?(:value) # e.g. JavaScriptException.getValue
cause.value
elsif ( unwrap = self.unwrap ) && unwrap.respond_to?(:value)
@value = unwrap.value
else
@value = nil
unwrap.value
end
end
def unwrap
return @unwrap if defined?(@unwrap)
cause = self.cause
if cause && cause.is_a?(JS::WrappedException)
@unwrap ||= if cause && cause.is_a?(JS::WrappedException)
e = cause.getWrappedException
if e && e.is_a?(Java::OrgJrubyExceptions::RaiseException)
@unwrap = e.getException
e.getException
else
@unwrap = e
e
end
else
@unwrap = nil
end
end