diff --git a/lib/mini_racer/truffleruby.rb b/lib/mini_racer/truffleruby.rb index cc9c3fe..5beed70 100644 --- a/lib/mini_racer/truffleruby.rb +++ b/lib/mini_racer/truffleruby.rb @@ -249,7 +249,7 @@ def convert_js_to_ruby(value) elsif map?(value) js_map_to_hash(value) elsif map_iterator?(value) - value.flat_map { |e| convert_js_to_ruby(e) } + value.map { |e| convert_js_to_ruby(e) } else object = value h = {} diff --git a/test/mini_racer_test.rb b/test/mini_racer_test.rb index 3dbc336..87dcc00 100644 --- a/test/mini_racer_test.rb +++ b/test/mini_racer_test.rb @@ -1063,8 +1063,17 @@ def test_map context = MiniRacer::Context.new expected = {"x" => 42, "y" => 43} assert_equal expected, context.eval("new Map([['x', 42], ['y', 43]])") - expected = ["x", 42, "y", 43] + if RUBY_ENGINE == "truffleruby" + # See https://github.com/rubyjs/mini_racer/pull/325#discussion_r1907187166 + expected = [["x", 42], ["y", 43]] + else + expected = ["x", 42, "y", 43] + end assert_equal expected, context.eval("new Map([['x', 42], ['y', 43]]).entries()") + expected = ["x", "y"] + assert_equal expected, context.eval("new Map([['x', 42], ['y', 43]]).keys()") + expected = [[42], [43]] + assert_equal expected, context.eval("new Map([['x', [42]], ['y', [43]]]).values()") end def test_regexp_string_iterator