From 3ae024c4c4ec18c75fbb8b05a378dbfbe1ff5adb Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 14 Sep 2026 11:40:51 -0700 Subject: [PATCH] fix(evaluate): 0.0 is serialized as -0 `d == -0` is true for both 0.0 and -0.0, so positive zero was sent to the browser as -0. --- .../java/com/microsoft/playwright/impl/Serialization.java | 2 +- .../java/com/microsoft/playwright/TestPageEvaluate.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java index f5b44c96c..d32a034b6 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java @@ -152,7 +152,7 @@ private SerializedValue serializeValue(Object value) { result.v = "Infinity"; } else if (d == Double.NEGATIVE_INFINITY) { result.v = "-Infinity"; - } else if (d == -0) { + } else if (Double.compare(d, -0.0) == 0) { result.v = "-0"; } else if (Double.isNaN(d)) { result.v = "NaN"; diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java b/playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java index 01d49bc22..d7a9f2016 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java @@ -52,6 +52,13 @@ void shouldTransfer0() { assertEquals(Double.NEGATIVE_INFINITY, 1 / (Double) result); } + @Test + void shouldTransferPositive0() { + assertEquals(true, page.evaluate("a => Object.is(a, 0)", 0.0)); + Object result = page.evaluate("a => a", 0.0); + assertEquals(Double.POSITIVE_INFINITY, 1 / ((Number) result).doubleValue()); + } + @Test void shouldTransferInfinity() { Object result = page.evaluate("a => a", Double.POSITIVE_INFINITY);