aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json/encoding.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/json/encoding.rb')
-rw-r--r--activesupport/lib/active_support/json/encoding.rb15
1 files changed, 6 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index d22fe14b33..469ae69258 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -1,6 +1,5 @@
require 'active_support/core_ext/object/to_json'
require 'active_support/core_ext/module/delegation'
-require 'active_support/deprecation'
require 'active_support/json/variable'
require 'active_support/ordered_hash'
@@ -14,6 +13,7 @@ require 'time'
require 'active_support/core_ext/time/conversions'
require 'active_support/core_ext/date_time/conversions'
require 'active_support/core_ext/date/conversions'
+require 'set'
module ActiveSupport
class << self
@@ -38,8 +38,8 @@ module ActiveSupport
attr_reader :options
def initialize(options = nil)
- @options = options
- @seen = []
+ @options = options || {}
+ @seen = Set.new
end
def encode(value, use_options = true)
@@ -59,7 +59,7 @@ module ActiveSupport
def options_for(value)
if value.is_a?(Array) || value.is_a?(Hash)
# hashes and arrays need to get encoder in the options, so that they can detect circular references
- (options || {}).merge(:encoder => self)
+ options.merge(:encoder => self)
else
options
end
@@ -71,13 +71,12 @@ module ActiveSupport
private
def check_for_circular_references(value)
- if @seen.any? { |object| object.equal?(value) }
+ unless @seen.add?(value.__id__)
raise CircularReferenceError, 'object references itself'
end
- @seen.unshift value
yield
ensure
- @seen.shift
+ @seen.delete(value.__id__)
end
end
@@ -139,8 +138,6 @@ module ActiveSupport
self.use_standard_json_time_format = true
self.escape_html_entities_in_json = false
end
-
- CircularReferenceError = Deprecation::DeprecatedConstantProxy.new('ActiveSupport::JSON::CircularReferenceError', Encoding::CircularReferenceError)
end
end