Skip to content
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

[dotnet] Annotate nullability on JavaScript protocol #15238

Merged
merged 1 commit into from
Feb 6, 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
8 changes: 5 additions & 3 deletions dotnet/src/webdriver/DevTools/JavaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using System;
using System.Threading.Tasks;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
Expand All @@ -30,17 +32,17 @@ public abstract class JavaScript
/// <summary>
/// Occurs when a JavaScript script binding is called.
/// </summary>
public event EventHandler<BindingCalledEventArgs> BindingCalled;
public event EventHandler<BindingCalledEventArgs>? BindingCalled;

/// <summary>
/// Occurs when the browser's JavaScript console API is called.
/// </summary>
public event EventHandler<ConsoleApiCalledEventArgs> ConsoleApiCalled;
public event EventHandler<ConsoleApiCalledEventArgs>? ConsoleApiCalled;

/// <summary>
/// Occurs when a JavaScript exception is thrown.
/// </summary>
public event EventHandler<ExceptionThrownEventArgs> ExceptionThrown;
public event EventHandler<ExceptionThrownEventArgs>? ExceptionThrown;

/// <summary>
/// Asynchronously enables the Runtime domain in the DevTools Protocol.
Expand Down
21 changes: 12 additions & 9 deletions dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;

#nullable enable

namespace OpenQA.Selenium.DevTools.V130
{
/// <summary>
/// Class containing the JavaScript implementation for version 130 of the DevTools Protocol.
/// </summary>
public class V130JavaScript : JavaScript
{
private RuntimeAdapter runtime;
private PageAdapter page;
private readonly RuntimeAdapter runtime;
private readonly PageAdapter page;

/// <summary>
/// Initializes a new instance of the <see cref="V130JavaScript"/> class.
/// </summary>
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
public V130JavaScript(RuntimeAdapter runtime, PageAdapter page)
{
this.runtime = runtime;
this.page = page;
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
this.page = page ?? throw new ArgumentNullException(nameof(page));
this.runtime.BindingCalled += OnRuntimeBindingCalled;
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
Expand Down Expand Up @@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
}

private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
{
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
(
Expand All @@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
this.OnBindingCalled(wrapped);
}

private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
{
// TODO: Collect stack trace elements
var wrapped = new ExceptionThrownEventArgs
Expand All @@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
this.OnExceptionThrown(wrapped);
}

private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
{
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
foreach (var arg in e.Args)
{
string argValue = arg.Value?.ToString();
string? argValue = arg.Value?.ToString();
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
}

Expand Down
21 changes: 12 additions & 9 deletions dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;

#nullable enable

namespace OpenQA.Selenium.DevTools.V131
{
/// <summary>
/// Class containing the JavaScript implementation for version 131 of the DevTools Protocol.
/// </summary>
public class V131JavaScript : JavaScript
{
private RuntimeAdapter runtime;
private PageAdapter page;
private readonly RuntimeAdapter runtime;
private readonly PageAdapter page;

/// <summary>
/// Initializes a new instance of the <see cref="V131JavaScript"/> class.
/// </summary>
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
public V131JavaScript(RuntimeAdapter runtime, PageAdapter page)
{
this.runtime = runtime;
this.page = page;
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
this.page = page ?? throw new ArgumentNullException(nameof(page));
this.runtime.BindingCalled += OnRuntimeBindingCalled;
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
Expand Down Expand Up @@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
}

private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
{
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
(
Expand All @@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
this.OnBindingCalled(wrapped);
}

private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
{
// TODO: Collect stack trace elements
var wrapped = new ExceptionThrownEventArgs
Expand All @@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
this.OnExceptionThrown(wrapped);
}

private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
{
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
foreach (var arg in e.Args)
{
string argValue = arg.Value?.ToString();
string? argValue = arg.Value?.ToString();
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
}

Expand Down
21 changes: 12 additions & 9 deletions dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;

#nullable enable

namespace OpenQA.Selenium.DevTools.V132
{
/// <summary>
/// Class containing the JavaScript implementation for version 132 of the DevTools Protocol.
/// </summary>
public class V132JavaScript : JavaScript
{
private RuntimeAdapter runtime;
private PageAdapter page;
private readonly RuntimeAdapter runtime;
private readonly PageAdapter page;

/// <summary>
/// Initializes a new instance of the <see cref="V132JavaScript"/> class.
/// </summary>
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
public V132JavaScript(RuntimeAdapter runtime, PageAdapter page)
{
this.runtime = runtime;
this.page = page;
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
this.page = page ?? throw new ArgumentNullException(nameof(page));
this.runtime.BindingCalled += OnRuntimeBindingCalled;
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
Expand Down Expand Up @@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
}

private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
{
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
(
Expand All @@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
this.OnBindingCalled(wrapped);
}

private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
{
// TODO: Collect stack trace elements
var wrapped = new ExceptionThrownEventArgs
Expand All @@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
this.OnExceptionThrown(wrapped);
}

private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
{
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
foreach (var arg in e.Args)
{
string argValue = arg.Value?.ToString();
string? argValue = arg.Value?.ToString();
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
}

Expand Down
21 changes: 12 additions & 9 deletions dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;

#nullable enable

namespace OpenQA.Selenium.DevTools.V85
{
/// <summary>
/// Class containing the JavaScript implementation for version 86 of the DevTools Protocol.
/// </summary>
public class V85JavaScript : JavaScript
{
private RuntimeAdapter runtime;
private PageAdapter page;
private readonly RuntimeAdapter runtime;
private readonly PageAdapter page;

/// <summary>
/// Initializes a new instance of the <see cref="V85JavaScript"/> class.
/// </summary>
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
public V85JavaScript(RuntimeAdapter runtime, PageAdapter page)
{
this.runtime = runtime;
this.page = page;
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
this.page = page ?? throw new ArgumentNullException(nameof(page));
this.runtime.BindingCalled += OnRuntimeBindingCalled;
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
Expand Down Expand Up @@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
}

private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
{
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
(
Expand All @@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
this.OnBindingCalled(wrapped);
}

private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
{
// TODO: Collect stack trace elements
var wrapped = new ExceptionThrownEventArgs
Expand All @@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
this.OnExceptionThrown(wrapped);
}

private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
{
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
foreach (var arg in e.Args)
{
string argValue = arg.Value?.ToString();
string? argValue = arg.Value?.ToString();
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
}

Expand Down
Loading