Changeset 234045 in webkit
- Timestamp:
- Jul 20, 2018 9:58:54 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r234044 r234045 1 2018-07-20 Youenn Fablet <youenn@apple.com> 2 3 FetchResponse should close its stream when loading finishes 4 https://bugs.webkit.org/show_bug.cgi?id=187790 5 6 Reviewed by Chris Dumez. 7 8 It simplifies for a FetchResponse to push all its data into its stream if already created at end of load time. 9 Did some refactoring in FetchBodyOwner to have a cleaner relationship with the stream source. 10 Did a minor refactoring to expose the error description when loading fails as part of the rejected promise. 11 This is consistent to errors sent back through callbacks. 12 13 Covered by existing tests. 14 15 * Modules/fetch/FetchBodyOwner.cpp: 16 (WebCore::FetchBodyOwner::~FetchBodyOwner): 17 * Modules/fetch/FetchBodyOwner.h: 18 * Modules/fetch/FetchBodySource.cpp: 19 (WebCore::FetchBodySource::FetchBodySource): 20 (WebCore::FetchBodySource::setActive): 21 (WebCore::FetchBodySource::setInactive): 22 (WebCore::FetchBodySource::doStart): 23 (WebCore::FetchBodySource::doPull): 24 (WebCore::FetchBodySource::doCancel): 25 (WebCore::FetchBodySource::cleanBodyOwner): 26 * Modules/fetch/FetchBodySource.h: 27 * Modules/fetch/FetchResponse.cpp: 28 (WebCore::FetchResponse::BodyLoader::didSucceed): 29 (WebCore::FetchResponse::BodyLoader::didFail): 30 1 31 2018-07-20 Jer Noble <jer.noble@apple.com> 2 32 -
trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
r234003 r234045 46 46 } 47 47 48 FetchBodyOwner::~FetchBodyOwner() 49 { 50 if (m_readableStreamSource) 51 m_readableStreamSource->detach(); 52 } 53 48 54 void FetchBodyOwner::stop() 49 55 { -
trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h
r234003 r234045 42 42 public: 43 43 FetchBodyOwner(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&); 44 ~FetchBodyOwner(); 44 45 45 46 bool bodyUsed() const { return isDisturbed(); } -
trunk/Source/WebCore/Modules/fetch/FetchBodySource.cpp
r234003 r234045 35 35 36 36 FetchBodySource::FetchBodySource(FetchBodyOwner& bodyOwner) 37 : m_bodyOwner( bodyOwner)37 : m_bodyOwner(&bodyOwner) 38 38 { 39 39 } … … 41 41 void FetchBodySource::setActive() 42 42 { 43 m_bodyOwner.setPendingActivity(&m_bodyOwner); 43 ASSERT(m_bodyOwner); 44 if (m_bodyOwner) 45 m_bodyOwner->setPendingActivity(m_bodyOwner); 44 46 } 45 47 46 48 void FetchBodySource::setInactive() 47 49 { 48 m_bodyOwner.unsetPendingActivity(&m_bodyOwner); 50 ASSERT(m_bodyOwner); 51 if (m_bodyOwner) 52 m_bodyOwner->unsetPendingActivity(m_bodyOwner); 49 53 } 50 54 51 55 void FetchBodySource::doStart() 52 56 { 53 m_bodyOwner.consumeBodyAsStream(); 57 ASSERT(m_bodyOwner); 58 if (m_bodyOwner) 59 m_bodyOwner->consumeBodyAsStream(); 54 60 } 55 61 56 62 void FetchBodySource::doPull() 57 63 { 58 m_bodyOwner.feedStream(); 64 ASSERT(m_bodyOwner); 65 if (m_bodyOwner) 66 m_bodyOwner->feedStream(); 59 67 } 60 68 … … 62 70 { 63 71 m_isCancelling = true; 64 m_bodyOwner.cancel(); 72 ASSERT(m_bodyOwner || m_isClosed); 73 if (!m_bodyOwner) 74 return; 75 76 m_bodyOwner->cancel(); 77 m_bodyOwner = nullptr; 65 78 } 66 79 67 80 void FetchBodySource::close() 68 81 { 82 #ifndef NDEBUG 83 m_isClosed = true; 84 #endif 85 69 86 controller().close(); 70 87 clean(); 88 m_bodyOwner = nullptr; 71 89 } 72 90 … … 75 93 controller().error(value); 76 94 clean(); 95 m_bodyOwner = nullptr; 77 96 } 78 97 -
trunk/Source/WebCore/Modules/fetch/FetchBodySource.h
r234003 r234045 50 50 51 51 void resolvePullPromise() { pullFinished(); } 52 void detach() { m_bodyOwner = nullptr; } 52 53 53 54 private: … … 58 59 void setInactive() final; 59 60 60 FetchBodyOwner &m_bodyOwner;61 FetchBodyOwner* m_bodyOwner; 61 62 bool m_isCancelling { false }; 63 #ifndef NDEBUG 64 bool m_isClosed { false }; 65 #endif 62 66 }; 63 67 -
trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp
r234003 r234045 226 226 227 227 #if ENABLE(STREAMS_API) 228 if (m_response.m_readableStreamSource && !m_response.body().consumer().hasData()) 228 if (m_response.m_readableStreamSource) { 229 if (m_response.body().consumer().hasData()) 230 m_response.m_readableStreamSource->enqueue(m_response.body().consumer().takeAsArrayBuffer()); 231 229 232 m_response.closeStream(); 233 } 230 234 #endif 231 235 if (auto consumeDataCallback = WTFMove(m_consumeDataCallback)) … … 253 257 if (m_response.m_readableStreamSource) { 254 258 if (!m_response.m_readableStreamSource->isCancelling()) 255 m_response.m_readableStreamSource->error( "Loading failed"_s);259 m_response.m_readableStreamSource->error(makeString("Loading failed: "_s, error.localizedDescription())); 256 260 m_response.m_readableStreamSource = nullptr; 257 261 }
Note: See TracChangeset
for help on using the changeset viewer.