Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow custom json options to be specified

This allows other libraries to prevent errors like:

nesting of 20 is too deep

elabs/serenade.js#64
  • Loading branch information...
commit a9bd4ab5169350b6a1181bdf9da19e9d1ea82e3b 1 parent 1e87b37
@rosenfeld rosenfeld authored
Showing with 10 additions and 8 deletions.
  1. +1 −0  lib/execjs.rb
  2. +8 −8 lib/execjs/json.rb
  3. +1 −0  lib/execjs/module.rb
View
1  lib/execjs.rb
@@ -3,4 +3,5 @@
module ExecJS
self.runtime ||= Runtimes.autodetect
+ self.json_options = {}
end
View
16 lib/execjs/json.rb
@@ -3,20 +3,20 @@
module ExecJS
module JSON
if MultiJson.respond_to?(:dump)
- def self.decode(obj)
- MultiJson.load(obj)
+ def self.decode(obj, json_options = ExecJS.json_options)
+ MultiJson.load(obj, json_options)
end
- def self.encode(obj)
- MultiJson.dump(obj)
+ def self.encode(obj, json_options = ExecJS.json_options)
+ MultiJson.dump(obj, json_options)
end
else
- def self.decode(obj)
- MultiJson.decode(obj)
+ def self.decode(obj, json_options = ExecJS.json_options)
+ MultiJson.decode(obj, json_options)
end
- def self.encode(obj)
- MultiJson.encode(obj)
+ def self.encode(obj, json_options = ExecJS.json_options)
+ MultiJson.encode(obj, json_options)
end
end
end
View
1  lib/execjs/module.rb
@@ -9,6 +9,7 @@ class RuntimeUnavailable < RuntimeError; end
class << self
attr_reader :runtime
+ attr_accessor :json_options
def runtime=(runtime)
raise RuntimeUnavailable, "#{runtime.name} is unavailable on this system" unless runtime.available?
Please sign in to comment.
Something went wrong with that request. Please try again.