diff --git a/playwright/src/main/java/com/microsoft/playwright/Frame.java b/playwright/src/main/java/com/microsoft/playwright/Frame.java
index 2c87e613..a7820fe4 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Frame.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Frame.java
@@ -1218,22 +1218,6 @@ public interface Frame {
}
}
class LocatorOptions {
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator above;
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator below;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
}.
*/
public Object hasText;
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator leftOf;
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator near;
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator rightOf;
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setAbove(Locator above) {
- this.above = above;
- return this;
- }
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setBelow(Locator below) {
- this.below = below;
- return this;
- }
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
Playwright
}.
@@ -1322,39 +1260,6 @@ public interface Frame {
this.hasText = hasText;
return this;
}
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setLeftOf(Locator leftOf) {
- this.leftOf = leftOf;
- return this;
- }
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setNear(Locator near) {
- this.near = near;
- return this;
- }
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setRightOf(Locator rightOf) {
- this.rightOf = rightOf;
- return this;
- }
}
class PressOptions {
/**
diff --git a/playwright/src/main/java/com/microsoft/playwright/FrameLocator.java b/playwright/src/main/java/com/microsoft/playwright/FrameLocator.java
index 3f2bdef6..e294e1d9 100644
--- a/playwright/src/main/java/com/microsoft/playwright/FrameLocator.java
+++ b/playwright/src/main/java/com/microsoft/playwright/FrameLocator.java
@@ -49,22 +49,6 @@ import java.util.regex.Pattern;
*/
public interface FrameLocator {
class LocatorOptions {
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator above;
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator below;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
}.
*/
public Object hasText;
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator leftOf;
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator near;
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator rightOf;
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setAbove(Locator above) {
- this.above = above;
- return this;
- }
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setBelow(Locator below) {
- this.below = below;
- return this;
- }
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
Playwright
}.
@@ -153,39 +91,6 @@ public interface FrameLocator {
this.hasText = hasText;
return this;
}
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setLeftOf(Locator leftOf) {
- this.leftOf = leftOf;
- return this;
- }
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setNear(Locator near) {
- this.near = near;
- return this;
- }
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setRightOf(Locator rightOf) {
- this.rightOf = rightOf;
- return this;
- }
}
/**
* Returns locator to the first matching frame.
diff --git a/playwright/src/main/java/com/microsoft/playwright/Locator.java b/playwright/src/main/java/com/microsoft/playwright/Locator.java
index 200b4458..667a8797 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Locator.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Locator.java
@@ -591,22 +591,6 @@ public interface Locator {
}
}
class FilterOptions {
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator above;
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator below;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
}.
*/
public Object hasText;
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator leftOf;
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator near;
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator rightOf;
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public FilterOptions setAbove(Locator above) {
- this.above = above;
- return this;
- }
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public FilterOptions setBelow(Locator below) {
- this.below = below;
- return this;
- }
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
Playwright
}.
@@ -695,39 +633,6 @@ public interface Locator {
this.hasText = hasText;
return this;
}
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public FilterOptions setLeftOf(Locator leftOf) {
- this.leftOf = leftOf;
- return this;
- }
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public FilterOptions setNear(Locator near) {
- this.near = near;
- return this;
- }
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public FilterOptions setRightOf(Locator rightOf) {
- this.rightOf = rightOf;
- return this;
- }
}
class FocusOptions {
/**
@@ -1003,22 +908,6 @@ public interface Locator {
}
}
class LocatorOptions {
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator above;
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator below;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
}.
*/
public Object hasText;
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator leftOf;
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator near;
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator rightOf;
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setAbove(Locator above) {
- this.above = above;
- return this;
- }
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setBelow(Locator below) {
- this.below = below;
- return this;
- }
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
Playwright
}.
@@ -1107,39 +950,6 @@ public interface Locator {
this.hasText = hasText;
return this;
}
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setLeftOf(Locator leftOf) {
- this.leftOf = leftOf;
- return this;
- }
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setNear(Locator near) {
- this.near = near;
- return this;
- }
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setRightOf(Locator rightOf) {
- this.rightOf = rightOf;
- return this;
- }
}
class PressOptions {
/**
diff --git a/playwright/src/main/java/com/microsoft/playwright/Page.java b/playwright/src/main/java/com/microsoft/playwright/Page.java
index 7af0e549..1d6ee25d 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Page.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Page.java
@@ -1658,22 +1658,6 @@ public interface Page extends AutoCloseable {
}
}
class LocatorOptions {
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator above;
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator below;
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
}.
*/
public Object hasText;
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator leftOf;
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator near;
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public Locator rightOf;
- /**
- * Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setAbove(Locator above) {
- this.above = above;
- return this;
- }
- /**
- * Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setBelow(Locator below) {
- this.below = below;
- return this;
- }
/**
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
* For example, {@code article} that has {@code text=Playwright} matches {@code
Playwright
}.
@@ -1762,39 +1700,6 @@ public interface Page extends AutoCloseable {
this.hasText = hasText;
return this;
}
- /**
- * Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator
- * is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setLeftOf(Locator leftOf) {
- this.leftOf = leftOf;
- return this;
- }
- /**
- * Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is
- * queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setNear(Locator near) {
- this.near = near;
- return this;
- }
- /**
- * Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner
- * locator is queried against the same root as the outer one. More details in layout selectors guide.
- *
- *
Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
- */
- public LocatorOptions setRightOf(Locator rightOf) {
- this.rightOf = rightOf;
- return this;
- }
}
class PdfOptions {
/**
diff --git a/playwright/src/main/java/com/microsoft/playwright/Route.java b/playwright/src/main/java/com/microsoft/playwright/Route.java
index d84f6706..f464af89 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Route.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Route.java
@@ -22,6 +22,8 @@ import java.util.*;
/**
* Whenever a network route is set up with {@link Page#route Page.route()} or {@link BrowserContext#route
* BrowserContext.route()}, the {@code Route} object allows to handle the route.
+ *
+ *
Learn more about networking.
*/
public interface Route {
class ResumeOptions {
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
index 8d7afecc..1e8a2bef 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
@@ -32,11 +32,11 @@ class LocatorImpl implements Locator {
{
try {
addFilter("has", "has");
- addFilter("leftOf", "left-of");
- addFilter("rightOf", "right-of");
- addFilter("above", "above");
- addFilter("below", "below");
- addFilter("near", "near");
+// addFilter("leftOf", "left-of");
+// addFilter("rightOf", "right-of");
+// addFilter("above", "above");
+// addFilter("below", "below");
+// addFilter("near", "near");
} catch (NoSuchFieldException e) {
throw new InternalError(e);
}
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java b/playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java
index 48162f69..28a69650 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java
@@ -43,6 +43,8 @@ class SerializedValue{
}
O[] o;
Number h;
+ Integer id;
+ Integer ref;
}
class SerializedArgument{
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 2157d84f..89a7e766 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java
@@ -71,82 +71,128 @@ class Serialization {
return result;
}
- private static SerializedValue serializeValue(Object value, List handles, int depth) {
- if (depth > 100) {
- throw new PlaywrightException("Maximum argument depth exceeded");
+ private static class ValueSerializer {
+ // hashCode() of a map containing itself as a key will throw stackoverflow exception,
+ // so we user wrappers.
+ private static class HashableValue {
+ final Object value;
+ HashableValue(Object value) {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return value == ((HashableValue) o).value;
+ }
+
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(value);
+ }
}
- SerializedValue result = new SerializedValue();
- if (value instanceof JSHandleImpl) {
- result.h = handles.size();
- handles.add((JSHandleImpl) value);
+ private final Map valueToId = new HashMap<>();
+ private int lastId = 0;
+ private final List handles = new ArrayList<>();
+ private final SerializedValue serializedValue;
+
+ ValueSerializer(Object value) {
+ serializedValue = serializeValue(value);
+ }
+
+ SerializedArgument toSerializedArgument() {
+ SerializedArgument result = new SerializedArgument();
+ result.value = serializedValue;
+ result.handles = new Channel[handles.size()];
+ int i = 0;
+ for (JSHandleImpl handle : handles) {
+ result.handles[i] = new Channel();
+ result.handles[i].guid = handle.guid;
+ ++i;
+ }
return result;
}
- if (value == null) {
- result.v = "undefined";
- } else if (value instanceof Double) {
- double d = ((Double) value);
- if (d == Double.POSITIVE_INFINITY) {
- result.v = "Infinity";
- } else if (d == Double.NEGATIVE_INFINITY) {
- result.v = "-Infinity";
- } else if (d == -0) {
- result.v = "-0";
- } else if (Double.isNaN(d)) {
- result.v = "NaN";
+
+ private SerializedValue serializeValue(Object value) {
+ SerializedValue result = new SerializedValue();
+ if (value instanceof JSHandleImpl) {
+ result.h = handles.size();
+ handles.add((JSHandleImpl) value);
+ return result;
+ }
+ if (value == null) {
+ result.v = "undefined";
+ } else if (value instanceof Double) {
+ double d = ((Double) value);
+ if (d == Double.POSITIVE_INFINITY) {
+ result.v = "Infinity";
+ } else if (d == Double.NEGATIVE_INFINITY) {
+ result.v = "-Infinity";
+ } else if (d == -0) {
+ result.v = "-0";
+ } else if (Double.isNaN(d)) {
+ result.v = "NaN";
+ } else {
+ result.n = d;
+ }
+ } else if (value instanceof Boolean) {
+ result.b = (Boolean) value;
+ } else if (value instanceof Integer) {
+ result.n = (Integer) value;
+ } else if (value instanceof String) {
+ result.s = (String) value;
} else {
- result.n = d;
+ HashableValue mapKey = new HashableValue(value);
+ Integer id = valueToId.get(mapKey);
+ if (id != null) {
+ result.ref = id;
+ } else {
+ result.id = ++lastId;
+ valueToId.put(mapKey, lastId);
+ if (value instanceof List) {
+ List list = new ArrayList<>();
+ for (Object o : (List>) value) {
+ list.add(serializeValue(o));
+ }
+ result.a = list.toArray(new SerializedValue[0]);
+ } else if (value instanceof Map) {
+ List list = new ArrayList<>();
+ @SuppressWarnings("unchecked")
+ Map map = (Map) value;
+ for (Map.Entry e : map.entrySet()) {
+ SerializedValue.O o = new SerializedValue.O();
+ o.k = e.getKey();
+ o.v = serializeValue(e.getValue());
+ list.add(o);
+ }
+ result.o = list.toArray(new SerializedValue.O[0]);
+ } else if (value instanceof Object[]) {
+ List list = new ArrayList<>();
+ for (Object o : (Object[]) value) {
+ list.add(serializeValue(o));
+ }
+ result.a = list.toArray(new SerializedValue[0]);
+ } else {
+ throw new PlaywrightException("Unsupported type of argument: " + value);
+ }
+ }
}
- } else if (value instanceof Boolean) {
- result.b = (Boolean) value;
- } else if (value instanceof Integer) {
- result.n = (Integer) value;
- } else if (value instanceof String) {
- result.s = (String) value;
- } else if (value instanceof List) {
- List list = new ArrayList<>();
- for (Object o : (List>) value) {
- list.add(serializeValue(o, handles, depth + 1));
- }
- result.a = list.toArray(new SerializedValue[0]);
- } else if (value instanceof Map) {
- List list = new ArrayList<>();
- @SuppressWarnings("unchecked")
- Map map = (Map) value;
- for (Map.Entry e : map.entrySet()) {
- SerializedValue.O o = new SerializedValue.O();
- o.k = e.getKey();
- o.v = serializeValue(e.getValue(), handles, depth + 1);
- list.add(o);
- }
- result.o = list.toArray(new SerializedValue.O[0]);
- } else if (value instanceof Object[]) {
- List list = new ArrayList<>();
- for (Object o : (Object[]) value) {
- list.add(serializeValue(o, handles, depth + 1));
- }
- result.a = list.toArray(new SerializedValue[0]);
- } else {
- throw new PlaywrightException("Unsupported type of argument: " + value);
+ return result;
}
- return result;
}
static SerializedArgument serializeArgument(Object arg) {
- SerializedArgument result = new SerializedArgument();
- List handles = new ArrayList<>();
- result.value = serializeValue(arg, handles, 0);
- result.handles = new Channel[handles.size()];
- int i = 0;
- for (JSHandleImpl handle : handles) {
- result.handles[i] = new Channel();
- result.handles[i].guid = handle.guid;
- ++i;
- }
- return result;
+ return new ValueSerializer(arg).toSerializedArgument();
+ }
+
+ static T deserialize(SerializedValue value) {
+ return deserialize(value, new HashMap<>());
}
@SuppressWarnings("unchecked")
- static T deserialize(SerializedValue value) {
+ private static T deserialize(SerializedValue value, Map idToValue) {
+ if (value.ref != null) {
+ return (T) idToValue.get(value.ref);
+ }
if (value.n != null) {
if (value.n.doubleValue() == (double) value.n.intValue()) {
return (T) Integer.valueOf(value.n.intValue());
@@ -177,15 +223,17 @@ class Serialization {
}
if (value.a != null) {
List