From a7a8b4742201e326bde784284be9d4d6f1fced9d Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 5 Feb 2025 15:06:21 -0500 Subject: [PATCH] [dotnet] Annotate nullability on `JavaScript` protocol --- dotnet/src/webdriver/DevTools/JavaScript.cs | 8 ++++--- .../webdriver/DevTools/v130/V130JavaScript.cs | 21 +++++++++++-------- .../webdriver/DevTools/v131/V131JavaScript.cs | 21 +++++++++++-------- .../webdriver/DevTools/v132/V132JavaScript.cs | 21 +++++++++++-------- .../webdriver/DevTools/v85/V85JavaScript.cs | 21 +++++++++++-------- 5 files changed, 53 insertions(+), 39 deletions(-) diff --git a/dotnet/src/webdriver/DevTools/JavaScript.cs b/dotnet/src/webdriver/DevTools/JavaScript.cs index d907b66f777ba..5af95f6df15b2 100644 --- a/dotnet/src/webdriver/DevTools/JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/JavaScript.cs @@ -20,6 +20,8 @@ using System; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -30,17 +32,17 @@ public abstract class JavaScript /// /// Occurs when a JavaScript script binding is called. /// - public event EventHandler BindingCalled; + public event EventHandler? BindingCalled; /// /// Occurs when the browser's JavaScript console API is called. /// - public event EventHandler ConsoleApiCalled; + public event EventHandler? ConsoleApiCalled; /// /// Occurs when a JavaScript exception is thrown. /// - public event EventHandler ExceptionThrown; + public event EventHandler? ExceptionThrown; /// /// Asynchronously enables the Runtime domain in the DevTools Protocol. diff --git a/dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs b/dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs index 3f5946ed51033..db6d4300720ab 100644 --- a/dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs @@ -23,6 +23,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools.V130 { /// @@ -30,18 +32,19 @@ namespace OpenQA.Selenium.DevTools.V130 /// public class V130JavaScript : JavaScript { - private RuntimeAdapter runtime; - private PageAdapter page; + private readonly RuntimeAdapter runtime; + private readonly PageAdapter page; /// /// Initializes a new instance of the class. /// /// The DevTools Protocol adapter for the Runtime domain. /// The DevTools Protocol adapter for the Page domain. + /// If or are . 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; @@ -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 ( @@ -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 @@ -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 args = new List(); + List args = new List(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)); } diff --git a/dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs b/dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs index d523202a85086..fe3cdcaf0c986 100644 --- a/dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs @@ -23,6 +23,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools.V131 { /// @@ -30,18 +32,19 @@ namespace OpenQA.Selenium.DevTools.V131 /// public class V131JavaScript : JavaScript { - private RuntimeAdapter runtime; - private PageAdapter page; + private readonly RuntimeAdapter runtime; + private readonly PageAdapter page; /// /// Initializes a new instance of the class. /// /// The DevTools Protocol adapter for the Runtime domain. /// The DevTools Protocol adapter for the Page domain. + /// If or are . 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; @@ -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 ( @@ -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 @@ -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 args = new List(); + List args = new List(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)); } diff --git a/dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs b/dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs index edbcdab9280a9..bf9f0dc4b8bb8 100644 --- a/dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs @@ -23,6 +23,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools.V132 { /// @@ -30,18 +32,19 @@ namespace OpenQA.Selenium.DevTools.V132 /// public class V132JavaScript : JavaScript { - private RuntimeAdapter runtime; - private PageAdapter page; + private readonly RuntimeAdapter runtime; + private readonly PageAdapter page; /// /// Initializes a new instance of the class. /// /// The DevTools Protocol adapter for the Runtime domain. /// The DevTools Protocol adapter for the Page domain. + /// If or are . 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; @@ -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 ( @@ -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 @@ -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 args = new List(); + List args = new List(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)); } diff --git a/dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs b/dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs index 7a9cfbab234c5..67066364032d0 100644 --- a/dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs @@ -23,6 +23,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools.V85 { /// @@ -30,18 +32,19 @@ namespace OpenQA.Selenium.DevTools.V85 /// public class V85JavaScript : JavaScript { - private RuntimeAdapter runtime; - private PageAdapter page; + private readonly RuntimeAdapter runtime; + private readonly PageAdapter page; /// /// Initializes a new instance of the class. /// /// The DevTools Protocol adapter for the Runtime domain. /// The DevTools Protocol adapter for the Page domain. + /// If or are . 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; @@ -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 ( @@ -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 @@ -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 args = new List(); + List args = new List(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)); }