Skip to content

[dotnet] [bidi] Migrate RemoteValue to separate types #15426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,33 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
[JsonSerializable(typeof(Modules.Script.EvaluateResult.Success))]
[JsonSerializable(typeof(Modules.Script.EvaluateResult.Exception))]

[JsonSerializable(typeof(Modules.Script.RemoteValue.Number), TypeInfoPropertyName = "Script_RemoteValue_Number")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Boolean), TypeInfoPropertyName = "Script_RemoteValue_Boolean")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.String), TypeInfoPropertyName = "Script_RemoteValue_String")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Null), TypeInfoPropertyName = "Script_RemoteValue_Null")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Undefined), TypeInfoPropertyName = "Script_RemoteValue_Undefined")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Symbol))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Array), TypeInfoPropertyName = "Script_RemoteValue_Array")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Object), TypeInfoPropertyName = "Script_RemoteValue_Object")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Function))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.RegExp), TypeInfoPropertyName = "Script_RemoteValue_RegExp")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.RegExp.RegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp_RegExpValue")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Date), TypeInfoPropertyName = "Script_RemoteValue_Date")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Map), TypeInfoPropertyName = "Script_RemoteValue_Map")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Set), TypeInfoPropertyName = "Script_RemoteValue_Set")]
[JsonSerializable(typeof(Modules.Script.RemoteValue.WeakMap))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.WeakSet))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Generator))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Error))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Proxy))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Promise))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.TypedArray))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.ArrayBuffer))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.NodeList))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.HtmlCollection))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.Node))]
[JsonSerializable(typeof(Modules.Script.RemoteValue.WindowProxy))]
[JsonSerializable(typeof(Modules.Script.NumberRemoteValue))]
[JsonSerializable(typeof(Modules.Script.BooleanRemoteValue))]
[JsonSerializable(typeof(Modules.Script.BigIntRemoteValue))]
[JsonSerializable(typeof(Modules.Script.StringRemoteValue))]
[JsonSerializable(typeof(Modules.Script.NullRemoteValue))]
[JsonSerializable(typeof(Modules.Script.UndefinedRemoteValue))]
[JsonSerializable(typeof(Modules.Script.SymbolRemoteValue))]
[JsonSerializable(typeof(Modules.Script.ArrayRemoteValue))]
[JsonSerializable(typeof(Modules.Script.ObjectRemoteValue))]
[JsonSerializable(typeof(Modules.Script.FunctionRemoteValue))]
[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue))]
[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue.RegExpValue), TypeInfoPropertyName = "Script_RegExpRemoteValue_RegExpValue")]
[JsonSerializable(typeof(Modules.Script.DateRemoteValue))]
[JsonSerializable(typeof(Modules.Script.MapRemoteValue))]
[JsonSerializable(typeof(Modules.Script.SetRemoteValue))]
[JsonSerializable(typeof(Modules.Script.WeakMapRemoteValue))]
[JsonSerializable(typeof(Modules.Script.WeakSetRemoteValue))]
[JsonSerializable(typeof(Modules.Script.GeneratorRemoteValue))]
[JsonSerializable(typeof(Modules.Script.ErrorRemoteValue))]
[JsonSerializable(typeof(Modules.Script.ProxyRemoteValue))]
[JsonSerializable(typeof(Modules.Script.PromiseRemoteValue))]
[JsonSerializable(typeof(Modules.Script.TypedArrayRemoteValue))]
[JsonSerializable(typeof(Modules.Script.ArrayBufferRemoteValue))]
[JsonSerializable(typeof(Modules.Script.NodeListRemoteValue))]
[JsonSerializable(typeof(Modules.Script.HtmlCollectionRemoteValue))]
[JsonSerializable(typeof(Modules.Script.NodeRemoteValue))]
[JsonSerializable(typeof(Modules.Script.WindowProxyRemoteValue))]

