Skip to content

Commit 572b087

Browse files
[dotnet] Annotate nullability on JavaScript protocol (#15238)
1 parent 9b0ccf1 commit 572b087

File tree

5 files changed

+53
-39
lines changed

5 files changed

+53
-39
lines changed

dotnet/src/webdriver/DevTools/JavaScript.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using System;
2121
using System.Threading.Tasks;
2222

23+
#nullable enable
24+
2325
namespace OpenQA.Selenium.DevTools
2426
{
2527
/// <summary>
@@ -30,17 +32,17 @@ public abstract class JavaScript
3032
/// <summary>
3133
/// Occurs when a JavaScript script binding is called.
3234
/// </summary>
33-
public event EventHandler<BindingCalledEventArgs> BindingCalled;
35+
public event EventHandler<BindingCalledEventArgs>? BindingCalled;
3436

3537
/// <summary>
3638
/// Occurs when the browser's JavaScript console API is called.
3739
/// </summary>
38-
public event EventHandler<ConsoleApiCalledEventArgs> ConsoleApiCalled;
40+
public event EventHandler<ConsoleApiCalledEventArgs>? ConsoleApiCalled;
3941

4042
/// <summary>
4143
/// Occurs when a JavaScript exception is thrown.
4244
/// </summary>
43-
public event EventHandler<ExceptionThrownEventArgs> ExceptionThrown;
45+
public event EventHandler<ExceptionThrownEventArgs>? ExceptionThrown;
4446

4547
/// <summary>
4648
/// Asynchronously enables the Runtime domain in the DevTools Protocol.

dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@
2323
using System.Collections.Generic;
2424
using System.Threading.Tasks;
2525

26+
#nullable enable
27+
2628
namespace OpenQA.Selenium.DevTools.V130
2729
{
2830
/// <summary>
2931
/// Class containing the JavaScript implementation for version 130 of the DevTools Protocol.
3032
/// </summary>
3133
public class V130JavaScript : JavaScript
3234
{
33-
private RuntimeAdapter runtime;
34-
private PageAdapter page;
35+
private readonly RuntimeAdapter runtime;
36+
private readonly PageAdapter page;
3537

3638
/// <summary>
3739
/// Initializes a new instance of the <see cref="V130JavaScript"/> class.
3840
/// </summary>
3941
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
4042
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
43+
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
4144
public V130JavaScript(RuntimeAdapter runtime, PageAdapter page)
4245
{
43-
this.runtime = runtime;
44-
this.page = page;
46+
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
47+
this.page = page ?? throw new ArgumentNullException(nameof(page));
4548
this.runtime.BindingCalled += OnRuntimeBindingCalled;
4649
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
4750
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
@@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
138141
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
139142
}
140143

141-
private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
144+
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
142145
{
143146
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
144147
(
@@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
150153
this.OnBindingCalled(wrapped);
151154
}
152155

153-
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
156+
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
154157
{
155158
// TODO: Collect stack trace elements
156159
var wrapped = new ExceptionThrownEventArgs
@@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
162165
this.OnExceptionThrown(wrapped);
163166
}
164167

165-
private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
168+
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
166169
{
167-
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
170+
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
168171
foreach (var arg in e.Args)
169172
{
170-
string argValue = arg.Value?.ToString();
173+
string? argValue = arg.Value?.ToString();
171174
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
172175
}
173176

dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@
2323
using System.Collections.Generic;
2424
using System.Threading.Tasks;
2525

26+
#nullable enable
27+
2628
namespace OpenQA.Selenium.DevTools.V131
2729
{
2830
/// <summary>
2931
/// Class containing the JavaScript implementation for version 131 of the DevTools Protocol.
3032
/// </summary>
3133
public class V131JavaScript : JavaScript
3234
{
33-
private RuntimeAdapter runtime;
34-
private PageAdapter page;
35+
private readonly RuntimeAdapter runtime;
36+
private readonly PageAdapter page;
3537

3638
/// <summary>
3739
/// Initializes a new instance of the <see cref="V131JavaScript"/> class.
3840
/// </summary>
3941
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
4042
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
43+
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
4144
public V131JavaScript(RuntimeAdapter runtime, PageAdapter page)
4245
{
43-
this.runtime = runtime;
44-
this.page = page;
46+
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
47+
this.page = page ?? throw new ArgumentNullException(nameof(page));
4548
this.runtime.BindingCalled += OnRuntimeBindingCalled;
4649
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
4750
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
@@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
138141
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
139142
}
140143

141-
private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
144+
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
142145
{
143146
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
144147
(
@@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
150153
this.OnBindingCalled(wrapped);
151154
}
152155

153-
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
156+
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
154157
{
155158
// TODO: Collect stack trace elements
156159
var wrapped = new ExceptionThrownEventArgs
@@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
162165
this.OnExceptionThrown(wrapped);
163166
}
164167

165-
private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
168+
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
166169
{
167-
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
170+
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
168171
foreach (var arg in e.Args)
169172
{
170-
string argValue = arg.Value?.ToString();
173+
string? argValue = arg.Value?.ToString();
171174
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
172175
}
173176

dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@
2323
using System.Collections.Generic;
2424
using System.Threading.Tasks;
2525

26+
#nullable enable
27+
2628
namespace OpenQA.Selenium.DevTools.V132
2729
{
2830
/// <summary>
2931
/// Class containing the JavaScript implementation for version 132 of the DevTools Protocol.
3032
/// </summary>
3133
public class V132JavaScript : JavaScript
3234
{
33-
private RuntimeAdapter runtime;
34-
private PageAdapter page;
35+
private readonly RuntimeAdapter runtime;
36+
private readonly PageAdapter page;
3537

3638
/// <summary>
3739
/// Initializes a new instance of the <see cref="V132JavaScript"/> class.
3840
/// </summary>
3941
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
4042
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
43+
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
4144
public V132JavaScript(RuntimeAdapter runtime, PageAdapter page)
4245
{
43-
this.runtime = runtime;
44-
this.page = page;
46+
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
47+
this.page = page ?? throw new ArgumentNullException(nameof(page));
4548
this.runtime.BindingCalled += OnRuntimeBindingCalled;
4649
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
4750
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
@@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
138141
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
139142
}
140143

141-
private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
144+
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
142145
{
143146
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
144147
(
@@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
150153
this.OnBindingCalled(wrapped);
151154
}
152155

153-
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
156+
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
154157
{
155158
// TODO: Collect stack trace elements
156159
var wrapped = new ExceptionThrownEventArgs
@@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
162165
this.OnExceptionThrown(wrapped);
163166
}
164167

165-
private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
168+
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
166169
{
167-
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
170+
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
168171
foreach (var arg in e.Args)
169172
{
170-
string argValue = arg.Value?.ToString();
173+
string? argValue = arg.Value?.ToString();
171174
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
172175
}
173176

dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@
2323
using System.Collections.Generic;
2424
using System.Threading.Tasks;
2525

26+
#nullable enable
27+
2628
namespace OpenQA.Selenium.DevTools.V85
2729
{
2830
/// <summary>
2931
/// Class containing the JavaScript implementation for version 86 of the DevTools Protocol.
3032
/// </summary>
3133
public class V85JavaScript : JavaScript
3234
{
33-
private RuntimeAdapter runtime;
34-
private PageAdapter page;
35+
private readonly RuntimeAdapter runtime;
36+
private readonly PageAdapter page;
3537

3638
/// <summary>
3739
/// Initializes a new instance of the <see cref="V85JavaScript"/> class.
3840
/// </summary>
3941
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
4042
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
43+
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
4144
public V85JavaScript(RuntimeAdapter runtime, PageAdapter page)
4245
{
43-
this.runtime = runtime;
44-
this.page = page;
46+
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
47+
this.page = page ?? throw new ArgumentNullException(nameof(page));
4548
this.runtime.BindingCalled += OnRuntimeBindingCalled;
4649
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
4750
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
@@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
138141
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
139142
}
140143

141-
private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
144+
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
142145
{
143146
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
144147
(
@@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
150153
this.OnBindingCalled(wrapped);
151154
}
152155

153-
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
156+
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
154157
{
155158
// TODO: Collect stack trace elements
156159
var wrapped = new ExceptionThrownEventArgs
@@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
162165
this.OnExceptionThrown(wrapped);
163166
}
164167

165-
private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
168+
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
166169
{
167-
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
170+
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
168171
foreach (var arg in e.Args)
169172
{
170-
string argValue = arg.Value?.ToString();
173+
string? argValue = arg.Value?.ToString();
171174
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
172175
}
173176

0 commit comments

Comments
 (0)