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

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: tidy unit tests Created 5 years, 5 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
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (!resolver->executionContext() || resolver->executionContext()->activeDOM ObjectsAreStopped()) 56 if (!resolver->executionContext() || resolver->executionContext()->activeDOM ObjectsAreStopped())
57 return; 57 return;
58 58
59 ScriptState::Scope scope(resolver->scriptState()); 59 ScriptState::Scope scope(resolver->scriptState());
60 v8::Isolate* isolate = resolver->scriptState()->isolate(); 60 v8::Isolate* isolate = resolver->scriptState()->isolate();
61 resolver->reject(v8::Exception::TypeError(v8String(isolate, errorDetails))); 61 resolver->reject(v8::Exception::TypeError(v8String(isolate, errorDetails)));
62 } 62 }
63 63
64 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver { 64 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver {
65 public: 65 public:
66 static PassRefPtrWillBeRawPtr<ScriptPromiseResolver> create(ScriptState* scr iptState, CryptoResultImpl* result) 66 static Resolver* create(ScriptState* scriptState, CryptoResultImpl* result)
67 { 67 {
68 RefPtrWillBeRawPtr<Resolver> resolver = adoptRefWillBeNoop(new Resolver( scriptState, result)); 68 Resolver* resolver = new Resolver(scriptState, result);
69 resolver->suspendIfNeeded(); 69 resolver->suspendIfNeeded();
70 resolver->keepAliveWhilePending(); 70 resolver->keepAliveWhilePending();
71 return resolver.release(); 71 return resolver;
72 } 72 }
73 73
74 void stop() override 74 void stop() override
75 { 75 {
76 m_result->cancel(); 76 m_result->cancel();
77 m_result->clearResolver(); 77 m_result->clearResolver();
78 m_result = nullptr; 78 m_result = nullptr;
79 ScriptPromiseResolver::stop(); 79 ScriptPromiseResolver::stop();
80 } 80 }
81 81
82 DEFINE_INLINE_VIRTUAL_TRACE()
83 {
84 visitor->trace(m_result);
85 ScriptPromiseResolver::trace(visitor);
86 }
87
82 private: 88 private:
83 Resolver(ScriptState* scriptState, CryptoResultImpl* result) 89 Resolver(ScriptState* scriptState, CryptoResultImpl* result)
84 : ScriptPromiseResolver(scriptState) 90 : ScriptPromiseResolver(scriptState)
85 , m_result(result) { } 91 , m_result(result) { }
86 RefPtr<CryptoResultImpl> m_result; 92
93 Member<CryptoResultImpl> m_result;
87 }; 94 };
88 95
89 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType) 96 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType)
90 { 97 {
91 switch (errorType) { 98 switch (errorType) {
92 case WebCryptoErrorTypeNotSupported: 99 case WebCryptoErrorTypeNotSupported:
93 return NotSupportedError; 100 return NotSupportedError;
94 case WebCryptoErrorTypeSyntax: 101 case WebCryptoErrorTypeSyntax:
95 return SyntaxError; 102 return SyntaxError;
96 case WebCryptoErrorTypeInvalidAccess: 103 case WebCryptoErrorTypeInvalidAccess:
97 return InvalidAccessError; 104 return InvalidAccessError;
98 case WebCryptoErrorTypeData: 105 case WebCryptoErrorTypeData:
99 return DataError; 106 return DataError;
100 case WebCryptoErrorTypeOperation: 107 case WebCryptoErrorTypeOperation:
101 return OperationError; 108 return OperationError;
102 case WebCryptoErrorTypeType: 109 case WebCryptoErrorTypeType:
103 return V8TypeError; 110 return V8TypeError;
104 } 111 }
105 112
106 ASSERT_NOT_REACHED(); 113 ASSERT_NOT_REACHED();
107 return 0; 114 return 0;
108 } 115 }
109 116
117 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState)
118 : m_cancelled(0)
119 {
120 ASSERT(scriptState->contextIsValid());
121 if (scriptState->executionContext()->activeDOMObjectsAreStopped()) {
haraken 2015/07/17 01:40:36 Not related to this CL, why do we need this specia
sof 2015/07/17 09:43:26 It's due to https://codereview.chromium.org/780793
122 // If active dom objects have been stopped, avoid creating
123 // CryptoResultResolver.
124 m_resolver = nullptr;
125 } else {
126 m_resolver = Resolver::create(scriptState, this);
127 }
128 }
129
110 CryptoResultImpl::~CryptoResultImpl() 130 CryptoResultImpl::~CryptoResultImpl()
111 { 131 {
112 ASSERT(!m_resolver); 132 ASSERT(!m_resolver);
113 } 133 }
114 134
135 DEFINE_TRACE(CryptoResultImpl)
136 {
137 visitor->trace(m_resolver);
138 CryptoResult::trace(visitor);
139 }
140
115 void CryptoResultImpl::clearResolver() 141 void CryptoResultImpl::clearResolver()
116 { 142 {
117 m_resolver = nullptr; 143 m_resolver = nullptr;
118 } 144 }
119 145
120 PassRefPtrWillBeRawPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* s criptState) 146 CryptoResultImpl* CryptoResultImpl::create(ScriptState* scriptState)
121 { 147 {
122 return adoptRefWillBeNoop(new CryptoResultImpl(scriptState)); 148 return new CryptoResultImpl(scriptState);
123 } 149 }
124 150
125 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails) 151 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails)
126 { 152 {
127 if (m_resolver) { 153 if (m_resolver) {
128 ExceptionCode ec = webCryptoErrorToExceptionCode(errorType); 154 ExceptionCode ec = webCryptoErrorToExceptionCode(errorType);
129 155
130 // Handle TypeError separately, as it cannot be created using 156 // Handle TypeError separately, as it cannot be created using
131 // DOMException. 157 // DOMException.
132 if (ec == V8TypeError) 158 if (ec == V8TypeError)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 bool CryptoResultImpl::cancelled() const 222 bool CryptoResultImpl::cancelled() const
197 { 223 {
198 return acquireLoad(&m_cancelled); 224 return acquireLoad(&m_cancelled);
199 } 225 }
200 226
201 void CryptoResultImpl::cancel() 227 void CryptoResultImpl::cancel()
202 { 228 {
203 releaseStore(&m_cancelled, 1); 229 releaseStore(&m_cancelled, 1);
204 } 230 }
205 231
206 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState)
207 : m_cancelled(0)
208 {
209 ASSERT(scriptState->contextIsValid());
210 if (scriptState->executionContext()->activeDOMObjectsAreStopped()) {
211 // If active dom objects have been stopped, avoid creating
212 // CryptoResultResolver.
213 m_resolver = nullptr;
214 } else {
215 m_resolver = Resolver::create(scriptState, this).get();
216 }
217 }
218
219 ScriptPromise CryptoResultImpl::promise() 232 ScriptPromise CryptoResultImpl::promise()
220 { 233 {
221 return m_resolver ? m_resolver->promise() : ScriptPromise(); 234 return m_resolver ? m_resolver->promise() : ScriptPromise();
222 } 235 }
223 236
224 } // namespace blink 237 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698