diff --git a/execjs.gemspec b/execjs.gemspec index e83912b..3a6c9be 100644 --- a/execjs.gemspec +++ b/execjs.gemspec @@ -19,4 +19,5 @@ Gem::Specification.new do |s| s.email = ["sstephenson@gmail.com", "josh@joshpeek.com"] s.required_ruby_version = '>= 2.5.0' + s.add_dependency 'json', '>= 2' end diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index a0325f4..ce35194 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -19,7 +19,7 @@ def eval(source, options = {}) source = source.encode(Encoding::UTF_8) if /\S/ =~ source - exec("return eval(#{::JSON.generate("(#{source})", quirks_mode: true)})") + exec("return eval(#{::JSON.generate("(#{source})")})") end end @@ -66,7 +66,7 @@ def write_to_tempfile(contents) end def extract_result(output, filename) - status, value, stack = output.empty? ? [] : ::JSON.parse(output, create_additions: false) + status, value, stack = output.empty? ? [] : ::JSON.parse(output) if status == "ok" value else @@ -156,7 +156,7 @@ def json2_source def encode_source(source) encoded_source = encode_unicode_codepoints(source) - ::JSON.generate("(function(){ #{encoded_source} })()", quirks_mode: true) + ::JSON.generate("(function(){ #{encoded_source} })()") end def encode_unicode_codepoints(str) diff --git a/lib/execjs/ruby_rhino_runtime.rb b/lib/execjs/ruby_rhino_runtime.rb index 4829263..ff7edc4 100644 --- a/lib/execjs/ruby_rhino_runtime.rb +++ b/lib/execjs/ruby_rhino_runtime.rb @@ -35,7 +35,7 @@ def eval(source, options = {}) def call(properties, *args) # Might no longer be necessary if therubyrhino handles Symbols directly: # https://github.com/rubyjs/therubyrhino/issues/43 - converted_args = JSON.parse(JSON.generate(args), create_additions: false) + converted_args = JSON.parse(JSON.generate(args)) unbox @rhino_context.eval(properties).call(*converted_args) rescue Exception => e diff --git a/test/test_execjs.rb b/test/test_execjs.rb index b3fec92..2c2d7af 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -152,10 +152,10 @@ def test_context_call_missing_function { "a" => 1, "b" => [2, 3]}, { "a" => true } ].each_with_index do |value, index| - json_value = JSON.generate(value, quirks_mode: true) + json_value = JSON.generate(value) define_method("test_json_value_#{index}") do - assert_output value, JSON.parse(json_value, quirks_mode: true) + assert_output value, JSON.parse(json_value) end define_method("test_exec_value_#{index}") do