|
1 | 1 | /* |
2 | 2 | * Copyright (C) 2016 Canon Inc. |
| 3 | + * Copyright (C) 2020 Apple Inc. All rights reserved. |
3 | 4 | * |
4 | 5 | * Redistribution and use in source and binary forms, with or without |
5 | 6 | * modification, are permitted, provided that the following conditions |
@@ -311,27 +312,40 @@ void FetchBodyOwner::BlobLoader::didFail(const ResourceError&) |
311 | 312 | owner.blobLoadingFailed(); |
312 | 313 | } |
313 | 314 |
|
314 | | -RefPtr<ReadableStream> FetchBodyOwner::readableStream(JSC::JSGlobalObject& state) |
| 315 | +ExceptionOr<RefPtr<ReadableStream>> FetchBodyOwner::readableStream(JSC::JSGlobalObject& state) |
315 | 316 | { |
316 | 317 | if (isBodyNullOrOpaque()) |
317 | 318 | return nullptr; |
318 | 319 |
|
319 | | - if (!m_body->hasReadableStream()) |
320 | | - createReadableStream(state); |
| 320 | + if (!m_body->hasReadableStream()) { |
| 321 | + auto voidOrException = createReadableStream(state); |
| 322 | + if (UNLIKELY(voidOrException.hasException())) |
| 323 | + return voidOrException.releaseException(); |
| 324 | + } |
321 | 325 |
|
322 | 326 | return m_body->readableStream(); |
323 | 327 | } |
324 | 328 |
|
325 | | -void FetchBodyOwner::createReadableStream(JSC::JSGlobalObject& state) |
| 329 | +ExceptionOr<void> FetchBodyOwner::createReadableStream(JSC::JSGlobalObject& state) |
326 | 330 | { |
327 | 331 | ASSERT(!m_readableStreamSource); |
328 | 332 | if (isDisturbed()) { |
329 | | - m_body->setReadableStream(ReadableStream::create(state, nullptr)); |
| 333 | + auto streamOrException = ReadableStream::create(state, nullptr); |
| 334 | + if (UNLIKELY(streamOrException.hasException())) |
| 335 | + return streamOrException.releaseException(); |
| 336 | + m_body->setReadableStream(streamOrException.releaseReturnValue()); |
330 | 337 | m_body->readableStream()->lock(); |
331 | | - } else { |
332 | | - m_readableStreamSource = adoptRef(*new FetchBodySource(*this)); |
333 | | - m_body->setReadableStream(ReadableStream::create(state, m_readableStreamSource)); |
| 338 | + return { }; |
334 | 339 | } |
| 340 | + |
| 341 | + m_readableStreamSource = adoptRef(*new FetchBodySource(*this)); |
| 342 | + auto streamOrException = ReadableStream::create(state, m_readableStreamSource); |
| 343 | + if (UNLIKELY(streamOrException.hasException())) { |
| 344 | + m_readableStreamSource = nullptr; |
| 345 | + return streamOrException.releaseException(); |
| 346 | + } |
| 347 | + m_body->setReadableStream(streamOrException.releaseReturnValue()); |
| 348 | + return { }; |
335 | 349 | } |
336 | 350 |
|
337 | 351 | void FetchBodyOwner::consumeBodyAsStream() |
|
0 commit comments