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

Side by Side Diff: Source/modules/crypto/CryptoResultImpl.cpp

Issue 1233173002: Have ScriptPromiseResolver on the Oilpan heap always. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix webusb ScriptPromiseResolver usage Created 5 years, 4 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 | « Source/modules/crypto/CryptoResultImpl.h ('k') | Source/modules/crypto/SubtleCrypto.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (!resolver->executionContext() || resolver->executionContext()->activeDOM ObjectsAreStopped()) 57 if (!resolver->executionContext() || resolver->executionContext()->activeDOM ObjectsAreStopped())
58 return; 58 return;
59 59
60 ScriptState::Scope scope(resolver->scriptState()); 60 ScriptState::Scope scope(resolver->scriptState());
61 v8::Isolate* isolate = resolver->scriptState()->isolate(); 61 v8::Isolate* isolate = resolver->scriptState()->isolate();
62 resolver->reject(v8::Exception::TypeError(v8String(isolate, errorDetails))); 62 resolver->reject(v8::Exception::TypeError(v8String(isolate, errorDetails)));
63 } 63 }
64 64
65 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver { 65 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver {
66 public: 66 public:
67 static PassRefPtrWillBeRawPtr<Resolver> create(ScriptState* scriptState, Cry ptoResultImpl* result) 67 static Resolver* create(ScriptState* scriptState, CryptoResultImpl* result)
68 { 68 {
69 RefPtrWillBeRawPtr<Resolver> resolver = adoptRefWillBeNoop(new Resolver( scriptState, result)); 69 ASSERT(scriptState->contextIsValid());
70 Resolver* resolver = new Resolver(scriptState, result);
70 resolver->suspendIfNeeded(); 71 resolver->suspendIfNeeded();
71 resolver->keepAliveWhilePending(); 72 resolver->keepAliveWhilePending();
72 return resolver.release(); 73 return resolver;
73 } 74 }
74 75
75 void stop() override 76 void stop() override
76 { 77 {
77 m_result->cancel(); 78 m_result->cancel();
78 m_result = nullptr; 79 m_result = nullptr;
79 ScriptPromiseResolver::stop(); 80 ScriptPromiseResolver::stop();
80 } 81 }
81 82
82 DEFINE_INLINE_VIRTUAL_TRACE() 83 DEFINE_INLINE_VIRTUAL_TRACE()
83 { 84 {
84 visitor->trace(m_result); 85 visitor->trace(m_result);
85 ScriptPromiseResolver::trace(visitor); 86 ScriptPromiseResolver::trace(visitor);
86 } 87 }
87 88
88 private: 89 private:
89 Resolver(ScriptState* scriptState, CryptoResultImpl* result) 90 Resolver(ScriptState* scriptState, CryptoResultImpl* result)
90 : ScriptPromiseResolver(scriptState) 91 : ScriptPromiseResolver(scriptState)
91 , m_result(result) { } 92 , m_result(result) { }
92 93
93 RefPtrWillBeMember<CryptoResultImpl> m_result; 94 Member<CryptoResultImpl> m_result;
94 }; 95 };
95 96
96 CryptoResultImpl::ResultCancel::ResultCancel() 97 CryptoResultImpl::ResultCancel::ResultCancel()
97 : m_cancelled(0) 98 : m_cancelled(0)
98 { 99 {
99 } 100 }
100 101
101 bool CryptoResultImpl::ResultCancel::cancelled() const 102 bool CryptoResultImpl::ResultCancel::cancelled() const
102 { 103 {
103 return acquireLoad(&m_cancelled); 104 return acquireLoad(&m_cancelled);
(...skipping 19 matching lines...) Expand all
123 return OperationError; 124 return OperationError;
124 case WebCryptoErrorTypeType: 125 case WebCryptoErrorTypeType:
125 return V8TypeError; 126 return V8TypeError;
126 } 127 }
127 128
128 ASSERT_NOT_REACHED(); 129 ASSERT_NOT_REACHED();
129 return 0; 130 return 0;
130 } 131 }
131 132
132 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) 133 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState)
133 : m_cancel(ResultCancel::create()) 134 : m_resolver(Resolver::create(scriptState, this))
135 , m_cancel(ResultCancel::create())
134 { 136 {
135 ASSERT(scriptState->contextIsValid()); 137 // Sync cancellation state.
136 if (scriptState->executionContext()->activeDOMObjectsAreStopped()) { 138 if (scriptState->executionContext()->activeDOMObjectsAreStopped())
137 // If active dom objects have been stopped, avoid creating
138 // CryptoResultImpl::Resolver.
139 m_resolver = nullptr;
140 m_cancel->cancel(); 139 m_cancel->cancel();
141 return;
142 }
143 m_resolver = Resolver::create(scriptState, this).get();
144 } 140 }
145 141
146 CryptoResultImpl::~CryptoResultImpl() 142 CryptoResultImpl::~CryptoResultImpl()
147 { 143 {
148 ASSERT(!m_resolver); 144 ASSERT(!m_resolver);
149 } 145 }
150 146
151 DEFINE_TRACE(CryptoResultImpl) 147 DEFINE_TRACE(CryptoResultImpl)
152 { 148 {
153 visitor->trace(m_resolver); 149 visitor->trace(m_resolver);
154 CryptoResult::trace(visitor); 150 CryptoResult::trace(visitor);
155 } 151 }
156 152
157 void CryptoResultImpl::clearResolver() 153 void CryptoResultImpl::clearResolver()
158 { 154 {
159 m_resolver = nullptr; 155 m_resolver = nullptr;
160 } 156 }
161 157
162 PassRefPtrWillBeRawPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* s criptState) 158 CryptoResultImpl* CryptoResultImpl::create(ScriptState* scriptState)
163 { 159 {
164 return adoptRefWillBeNoop(new CryptoResultImpl(scriptState)); 160 return new CryptoResultImpl(scriptState);
165 } 161 }
166 162
167 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails) 163 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails)
168 { 164 {
169 if (!m_resolver) 165 if (!m_resolver)
170 return; 166 return;
171 167
172 ExceptionCode ec = webCryptoErrorToExceptionCode(errorType); 168 ExceptionCode ec = webCryptoErrorToExceptionCode(errorType);
173 169
174 // Handle TypeError separately, as it cannot be created using 170 // Handle TypeError separately, as it cannot be created using
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 m_cancel.clear(); 246 m_cancel.clear();
251 clearResolver(); 247 clearResolver();
252 } 248 }
253 249
254 ScriptPromise CryptoResultImpl::promise() 250 ScriptPromise CryptoResultImpl::promise()
255 { 251 {
256 return m_resolver ? m_resolver->promise() : ScriptPromise(); 252 return m_resolver ? m_resolver->promise() : ScriptPromise();
257 } 253 }
258 254
259 } // namespace blink 255 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/crypto/CryptoResultImpl.h ('k') | Source/modules/crypto/SubtleCrypto.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698