[JsonSerializable(typeof(Modules.Script.RealmInfo.Window))]
[JsonSerializable(typeof(Modules.Script.RealmInfo.DedicatedWorker))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class LocateNodesResultConverter : JsonConverter<LocateNodesResult>
public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using var doc = JsonDocument.ParseValue(ref reader);
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<RemoteValue.Node>>(options);
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<NodeRemoteValue>>(options);

return new LocateNodesResult(nodes!);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,37 @@ internal class RemoteValueConverter : JsonConverter<RemoteValue>

if (jsonDocument.RootElement.ValueKind == JsonValueKind.String)
{
return new RemoteValue.String(jsonDocument.RootElement.GetString()!);
return new StringRemoteValue(jsonDocument.RootElement.GetString()!);
}

return jsonDocument.RootElement.GetProperty("type").ToString() switch
{
"number" => jsonDocument.Deserialize<RemoteValue.Number>(options),
"boolean" => jsonDocument.Deserialize<RemoteValue.Boolean>(options),
"string" => jsonDocument.Deserialize<RemoteValue.String>(options),
"null" => jsonDocument.Deserialize<RemoteValue.Null>(options),
"undefined" => jsonDocument.Deserialize<RemoteValue.Undefined>(options),
"symbol" => jsonDocument.Deserialize<RemoteValue.Symbol>(options),
"array" => jsonDocument.Deserialize<RemoteValue.Array>(options),
"object" => jsonDocument.Deserialize<RemoteValue.Object>(options),
"function" => jsonDocument.Deserialize<RemoteValue.Function>(options),
"regexp" => jsonDocument.Deserialize<RemoteValue.RegExp>(options),
"date" => jsonDocument.Deserialize<RemoteValue.Date>(options),
"map" => jsonDocument.Deserialize<RemoteValue.Map>(options),
"set" => jsonDocument.Deserialize<RemoteValue.Set>(options),
"weakmap" => jsonDocument.Deserialize<RemoteValue.WeakMap>(options),
"weakset" => jsonDocument.Deserialize<RemoteValue.WeakSet>(options),
"generator" => jsonDocument.Deserialize<RemoteValue.Generator>(options),
"error" => jsonDocument.Deserialize<RemoteValue.Error>(options),
"proxy" => jsonDocument.Deserialize<RemoteValue.Proxy>(options),
"promise" => jsonDocument.Deserialize<RemoteValue.Promise>(options),
"typedarray" => jsonDocument.Deserialize<RemoteValue.TypedArray>(options),
"arraybuffer" => jsonDocument.Deserialize<RemoteValue.ArrayBuffer>(options),
"nodelist" => jsonDocument.Deserialize<RemoteValue.NodeList>(options),
"htmlcollection" => jsonDocument.Deserialize<RemoteValue.HtmlCollection>(options),
"node" => jsonDocument.Deserialize<RemoteValue.Node>(options),
"window" => jsonDocument.Deserialize<RemoteValue.WindowProxy>(options),
"number" => jsonDocument.Deserialize<NumberRemoteValue>(options),
"boolean" => jsonDocument.Deserialize<BooleanRemoteValue>(options),
"bigint" => jsonDocument.Deserialize<BigIntRemoteValue>(options),
"string" => jsonDocument.Deserialize<StringRemoteValue>(options),
"null" => jsonDocument.Deserialize<NullRemoteValue>(options),
"undefined" => jsonDocument.Deserialize<UndefinedRemoteValue>(options),
"symbol" => jsonDocument.Deserialize<SymbolRemoteValue>(options),
"array" => jsonDocument.Deserialize<ArrayRemoteValue>(options),
"object" => jsonDocument.Deserialize<ObjectRemoteValue>(options),
"function" => jsonDocument.Deserialize<FunctionRemoteValue>(options),
"regexp" => jsonDocument.Deserialize<RegExpRemoteValue>(options),
"date" => jsonDocument.Deserialize<DateRemoteValue>(options),
"map" => jsonDocument.Deserialize<MapRemoteValue>(options),
"set" => jsonDocument.Deserialize<SetRemoteValue>(options),
"weakmap" => jsonDocument.Deserialize<WeakMapRemoteValue>(options),
"weakset" => jsonDocument.Deserialize<WeakSetRemoteValue>(options),
"generator" => jsonDocument.Deserialize<GeneratorRemoteValue>(options),
"error" => jsonDocument.Deserialize<ErrorRemoteValue>(options),
"proxy" => jsonDocument.Deserialize<ProxyRemoteValue>(options),
"promise" => jsonDocument.Deserialize<PromiseRemoteValue>(options),
"typedarray" => jsonDocument.Deserialize<TypedArrayRemoteValue>(options),
"arraybuffer" => jsonDocument.Deserialize<ArrayBufferRemoteValue>(options),
"nodelist" => jsonDocument.Deserialize<NodeListRemoteValue>(options),
"htmlcollection" => jsonDocument.Deserialize<HtmlCollectionRemoteValue>(options),
"node" => jsonDocument.Deserialize<NodeRemoteValue>(options),
"window" => jsonDocument.Deserialize<WindowProxyRemoteValue>(options),
_ => null,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ public record LocateNodesOptions : CommandOptions
public IEnumerable<Script.ISharedReference>? StartNodes { get; set; }
}

public record LocateNodesResult : IReadOnlyList<Script.RemoteValue.Node>
public record LocateNodesResult : IReadOnlyList<Script.NodeRemoteValue>
{
private readonly IReadOnlyList<Script.RemoteValue.Node> _nodes;
private readonly IReadOnlyList<Script.NodeRemoteValue> _nodes;

internal LocateNodesResult(IReadOnlyList<Script.RemoteValue.Node> nodes)
internal LocateNodesResult(IReadOnlyList<Script.NodeRemoteValue> nodes)
{
_nodes = nodes;
}

public Script.RemoteValue.Node this[int index] => _nodes[index];
public Script.NodeRemoteValue this[int index] => _nodes[index];

public int Count => _nodes.Count;

public IEnumerator<Script.RemoteValue.Node> GetEnumerator() => _nodes.GetEnumerator();
public IEnumerator<Script.NodeRemoteValue> GetEnumerator() => _nodes.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => (_nodes as IEnumerable).GetEnumerator();
}
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public record NodeProperties(long NodeType, long ChildNodeCount)
public IReadOnlyDictionary<string, string>? Attributes { get; internal set; }

[JsonInclude]
public IReadOnlyList<RemoteValue.Node>? Children { get; internal set; }
public IReadOnlyList<NodeRemoteValue>? Children { get; internal set; }

[JsonInclude]
public string? LocalName { get; internal set; }
Expand All @@ -43,5 +43,5 @@ public record NodeProperties(long NodeType, long ChildNodeCount)
public string? NodeValue { get; internal set; }

[JsonInclude]
public RemoteValue.Node? ShadowRoot { get; internal set; }
public NodeRemoteValue? ShadowRoot { get; internal set; }
}
Loading
Loading