Bug 1580014. Don't force methods into the "can throw any exception" bucket just because they always return a new JS object. r=peterv

Instead, mark them as "can OOM", since we have that concept now.

Differential Revision: https://phabricator.services.mozilla.com/D45251

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-09-24 08:51:47 +00:00
parent a966f41d5c
commit 222487304c
4 changed files with 12 additions and 12 deletions

View File

@ -286,8 +286,6 @@ class NoSuchDescriptorError(TypeError):
def methodReturnsJSObject(method):
assert method.isMethod()
if method.returnsPromise():
return True
for signature in method.signatures():
returnType = signature[0]
@ -656,9 +654,11 @@ class Descriptor(DescriptorProvider):
if member.isMethod():
# JSObject-returning [NewObject] methods must be fallible,
# since they have to (fallibly) allocate the new JSObject.
if (member.getExtendedAttribute("NewObject") and
methodReturnsJSObject(member)):
throws = True
if member.getExtendedAttribute("NewObject"):
if member.returnsPromise():
throws = True
elif methodReturnsJSObject(member):
canOOM = True
attrs = self.extendedAttributes['all'].get(name, [])
maybeAppendInfallibleToAttrs(attrs, throws)
maybeAppendCanOOMToAttrs(attrs, canOOM)

View File

@ -15,12 +15,12 @@ namespace dom {
void TextEncoder::Encode(JSContext* aCx, JS::Handle<JSObject*> aObj,
JS::Handle<JSString*> aString,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv) {
OOMReporter& aRv) {
CheckedInt<size_t> bufLen(JS::GetStringLength(aString));
bufLen *= 3; // from the contract for JS_EncodeStringToUTF8BufferPartial
// Uint8Array::Create takes uint32_t as the length.
if (!bufLen.isValid() || bufLen.value() > UINT32_MAX) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
aRv.ReportOOM();
return;
}
@ -28,7 +28,7 @@ void TextEncoder::Encode(JSContext* aCx, JS::Handle<JSObject*> aObj,
// is small.
auto data = mozilla::MakeUniqueFallible<uint8_t[]>(bufLen.value());
if (!data) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
aRv.ReportOOM();
return;
}
@ -37,7 +37,7 @@ void TextEncoder::Encode(JSContext* aCx, JS::Handle<JSObject*> aObj,
auto maybe = JS_EncodeStringToUTF8BufferPartial(
aCx, aString, AsWritableChars(MakeSpan(data.get(), bufLen.value())));
if (!maybe) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
aRv.ReportOOM();
return;
}
Tie(read, written) = *maybe;
@ -47,7 +47,7 @@ void TextEncoder::Encode(JSContext* aCx, JS::Handle<JSObject*> aObj,
JSAutoRealm ar(aCx, aObj);
JSObject* outView = Uint8Array::Create(aCx, written, data.get());
if (!outView) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
aRv.ReportOOM();
return;
}

View File

@ -53,7 +53,7 @@ class TextEncoder final : public NonRefcountedDOMObject {
*/
void Encode(JSContext* aCx, JS::Handle<JSObject*> aObj,
JS::Handle<JSString*> aString,
JS::MutableHandle<JSObject*> aRetval, ErrorResult& aRv);
JS::MutableHandle<JSObject*> aRetval, OOMReporter& aRv);
void EncodeInto(JSContext* aCx, JS::Handle<JSString*> aSrc,
const Uint8Array& aDst, TextEncoderEncodeIntoResult& aResult,

View File

@ -31,7 +31,7 @@ interface Blob {
optional DOMString contentType);
// read from the Blob.
[NewObject] ReadableStream stream();
[NewObject, Throws] ReadableStream stream();
[NewObject] Promise<USVString> text();
[NewObject] Promise<ArrayBuffer> arrayBuffer();
};