Skip to content

Commit

Permalink
[webkit] Add nullability to (generated and manual) bindings (#15028)
Browse files Browse the repository at this point in the history
* Adding nullable enable

* throw better exceptions

* use is null

* fix messages on throw exceptions

* throw ObjectDisposedException

* throw another ObjectDisposedException

Co-authored-by: TJ Lambert <tjlambert@microsoft.com>
  • Loading branch information
tj-devel709 and TJ Lambert authored Jun 17, 2022
1 parent a1e53d6 commit 893cd77
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/WebKit/DomCssRuleList.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

namespace WebKit {

public partial class DomCssRuleList {
Expand Down
2 changes: 2 additions & 0 deletions src/WebKit/DomHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;
using ObjCRuntime;
using Foundation;
Expand Down
10 changes: 6 additions & 4 deletions src/WebKit/DomNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#nullable enable

using System;
using System.Runtime.Versioning;

Expand Down Expand Up @@ -77,8 +79,8 @@ public IDomEventListener AddEventListener (string type, DomEventListenerHandler
public DomEventListener AddEventListener (string type, DomEventListenerHandler handler, bool useCapture)
#endif
{
if (handler == null)
throw new ArgumentNullException ("handler");
if (handler is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (handler));
var obj = new DomNodeEventProxy (this, handler);
AddEventListener (type, obj, useCapture);
return obj;
Expand All @@ -90,8 +92,8 @@ public IDomEventListener AddEventListener (string type, Action<DomEvent> callbac
public DomEventListener AddEventListener (string type, Action<DomEvent> callback, bool useCapture)
#endif
{
if (callback == null)
throw new ArgumentNullException ("callback");
if (callback is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback));
var obj = new DomNodeEventProxy2 (callback);
AddEventListener (type, obj, useCapture);
return obj;
Expand Down
10 changes: 8 additions & 2 deletions src/WebKit/Enumerators.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;
using System.Collections;
using System.Collections.Generic;
Expand All @@ -24,23 +26,27 @@ public void Dispose () {

public T Current {
get {
if (_container is null)
throw new ObjectDisposedException (nameof (_container));
return _container [_index];
}
}

object IEnumerator.Current {
object? IEnumerator.Current {
get { return ((IEnumerator<T>) this).Current; }
}

public bool MoveNext () {
if (_container is null)
throw new ObjectDisposedException (nameof (_container));
return ++_index < _container.Count;
}

public void Reset () {
_index = -1;
}

IIndexedContainer<T> _container;
IIndexedContainer<T>? _container;
int _index;
}

Expand Down
2 changes: 2 additions & 0 deletions src/WebKit/Indexers.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

namespace WebKit {

public partial class DomCssRuleList {
Expand Down
2 changes: 2 additions & 0 deletions src/WebKit/WebKit.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using Foundation;

namespace WebKit {
Expand Down
8 changes: 5 additions & 3 deletions src/WebKit/WebNavigationPolicyEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
// Copyright 2013 Xamarin Inc

#nullable enable

using System;

using Foundation;
Expand All @@ -27,14 +29,14 @@ public WebNavigationType NavigationType {
get { return (WebNavigationType)((NSNumber)ActionInformation[WebPolicyDelegate.WebActionNavigationTypeKey]).Int32Value; }
}

public NSDictionary ElementInfo {
public NSDictionary? ElementInfo {
get { return ActionInformation[WebPolicyDelegate.WebActionElementKey] as NSDictionary; }
}

public WebActionMouseButton MouseButton {
get {
var number = ActionInformation[WebPolicyDelegate.WebActionButtonKey] as NSNumber;
if (number == null) {
if (number is null) {
return WebActionMouseButton.None;
}

Expand All @@ -46,7 +48,7 @@ public uint Flags {
get { return ((NSNumber)ActionInformation[WebPolicyDelegate.WebActionModifierFlagsKey]).UInt32Value; }
}

public NSUrl OriginalUrl {
public NSUrl? OriginalUrl {
get { return ActionInformation[WebPolicyDelegate.WebActionOriginalUrlKey] as NSUrl; }
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/WebKit/WebPolicyDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#nullable enable

using System;
using Foundation;
using ObjCRuntime;
Expand All @@ -33,24 +36,24 @@ public partial class WebPolicyDelegate {

public static void DecideUse (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("token");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));

ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selUse);
}

public static void DecideDownload (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("decisionToken");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));

ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selDownload);
}

public static void DecideIgnore (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("decisionToken");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));

ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selIgnore);
}
Expand Down
15 changes: 9 additions & 6 deletions src/WebKit/WebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#nullable enable

using System;
using Foundation;
using ObjCRuntime;
Expand All @@ -33,24 +36,24 @@ public partial class WebView {

public static void DecideUse (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("token");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));

ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selUse);
}

public static void DecideDownload (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("decisionToken");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));

ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selDownload);
}

public static void DecideIgnore (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("decisionToken");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));

ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selIgnore);
}
Expand Down

4 comments on commit 893cd77

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: 893cd7750366c55755fb9e8874d357aec0cce30b [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: 893cd7750366c55755fb9e8874d357aec0cce30b [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMMINI-053.Monterey'
Hash: 893cd7750366c55755fb9e8874d357aec0cce30b [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

11 tests failed, 223 tests passed.

Failed tests

  • Xtro/Legacy Xamarin: Failed (Test run failed.)
  • fsharp/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemNumericsTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemXmlTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemDataTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemWebServicesTests/watchOS 32-bits - simulator/Debug: Crashed
  • [xUnit] Mono SystemLinqXunit/watchOS 32-bits - simulator/Debug: Crashed
  • [xUnit] Mono MicrosoftCSharpXunit/watchOS 32-bits - simulator/Debug: Crashed
  • mscorlib Part 1/watchOS 32-bits - simulator/Debug: Crashed
  • mscorlib Part 3/watchOS 32-bits - simulator/Debug: Crashed
  • [xUnit] Mono SystemCoreXunit Part 2/watchOS 32-bits - simulator/Debug: Crashed

Pipeline on Agent XAMBOT-1109.Monterey'
[webkit] Add nullability to (generated and manual) bindings (#15028)

Please sign in to comment.