Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: Source/modules/serviceworkers/FetchBodyStream.cpp

Issue 535193002: [ServiceWorker] Add NULL check of ExecutionContext in FetchBodyStream::readAsync (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: same as patch set 1 Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/serviceworkers/FetchBodyStream.h" 6 #include "modules/serviceworkers/FetchBodyStream.h"
7 7
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8ThrowException.h" 10 #include "bindings/core/v8/V8ThrowException.h"
(...skipping 13 matching lines...) Expand all
24 fetchBodyStream->suspendIfNeeded(); 24 fetchBodyStream->suspendIfNeeded();
25 return fetchBodyStream.release(); 25 return fetchBodyStream.release();
26 } 26 }
27 27
28 ScriptPromise FetchBodyStream::readAsync(ScriptState* scriptState, ResponseType type) 28 ScriptPromise FetchBodyStream::readAsync(ScriptState* scriptState, ResponseType type)
29 { 29 {
30 if (m_hasRead) 30 if (m_hasRead)
31 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Already read", scriptState->isolate())); 31 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Already read", scriptState->isolate()));
32 32
33 m_hasRead = true; 33 m_hasRead = true;
34 m_responseType = type; 34 m_responseType = type;
yhirano 2014/09/05 06:17:16 Can you protect the ExecutionContext by placing a
haraken 2014/09/05 06:40:57 It looks strange to use a protecting pointer for E
35 35
36 ASSERT(!m_resolver); 36 ASSERT(!m_resolver);
37 m_resolver = ScriptPromiseResolver::create(scriptState); 37 m_resolver = ScriptPromiseResolver::create(scriptState);
38 ScriptPromise promise = m_resolver->promise(); 38 ScriptPromise promise = m_resolver->promise();
39 39
40 FileReaderLoader::ReadType readType = FileReaderLoader::ReadAsText; 40 FileReaderLoader::ReadType readType = FileReaderLoader::ReadAsText;
41 41
42 switch (type) { 42 switch (type) {
43 case ResponseAsArrayBuffer: 43 case ResponseAsArrayBuffer:
44 readType = FileReaderLoader::ReadAsArrayBuffer; 44 readType = FileReaderLoader::ReadAsArrayBuffer;
(...skipping 14 matching lines...) Expand all
59 // FIXME: Implement this. 59 // FIXME: Implement this.
60 ASSERT_NOT_REACHED(); 60 ASSERT_NOT_REACHED();
61 break; 61 break;
62 case ResponseAsJSON: 62 case ResponseAsJSON:
63 case ResponseAsText: 63 case ResponseAsText:
64 break; 64 break;
65 default: 65 default:
66 ASSERT_NOT_REACHED(); 66 ASSERT_NOT_REACHED();
67 } 67 }
68 68
69 ExecutionContext* executionContext = scriptState->executionContext();
70 if (!executionContext) {
71 m_resolver->reject(V8ThrowException::createTypeError("ExecutionContext t erminated", scriptState->isolate()));
72 m_resolver.clear();
73 return promise;
74 }
75
69 m_loader = adoptPtr(new FileReaderLoader(readType, this)); 76 m_loader = adoptPtr(new FileReaderLoader(readType, this));
70 m_loader->start(scriptState->executionContext(), m_blobDataHandle); 77 m_loader->start(executionContext, m_blobDataHandle);
71 78
72 return promise; 79 return promise;
73 } 80 }
74 81
75 ScriptPromise FetchBodyStream::asArrayBuffer(ScriptState* scriptState) 82 ScriptPromise FetchBodyStream::asArrayBuffer(ScriptState* scriptState)
76 { 83 {
77 return readAsync(scriptState, ResponseAsArrayBuffer); 84 return readAsync(scriptState, ResponseAsArrayBuffer);
78 } 85 }
79 86
80 ScriptPromise FetchBodyStream::asBlob(ScriptState* scriptState) 87 ScriptPromise FetchBodyStream::asBlob(ScriptState* scriptState)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 { 185 {
179 ASSERT(m_resolver); 186 ASSERT(m_resolver);
180 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) 187 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped())
181 return; 188 return;
182 189
183 m_resolver->resolve(""); 190 m_resolver->resolve("");
184 m_resolver.clear(); 191 m_resolver.clear();
185 } 192 }
186 193
187 } // namespace blink 194 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698