зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1613978. Allow passing u"...", not just nsAStrings, to templated ThrowType/RangeError. r=peterv
Differential Revision: https://phabricator.services.mozilla.com/D62061 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
12a26f2d5a
Коммит
05327f8a52
|
@ -731,7 +731,7 @@ void CustomElementRegistry::Define(
|
|||
*/
|
||||
if (!JS::IsConstructor(constructorUnwrapped)) {
|
||||
aRv.ThrowTypeError<MSG_NOT_CONSTRUCTOR>(
|
||||
NS_LITERAL_STRING("Argument 2 of CustomElementRegistry.define"));
|
||||
u"Argument 2 of CustomElementRegistry.define");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -870,8 +870,8 @@ void CustomElementRegistry::Define(
|
|||
* 14.2. If Type(prototype) is not Object, then throw a TypeError exception.
|
||||
*/
|
||||
if (!prototype.isObject()) {
|
||||
aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING(
|
||||
"CustomElementRegistry.define: constructor.prototype"));
|
||||
aRv.ThrowTypeError<MSG_NOT_OBJECT>(
|
||||
u"CustomElementRegistry.define: constructor.prototype");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1137,8 +1137,7 @@ bool Navigator::SendBeaconInternal(const nsAString& aUrl,
|
|||
|
||||
// Spec disallows any schemes save for HTTP/HTTPs
|
||||
if (!uri->SchemeIs("http") && !uri->SchemeIs("https")) {
|
||||
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>(NS_LITERAL_STRING("Beacon"),
|
||||
aUrl);
|
||||
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>(u"Beacon", aUrl);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -9099,14 +9099,14 @@ static void DoCustomElementCreate(Element** aElement, JSContext* aCx,
|
|||
UNWRAP_OBJECT(Element, &constructResult, element);
|
||||
if (aNodeInfo->NamespaceEquals(kNameSpaceID_XHTML)) {
|
||||
if (!element || !element->IsHTMLElement()) {
|
||||
aRv.ThrowTypeError<MSG_DOES_NOT_IMPLEMENT_INTERFACE>(
|
||||
NS_LITERAL_STRING("\"this\""), NS_LITERAL_STRING("HTMLElement"));
|
||||
aRv.ThrowTypeError<MSG_DOES_NOT_IMPLEMENT_INTERFACE>(u"\"this\"",
|
||||
u"HTMLElement");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!element || !element->IsXULElement()) {
|
||||
aRv.ThrowTypeError<MSG_DOES_NOT_IMPLEMENT_INTERFACE>(
|
||||
NS_LITERAL_STRING("\"this\""), NS_LITERAL_STRING("XULElement"));
|
||||
aRv.ThrowTypeError<MSG_DOES_NOT_IMPLEMENT_INTERFACE>(u"\"this\"",
|
||||
u"XULElement");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5623,13 +5623,13 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
getPromiseGlobal = fill(
|
||||
"""
|
||||
if (!$${val}.isObject()) {
|
||||
aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("${sourceDescription}"));
|
||||
aRv.ThrowTypeError<MSG_NOT_OBJECT>(u"${sourceDescription}");
|
||||
return nullptr;
|
||||
}
|
||||
JSObject* unwrappedVal = js::CheckedUnwrapStatic(&$${val}.toObject());
|
||||
if (!unwrappedVal) {
|
||||
// A slight lie, but not much of one, for a dead object wrapper.
|
||||
aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("${sourceDescription}"));
|
||||
aRv.ThrowTypeError<MSG_NOT_OBJECT>(u"${sourceDescription}");
|
||||
return nullptr;
|
||||
}
|
||||
globalObj = JS::GetNonCCWObjectGlobal(unwrappedVal);
|
||||
|
|
|
@ -100,6 +100,7 @@ struct StringArrayAppender {
|
|||
"required by the ErrNum.");
|
||||
}
|
||||
|
||||
// Allow passing nsAString instances for our args.
|
||||
template <typename... Ts>
|
||||
static void Append(nsTArray<nsString>& aArgs, uint16_t aCount,
|
||||
const nsAString& aFirst, Ts&&... aOtherArgs) {
|
||||
|
@ -112,6 +113,20 @@ struct StringArrayAppender {
|
|||
aArgs.AppendElement(aFirst);
|
||||
Append(aArgs, aCount - 1, std::forward<Ts>(aOtherArgs)...);
|
||||
}
|
||||
|
||||
// Also allow passing u"" instances for our args.
|
||||
template <int N, typename... Ts>
|
||||
static void Append(nsTArray<nsString>& aArgs, uint16_t aCount,
|
||||
const char16_t (&aFirst)[N], Ts&&... aOtherArgs) {
|
||||
if (aCount == 0) {
|
||||
MOZ_ASSERT(false,
|
||||
"There should not be more string arguments provided than are "
|
||||
"required by the ErrNum.");
|
||||
return;
|
||||
}
|
||||
aArgs.AppendElement(nsLiteralString(aFirst));
|
||||
Append(aArgs, aCount - 1, std::forward<Ts>(aOtherArgs)...);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -45,8 +45,7 @@ bool IsValidPutRequestURL(const nsAString& aUrl, ErrorResult& aRv) {
|
|||
}
|
||||
|
||||
if (!validScheme) {
|
||||
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>(NS_LITERAL_STRING("Request"),
|
||||
aUrl);
|
||||
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>(u"Request", aUrl);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -126,8 +126,7 @@ void TypeUtils::ToCacheRequest(
|
|||
if (!schemeValid) {
|
||||
if (aSchemeAction == TypeErrorOnInvalidScheme) {
|
||||
NS_ConvertUTF8toUTF16 urlUTF16(url);
|
||||
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>(NS_LITERAL_STRING("Request"),
|
||||
urlUTF16);
|
||||
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>(u"Request", urlUTF16);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,7 +323,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
|||
: fallbackCredentials;
|
||||
|
||||
if (mode == RequestMode::Navigate) {
|
||||
aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>(NS_LITERAL_STRING("navigate"));
|
||||
aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>(u"navigate");
|
||||
return nullptr;
|
||||
}
|
||||
if (aInit.IsAnyMemberPresent() && request->Mode() == RequestMode::Navigate) {
|
||||
|
|
|
@ -481,9 +481,8 @@ RefPtr<IDBTransaction> IDBDatabase::Transaction(
|
|||
// certain enum values as depending on preferences so we just duplicate the
|
||||
// normal exception generation here.
|
||||
aRv.ThrowTypeError<MSG_INVALID_ENUM_VALUE>(
|
||||
NS_LITERAL_STRING("Argument 2 of IDBDatabase.transaction"),
|
||||
NS_LITERAL_STRING("readwriteflush"),
|
||||
NS_LITERAL_STRING("IDBTransactionMode"));
|
||||
u"Argument 2 of IDBDatabase.transaction", u"readwriteflush",
|
||||
u"IDBTransactionMode");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -112,8 +112,8 @@ already_AddRefed<Promise> MediaCapabilities::DecodingInfo(
|
|||
if (!aConfiguration.mVideo.WasPassed() &&
|
||||
!aConfiguration.mAudio.WasPassed()) {
|
||||
aRv.ThrowTypeError<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>(
|
||||
NS_LITERAL_STRING("'audio' or 'video' member of argument of "
|
||||
"MediaCapabilities.decodingInfo"));
|
||||
u"'audio' or 'video' member of argument of "
|
||||
u"MediaCapabilities.decodingInfo");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -459,8 +459,8 @@ already_AddRefed<Promise> MediaCapabilities::EncodingInfo(
|
|||
if (!aConfiguration.mVideo.WasPassed() &&
|
||||
!aConfiguration.mAudio.WasPassed()) {
|
||||
aRv.ThrowTypeError<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>(
|
||||
NS_LITERAL_STRING("'audio' or 'video' member of argument of "
|
||||
"MediaCapabilities.encodingInfo"));
|
||||
u"'audio' or 'video' member of argument of "
|
||||
u"MediaCapabilities.encodingInfo");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -651,21 +651,21 @@ void AudioBufferSourceNode::Start(double aWhen, double aOffset,
|
|||
const Optional<double>& aDuration,
|
||||
ErrorResult& aRv) {
|
||||
if (!WebAudioUtils::IsTimeValid(aWhen)) {
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(
|
||||
NS_LITERAL_STRING("start time"));
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(u"start time");
|
||||
return;
|
||||
}
|
||||
if (aOffset < 0) {
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(NS_LITERAL_STRING("offset"));
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(u"offset");
|
||||
return;
|
||||
}
|
||||
if (aDuration.WasPassed() && !WebAudioUtils::IsTimeValid(aDuration.Value())) {
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(NS_LITERAL_STRING("duration"));
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(u"duration");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mStartCalled) {
|
||||
aRv.ThrowInvalidStateError("Start has already been called on this AudioBufferSourceNode.");
|
||||
aRv.ThrowInvalidStateError(
|
||||
"Start has already been called on this AudioBufferSourceNode.");
|
||||
return;
|
||||
}
|
||||
mStartCalled = true;
|
||||
|
@ -757,12 +757,13 @@ void AudioBufferSourceNode::SendOffsetAndDurationParametersToTrack(
|
|||
|
||||
void AudioBufferSourceNode::Stop(double aWhen, ErrorResult& aRv) {
|
||||
if (!WebAudioUtils::IsTimeValid(aWhen)) {
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(NS_LITERAL_STRING("stop time"));
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(u"stop time");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mStartCalled) {
|
||||
aRv.ThrowInvalidStateError("Start has not been called on this AudioBufferSourceNode.");
|
||||
aRv.ThrowInvalidStateError(
|
||||
"Start has not been called on this AudioBufferSourceNode.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,8 @@ void AudioWorkletGlobalScope::RegisterProcessor(
|
|||
* throw a TypeError and abort these steps.
|
||||
*/
|
||||
if (!JS::IsConstructor(constructorUnwrapped)) {
|
||||
aRv.ThrowTypeError<MSG_NOT_CONSTRUCTOR>(NS_LITERAL_STRING(
|
||||
"Argument 2 of AudioWorkletGlobalScope.registerProcessor"));
|
||||
aRv.ThrowTypeError<MSG_NOT_CONSTRUCTOR>(
|
||||
u"Argument 2 of AudioWorkletGlobalScope.registerProcessor");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -112,9 +112,9 @@ void AudioWorkletGlobalScope::RegisterProcessor(
|
|||
* TypeError and abort all these steps.
|
||||
*/
|
||||
if (!prototype.isObject()) {
|
||||
aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING(
|
||||
"Argument 2 of AudioWorkletGlobalScope.registerProcessor "
|
||||
"processorCtor.prototype"));
|
||||
aRv.ThrowTypeError<MSG_NOT_OBJECT>(
|
||||
u"Argument 2 of AudioWorkletGlobalScope.registerProcessor "
|
||||
u"processorCtor.prototype");
|
||||
return;
|
||||
}
|
||||
/**
|
||||
|
@ -146,7 +146,7 @@ void AudioWorkletGlobalScope::RegisterProcessor(
|
|||
|
||||
if (!descriptors.isUndefined() && !isArray) {
|
||||
aRv.ThrowTypeError<MSG_NOT_ARRAY_NOR_UNDEFINED>(
|
||||
NS_LITERAL_STRING(".constructor.parameterDescriptors of argument 2"));
|
||||
u".constructor.parameterDescriptors of argument 2");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -474,13 +474,11 @@ already_AddRefed<AudioWorkletNode> AudioWorkletNode::Constructor(
|
|||
}
|
||||
// MTG does not support more than UINT16_MAX inputs or outputs.
|
||||
if (aOptions.mNumberOfInputs > UINT16_MAX) {
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(
|
||||
NS_LITERAL_STRING("numberOfInputs"));
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(u"numberOfInputs");
|
||||
return nullptr;
|
||||
}
|
||||
if (aOptions.mNumberOfOutputs > UINT16_MAX) {
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(
|
||||
NS_LITERAL_STRING("numberOfOutputs"));
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(u"numberOfOutputs");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -203,8 +203,7 @@ void ConstantSourceNode::DestroyMediaTrack() {
|
|||
|
||||
void ConstantSourceNode::Start(double aWhen, ErrorResult& aRv) {
|
||||
if (!WebAudioUtils::IsTimeValid(aWhen)) {
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(
|
||||
NS_LITERAL_STRING("start time"));
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(u"start time");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -227,7 +226,7 @@ void ConstantSourceNode::Start(double aWhen, ErrorResult& aRv) {
|
|||
|
||||
void ConstantSourceNode::Stop(double aWhen, ErrorResult& aRv) {
|
||||
if (!WebAudioUtils::IsTimeValid(aWhen)) {
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(NS_LITERAL_STRING("stop time"));
|
||||
aRv.ThrowRangeError<MSG_VALUE_OUT_OF_RANGE>(u"stop time");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -2448,7 +2448,7 @@ void ServiceWorkerManager::UpdateInternal(
|
|||
if (NS_WARN_IF(!registration)) {
|
||||
ErrorResult error;
|
||||
error.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(
|
||||
NS_ConvertUTF8toUTF16(aScope), NS_LITERAL_STRING("uninstalled"));
|
||||
NS_ConvertUTF8toUTF16(aScope), u"uninstalled");
|
||||
aCallback->UpdateFailed(error);
|
||||
|
||||
// In case the callback does not consume the exception
|
||||
|
|
|
@ -232,7 +232,7 @@ void ServiceWorkerUpdateJob::AsyncExecute() {
|
|||
if (!registration) {
|
||||
ErrorResult rv;
|
||||
rv.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(
|
||||
NS_ConvertUTF8toUTF16(mScope), NS_LITERAL_STRING("uninstalled"));
|
||||
NS_ConvertUTF8toUTF16(mScope), u"uninstalled");
|
||||
FailUpdateJob(rv);
|
||||
return;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ void ServiceWorkerUpdateJob::AsyncExecute() {
|
|||
if (newest && !newest->ScriptSpec().Equals(mScriptSpec)) {
|
||||
ErrorResult rv;
|
||||
rv.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(
|
||||
NS_ConvertUTF8toUTF16(mScope), NS_LITERAL_STRING("changed"));
|
||||
NS_ConvertUTF8toUTF16(mScope), u"changed");
|
||||
FailUpdateJob(rv);
|
||||
return;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче