Skip to content

Commit

Permalink
chore: support js Map, Set in protocol results (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Sep 6, 2023
1 parent 05eb1f1 commit 4d91219
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static class O {
Number h;
Integer id;
Integer ref;
// JS representation of Map: [[key1, value1], [key2, value2], ...].
SerializedValue m;
// JS representation of Set: [item1, item2, ...].
SerializedValue se;
}

class SerializedArgument{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ private static <T> T deserialize(SerializedValue value, Map<Integer, Object> idT
}
return (T) map;
}
if (value.m != null) {
Map<?, ?> map = new LinkedHashMap<>();
idToValue.put(value.id, map);
return (T) map;
}
if (value.se != null) {
Map<?, ?> map = new LinkedHashMap<>();
idToValue.put(value.id, map);
return (T) map;
}
throw new PlaywrightException("Unexpected result: " + gson().toJson(value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,14 @@ void shouldAcceptParameter() {
assertTrue(object instanceof Date);
assertEquals(Date.from(instant), object);
}

@Test
void shouldTransferMaps() {
assertEquals(mapOf(), page.evaluate("() => new Map([[1, { test: 42n }]])"));
}

@Test
void shouldTransferSets() {
assertEquals(mapOf(), page.evaluate("() => new Set([1, { test: 42n }])"));
}
}

0 comments on commit 4d91219

Please sign in to comment.