Skip to content

Commit 4d91219

Browse files
authored
chore: support js Map, Set in protocol results (#1376)
1 parent 05eb1f1 commit 4d91219

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public static class O {
4747
Number h;
4848
Integer id;
4949
Integer ref;
50+
// JS representation of Map: [[key1, value1], [key2, value2], ...].
51+
SerializedValue m;
52+
// JS representation of Set: [item1, item2, ...].
53+
SerializedValue se;
5054
}
5155

5256
class SerializedArgument{

playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,16 @@ private static <T> T deserialize(SerializedValue value, Map<Integer, Object> idT
280280
}
281281
return (T) map;
282282
}
283+
if (value.m != null) {
284+
Map<?, ?> map = new LinkedHashMap<>();
285+
idToValue.put(value.id, map);
286+
return (T) map;
287+
}
288+
if (value.se != null) {
289+
Map<?, ?> map = new LinkedHashMap<>();
290+
idToValue.put(value.id, map);
291+
return (T) map;
292+
}
283293
throw new PlaywrightException("Unexpected result: " + gson().toJson(value));
284294
}
285295

playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,4 +645,14 @@ void shouldAcceptParameter() {
645645
assertTrue(object instanceof Date);
646646
assertEquals(Date.from(instant), object);
647647
}
648+
649+
@Test
650+
void shouldTransferMaps() {
651+
assertEquals(mapOf(), page.evaluate("() => new Map([[1, { test: 42n }]])"));
652+
}
653+
654+
@Test
655+
void shouldTransferSets() {
656+
assertEquals(mapOf(), page.evaluate("() => new Set([1, { test: 42n }])"));
657+
}
648658
}

0 commit comments

Comments
 (0)