Skip to content

Commit f31fe5e

Browse files
committed
Bug 1619112 part 3. Pass UTF8 strings to MaybeRejectWithType/RangeError promise methods. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D65539 --HG-- extra : moz-landing-system : lando
1 parent c878a8b commit f31fe5e

File tree

13 files changed

+45
-45
lines changed

13 files changed

+45
-45
lines changed

dom/base/Document.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12910,7 +12910,7 @@ class PendingFullscreenChangeList {
1291012910
// Always automatically drop fullscreen changes which are
1291112911
// from a document detached from the doc shell.
1291212912
UniquePtr<T> change = TakeAndNextInternal();
12913-
change->MayRejectPromise(u"Document is not active");
12913+
change->MayRejectPromise("Document is not active");
1291412914
continue;
1291512915
}
1291612916
while (docShell && docShell != mRootShellForIteration) {
@@ -13155,11 +13155,11 @@ void Document::RestorePreviousFullscreenState(UniquePtr<FullscreenExit> aExit) {
1315513155
"Should have at least 1 fullscreen root when fullscreen!");
1315613156

1315713157
if (!GetWindow()) {
13158-
aExit->MayRejectPromise(u"No active window");
13158+
aExit->MayRejectPromise("No active window");
1315913159
return;
1316013160
}
1316113161
if (!FullscreenStackTop() || FullscreenRoots::IsEmpty()) {
13162-
aExit->MayRejectPromise(u"Not in fullscreen mode");
13162+
aExit->MayRejectPromise("Not in fullscreen mode");
1316313163
return;
1316413164
}
1316513165

@@ -13531,7 +13531,7 @@ bool Document::FullscreenElementReadyCheck(FullscreenRequest& aRequest) {
1353113531
nsFocusManager* fm = nsFocusManager::GetFocusManager();
1353213532
if (!fm) {
1353313533
NS_WARNING("Failed to retrieve focus manager in fullscreen request.");
13534-
aRequest.MayRejectPromise(u"An unexpected error occurred");
13534+
aRequest.MayRejectPromise("An unexpected error occurred");
1353513535
return false;
1353613536
}
1353713537
if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(
@@ -13587,7 +13587,7 @@ void Document::RequestFullscreen(UniquePtr<FullscreenRequest> aRequest,
1358713587
bool applyFullScreenDirectly) {
1358813588
nsCOMPtr<nsPIDOMWindowOuter> rootWin = GetRootWindow(this);
1358913589
if (!rootWin) {
13590-
aRequest->MayRejectPromise(u"No active window");
13590+
aRequest->MayRejectPromise("No active window");
1359113591
return;
1359213592
}
1359313593

@@ -13645,7 +13645,7 @@ static void ClearPendingFullscreenRequests(Document* aDoc) {
1364513645
aDoc, PendingFullscreenChangeList::eInclusiveDescendants);
1364613646
while (!iter.AtEnd()) {
1364713647
UniquePtr<FullscreenRequest> request = iter.TakeAndNext();
13648-
request->MayRejectPromise(u"Fullscreen request aborted");
13648+
request->MayRejectPromise("Fullscreen request aborted");
1364913649
}
1365013650
}
1365113651

dom/base/FullscreenChange.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ class FullscreenChange : public LinkedListElement<FullscreenChange> {
4141
}
4242
}
4343

44-
void MayRejectPromise(const nsAString& aMessage) {
44+
void MayRejectPromise(const nsACString& aMessage) {
4545
if (mPromise) {
4646
MOZ_ASSERT(mPromise->State() == Promise::PromiseState::Pending);
4747
mPromise->MaybeRejectWithTypeError(aMessage);
4848
}
4949
}
5050
template <int N>
51-
void MayRejectPromise(const char16_t (&aMessage)[N]) {
52-
MayRejectPromise(nsLiteralString(aMessage));
51+
void MayRejectPromise(const char (&aMessage)[N]) {
52+
MayRejectPromise(nsLiteralCString(aMessage));
5353
}
5454

5555
protected:
@@ -102,7 +102,7 @@ class FullscreenRequest : public FullscreenChange {
102102
presContext->RefreshDriver()->ScheduleFullscreenEvent(
103103
std::move(pendingEvent));
104104
}
105-
MayRejectPromise(u"Fullscreen request denied");
105+
MayRejectPromise("Fullscreen request denied");
106106
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
107107
NS_LITERAL_CSTRING("DOM"), Document(),
108108
nsContentUtils::eDOM_PROPERTIES, aReason);

dom/base/Navigator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ void Navigator::FinishGetVRDisplays(bool isWebVRSupportedInwindow, Promise* p) {
15281528
// The Window has been torn down, so there is no further work that can
15291529
// be done.
15301530
p->MaybeRejectWithTypeError(
1531-
u"Unable to return VRDisplays for a closed window.");
1531+
"Unable to return VRDisplays for a closed window.");
15321532
return;
15331533
}
15341534

@@ -1544,7 +1544,7 @@ void Navigator::OnXRPermissionRequestAllow() {
15441544
if (!VRDisplay::RefreshVRDisplays(win->WindowID())) {
15451545
for (auto& p : mVRGetDisplaysPromises) {
15461546
// Failed to refresh, reject the promise now
1547-
p->MaybeRejectWithTypeError(u"Failed to find attached VR displays.");
1547+
p->MaybeRejectWithTypeError("Failed to find attached VR displays.");
15481548
}
15491549
}
15501550
}

dom/cache/CacheOpChild.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mozilla::ipc::IPCResult CacheOpChild::Recv__delete__(
138138
MOZ_DIAGNOSTIC_ASSERT(actor);
139139
if (!actor) {
140140
mPromise->MaybeRejectWithTypeError(
141-
u"CacheStorage.open() failed to access the storage system.");
141+
"CacheStorage.open() failed to access the storage system.");
142142
break;
143143
}
144144

dom/media/eme/DetailedPromise.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,29 @@ class DetailedPromise : public Promise {
6161
template <ErrNum errorNumber, typename... Ts>
6262
void MaybeRejectWithTypeError(Ts&&... aMessageArgs) = delete;
6363

64-
inline void MaybeRejectWithTypeError(const nsAString& aMessage) {
64+
inline void MaybeRejectWithTypeError(const nsACString& aMessage) {
6565
ErrorResult res;
6666
res.ThrowTypeError(aMessage);
67-
MaybeReject(std::move(res), NS_ConvertUTF16toUTF8(aMessage));
67+
MaybeReject(std::move(res), aMessage);
6868
}
6969

7070
template <int N>
71-
void MaybeRejectWithTypeError(const char16_t (&aMessage)[N]) {
72-
MaybeRejectWithTypeError(nsLiteralString(aMessage));
71+
void MaybeRejectWithTypeError(const char (&aMessage)[N]) {
72+
MaybeRejectWithTypeError(nsLiteralCString(aMessage));
7373
}
7474

7575
template <ErrNum errorNumber, typename... Ts>
7676
void MaybeRejectWithRangeError(Ts&&... aMessageArgs) = delete;
7777

78-
inline void MaybeRejectWithRangeError(const nsAString& aMessage) {
78+
inline void MaybeRejectWithRangeError(const nsACString& aMessage) {
7979
ErrorResult res;
8080
res.ThrowRangeError(aMessage);
81-
MaybeReject(std::move(res), NS_ConvertUTF16toUTF8(aMessage));
81+
MaybeReject(std::move(res), aMessage);
8282
}
8383

8484
template <int N>
85-
void MaybeRejectWithRangeError(const char16_t (&aMessage)[N]) {
86-
MaybeRejectWithRangeError(nsLiteralString(aMessage));
85+
void MaybeRejectWithRangeError(const char (&aMessage)[N]) {
86+
MaybeRejectWithRangeError(nsLiteralCString(aMessage));
8787
}
8888

8989
private:

dom/media/eme/MediaKeySession.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ already_AddRefed<Promise> MediaKeySession::GenerateRequest(
228228
// with a newly created TypeError.
229229
if (aInitDataType.IsEmpty()) {
230230
promise->MaybeRejectWithTypeError(
231-
u"Empty initDataType passed to MediaKeySession.generateRequest()");
231+
"Empty initDataType passed to MediaKeySession.generateRequest()");
232232
EME_LOG(
233233
"MediaKeySession[%p,'%s'] GenerateRequest() failed, empty initDataType",
234234
this, NS_ConvertUTF16toUTF8(mSessionId).get());
@@ -241,7 +241,7 @@ already_AddRefed<Promise> MediaKeySession::GenerateRequest(
241241
CopyArrayBufferViewOrArrayBufferData(aInitData, data);
242242
if (data.IsEmpty()) {
243243
promise->MaybeRejectWithTypeError(
244-
u"Empty initData passed to MediaKeySession.generateRequest()");
244+
"Empty initData passed to MediaKeySession.generateRequest()");
245245
EME_LOG("MediaKeySession[%p,'%s'] GenerateRequest() failed, empty initData",
246246
this, NS_ConvertUTF16toUTF8(mSessionId).get());
247247
return promise.forget();
@@ -277,7 +277,7 @@ already_AddRefed<Promise> MediaKeySession::GenerateRequest(
277277
// If the preceding step failed, reject promise with a newly created
278278
// TypeError.
279279
promise->MaybeRejectWithTypeError(
280-
u"initData sanitization failed in MediaKeySession.generateRequest()");
280+
"initData sanitization failed in MediaKeySession.generateRequest()");
281281
EME_LOG(
282282
"MediaKeySession[%p,'%s'] GenerateRequest() initData sanitization "
283283
"failed",
@@ -344,7 +344,7 @@ already_AddRefed<Promise> MediaKeySession::Load(const nsAString& aSessionId,
344344
// created TypeError.
345345
if (aSessionId.IsEmpty()) {
346346
promise->MaybeRejectWithTypeError(
347-
u"Trying to load a session with empty session ID");
347+
"Trying to load a session with empty session ID");
348348
// "The sessionId parameter is empty."
349349
EME_LOG("MediaKeySession[%p,''] Load() failed, no sessionId", this);
350350
return promise.forget();
@@ -355,7 +355,7 @@ already_AddRefed<Promise> MediaKeySession::Load(const nsAString& aSessionId,
355355
// a newly created TypeError.
356356
if (mSessionType == MediaKeySessionType::Temporary) {
357357
promise->MaybeRejectWithTypeError(
358-
u"Trying to load() into a non-persistent session");
358+
"Trying to load() into a non-persistent session");
359359
EME_LOG(
360360
"MediaKeySession[%p,''] Load() failed, can't load in a non-persistent "
361361
"session",
@@ -416,7 +416,7 @@ already_AddRefed<Promise> MediaKeySession::Update(
416416
CopyArrayBufferViewOrArrayBufferData(aResponse, data);
417417
if (data.IsEmpty()) {
418418
promise->MaybeRejectWithTypeError(
419-
u"Empty response buffer passed to MediaKeySession.update()");
419+
"Empty response buffer passed to MediaKeySession.update()");
420420
EME_LOG("MediaKeySession[%p,'%s'] Update() failed, empty response buffer",
421421
this, NS_ConvertUTF16toUTF8(mSessionId).get());
422422
return promise.forget();

dom/media/eme/MediaKeySystemAccessManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void MediaKeySystemAccessManager::PendingRequest::
6262
}
6363

6464
void MediaKeySystemAccessManager::PendingRequest::RejectPromiseWithTypeError(
65-
const nsAString& aReason) {
65+
const nsACString& aReason) {
6666
if (mPromise) {
6767
mPromise->MaybeRejectWithTypeError(aReason);
6868
}
@@ -146,7 +146,7 @@ void MediaKeySystemAccessManager::CheckDoesWindowSupportProtectedMedia(
146146
// In this case, there is no browser because the Navigator object has
147147
// been disconnected from its window. Thus, reject the promise.
148148
aRequest->mPromise->MaybeRejectWithTypeError(
149-
u"Browsing context is no longer available");
149+
"Browsing context is no longer available");
150150
} else {
151151
// In this case, there is no browser because e10s is off. Proceed with
152152
// the request with support since this scenario is always supported.
@@ -347,7 +347,7 @@ void MediaKeySystemAccessManager::RequestMediaKeySystemAccess(
347347
// 1. If keySystem is the empty string, return a promise rejected with a newly
348348
// created TypeError.
349349
if (aRequest->mKeySystem.IsEmpty()) {
350-
aRequest->mPromise->MaybeRejectWithTypeError(u"Key system string is empty");
350+
aRequest->mPromise->MaybeRejectWithTypeError("Key system string is empty");
351351
// Don't notify DecoderDoctor, as there's nothing we or the user can
352352
// do to fix this situation; the site is using the API wrong.
353353
return;
@@ -356,7 +356,7 @@ void MediaKeySystemAccessManager::RequestMediaKeySystemAccess(
356356
// newly created TypeError.
357357
if (aRequest->mConfigs.IsEmpty()) {
358358
aRequest->mPromise->MaybeRejectWithTypeError(
359-
u"Candidate MediaKeySystemConfigs is empty");
359+
"Candidate MediaKeySystemConfigs is empty");
360360
// Don't notify DecoderDoctor, as there's nothing we or the user can
361361
// do to fix this situation; the site is using the API wrong.
362362
return;

dom/media/eme/MediaKeySystemAccessManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class MediaKeySystemAccessManager final : public nsIObserver {
137137
// Convenience methods to reject the wrapped promise.
138138
void RejectPromiseWithInvalidAccessError(const nsAString& aReason);
139139
void RejectPromiseWithNotSupportedError(const nsAString& aReason);
140-
void RejectPromiseWithTypeError(const nsAString& aReason);
140+
void RejectPromiseWithTypeError(const nsACString& aReason);
141141

142142
void CancelTimer();
143143
};

dom/media/eme/MediaKeys.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ already_AddRefed<DetailedPromise> MediaKeys::SetServerCertificate(
186186
CopyArrayBufferViewOrArrayBufferData(aCert, data);
187187
if (data.IsEmpty()) {
188188
promise->MaybeRejectWithTypeError(
189-
u"Empty certificate passed to MediaKeys.setServerCertificate()");
189+
"Empty certificate passed to MediaKeys.setServerCertificate()");
190190
return promise.forget();
191191
}
192192

dom/notification/Notification.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ already_AddRefed<Promise> Notification::ShowPersistentNotification(
21682168
// with a TypeError exception, and terminate these substeps."
21692169
if (NS_WARN_IF(aRv.Failed()) ||
21702170
permission == NotificationPermission::Denied) {
2171-
p->MaybeRejectWithTypeError(u"Permission to show Notification denied.");
2171+
p->MaybeRejectWithTypeError("Permission to show Notification denied.");
21722172
return p.forget();
21732173
}
21742174

0 commit comments

Comments
 (0)