mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Fix invalid MultiJson API detection (closes #82)
`#load` is defined in Kernel and inherited in every object, thus Object.respond_to?(:load) will always return true. MultiJson switched to load/dump from decode/encode. Thus it's safe to use a single check for both encoding and decoding methods.
This commit is contained in:
parent
121e97dbf4
commit
5b87c9b7ec
1 changed files with 5 additions and 7 deletions
|
@ -85,21 +85,19 @@ module ExecJS
|
|||
end
|
||||
end
|
||||
|
||||
if MultiJson.respond_to?(:load)
|
||||
if MultiJson.respond_to?(:dump)
|
||||
def json_decode(obj)
|
||||
MultiJson.load(obj)
|
||||
end
|
||||
else
|
||||
def json_decode(obj)
|
||||
MultiJson.decode(obj)
|
||||
end
|
||||
end
|
||||
|
||||
if MultiJson.respond_to?(:dump)
|
||||
def json_encode(obj)
|
||||
MultiJson.dump(obj)
|
||||
end
|
||||
else
|
||||
def json_decode(obj)
|
||||
MultiJson.decode(obj)
|
||||
end
|
||||
|
||||
def json_encode(obj)
|
||||
MultiJson.encode(obj)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue