Skip to content

Commit 9e9ec35

Browse files
committed
Extend #test_map and fix behavior for the Map#values() case
1 parent c8d03d6 commit 9e9ec35

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/mini_racer/truffleruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def convert_js_to_ruby(value)
249249
elsif map?(value)
250250
js_map_to_hash(value)
251251
elsif map_iterator?(value)
252-
value.flat_map { |e| convert_js_to_ruby(e) }
252+
value.map { |e| convert_js_to_ruby(e) }
253253
else
254254
object = value
255255
h = {}

test/mini_racer_test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,17 @@ def test_map
10631063
context = MiniRacer::Context.new
10641064
expected = {"x" => 42, "y" => 43}
10651065
assert_equal expected, context.eval("new Map([['x', 42], ['y', 43]])")
1066-
expected = ["x", 42, "y", 43]
1066+
if RUBY_ENGINE == "truffleruby"
1067+
# See https://github.com/rubyjs/mini_racer/pull/325#discussion_r1907187166
1068+
expected = [["x", 42], ["y", 43]]
1069+
else
1070+
expected = ["x", 42, "y", 43]
1071+
end
10671072
assert_equal expected, context.eval("new Map([['x', 42], ['y', 43]]).entries()")
1073+
expected = ["x", "y"]
1074+
assert_equal expected, context.eval("new Map([['x', 42], ['y', 43]]).keys()")
1075+
expected = [[42], [43]]
1076+
assert_equal expected, context.eval("new Map([['x', [42]], ['y', [43]]]).values()")
10681077
end
10691078

10701079
def test_regexp_string_iterator

0 commit comments

Comments
 (0)