Bug 1698704 - Return early if the created NSURL is nil. r=mac-reviewers,bradwerth

This achieves the same as the previous code, but without an Objective C exception.
Before this patch, we could have called [NSArray arrayWithObject:nil], which would
have thrown an exception, which we would then have caught and turned into NS_ERROR_FAILURE.

Differential Revision: https://phabricator.services.mozilla.com/D108556
This commit is contained in:
Markus Stange 2021-03-16 17:56:35 +00:00
parent 2bb63845fa
commit 189716e23c

View File

@ -101,12 +101,15 @@ nsresult nsMacSharingService::GetSharingProviders(const nsAString& aPageUrl, JSC
JS::MutableHandleValue aResult) {
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
NSURL* url = [NSURL URLWithString:nsCocoaUtils::ToNSString(aPageUrl)];
if (!url) {
// aPageUrl is not a valid URL.
return NS_ERROR_FAILURE;
}
NSArray* sharingService =
[NSSharingService sharingServicesForItems:[NSArray arrayWithObject:url]];
NSArray* sharingService = [NSSharingService sharingServicesForItems:@[ url ]];
int32_t serviceCount = 0;
JS::Rooted<JSObject*> array(aCx, JS::NewArrayObject(aCx, 0));
for (NSSharingService* currentService in sharingService) {
if (ShouldIgnoreProvider([currentService name])) {