mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
rescue SystemStackError that comes from inspecting self-referencing Hashes and Arrays; fix #2461
This commit is contained in:
+10
-3
@@ -84,13 +84,20 @@ class Array
|
||||
self
|
||||
end
|
||||
|
||||
def _inspect
|
||||
return "[]" if self.size == 0
|
||||
"["+self.map{|x|x.inspect}.join(", ")+"]"
|
||||
end
|
||||
##
|
||||
# Private method for Array creation.
|
||||
# Return the contents of this array as a string.
|
||||
#
|
||||
# ISO 15.2.12.5.31 (x)
|
||||
def inspect
|
||||
return "[]" if self.size == 0
|
||||
"["+self.map{|x|x.inspect}.join(", ")+"]"
|
||||
begin
|
||||
self._inspect
|
||||
rescue SystemStackError
|
||||
"[...]"
|
||||
end
|
||||
end
|
||||
# ISO 15.2.12.5.32 (x)
|
||||
alias to_s inspect
|
||||
|
||||
+14
-6
@@ -192,16 +192,24 @@ class Hash
|
||||
h
|
||||
end
|
||||
|
||||
##
|
||||
# Return the contents of this hash as a string.
|
||||
#
|
||||
# ISO 15.2.13.4.30 (x)
|
||||
def inspect
|
||||
# internal method for Hash inspection
|
||||
def _inspect
|
||||
return "{}" if self.size == 0
|
||||
"{"+self.map {|k,v|
|
||||
k.inspect + "=>" + v.inspect
|
||||
k._inspect + "=>" + v._inspect
|
||||
}.join(", ")+"}"
|
||||
end
|
||||
##
|
||||
# Return the contents of this hash as a string.
|
||||
#
|
||||
# ISO 15.2.13.4.30 (x)
|
||||
def inspect
|
||||
begin
|
||||
self._inspect
|
||||
rescue SystemStackError
|
||||
"{...}"
|
||||
end
|
||||
end
|
||||
# ISO 15.2.13.4.31 (x)
|
||||
alias to_s inspect
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ module Kernel
|
||||
!(self =~ y)
|
||||
end
|
||||
|
||||
# internal method for inspect
|
||||
def _inspect
|
||||
self.inspect
|
||||
end
|
||||
|
||||
def to_enum(*a)
|
||||
raise NotImplementedError.new("fiber required for enumerator")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user