Skip to content

Commit

Permalink
Extend #test_map and fix behavior for the Map#values() case
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 9, 2025
1 parent 2cec0e7 commit ab4c4f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mini_racer/truffleruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
11 changes: 10 additions & 1 deletion test/mini_racer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab4c4f5

Please sign in to comment.