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

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

Issue 783423003: Make ScriptPromiseResolver RefCountedWillBeRefCountedGarbageCollected. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 if (!resolver->executionContext() || resolver->executionContext()->activeDOM ObjectsAreStopped()) 55 if (!resolver->executionContext() || resolver->executionContext()->activeDOM ObjectsAreStopped())
56 return; 56 return;
57 57
58 ScriptState::Scope scope(resolver->scriptState()); 58 ScriptState::Scope scope(resolver->scriptState());
59 v8::Isolate* isolate = resolver->scriptState()->isolate(); 59 v8::Isolate* isolate = resolver->scriptState()->isolate();
60 resolver->reject(v8::Exception::TypeError(v8String(isolate, errorDetails))); 60 resolver->reject(v8::Exception::TypeError(v8String(isolate, errorDetails)));
61 } 61 }
62 62
63 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver { 63 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver {
64 public: 64 public:
65 static PassRefPtr<ScriptPromiseResolver> create(ScriptState* scriptState, Cr yptoResultImpl* result) 65 static PassRefPtrWillBeRawPtr<ScriptPromiseResolver> create(ScriptState* scr iptState, CryptoResultImpl* result)
66 { 66 {
67 RefPtr<Resolver> resolver = adoptRef(new Resolver(scriptState, result)); 67 RefPtrWillBeRawPtr<Resolver> resolver = adoptRefWillBeNoop(new Resolver( scriptState, result));
68 resolver->suspendIfNeeded(); 68 resolver->suspendIfNeeded();
69 resolver->keepAliveWhilePending(); 69 resolver->keepAliveWhilePending();
70 return resolver.release(); 70 return resolver.release();
71 } 71 }
72 72
73 virtual void stop() override 73 virtual void stop() override
74 { 74 {
75 m_result->cancel(); 75 m_result->cancel();
76 m_result->clearResolver(); 76 m_result->clearResolver();
77 m_result = nullptr; 77 m_result = nullptr;
78 ScriptPromiseResolver::stop(); 78 ScriptPromiseResolver::stop();
79 } 79 }
80 80
81 virtual void trace(Visitor* visitor) override
82 {
83 ScriptPromiseResolver::trace(visitor);
84 }
85
81 private: 86 private:
82 Resolver(ScriptState* scriptState, CryptoResultImpl* result) 87 Resolver(ScriptState* scriptState, CryptoResultImpl* result)
83 : ScriptPromiseResolver(scriptState) 88 : ScriptPromiseResolver(scriptState)
84 , m_result(result) { } 89 , m_result(result) { }
85 RefPtr<CryptoResultImpl> m_result; 90 RefPtr<CryptoResultImpl> m_result;
86 }; 91 };
87 92
88 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType) 93 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType)
89 { 94 {
90 switch (errorType) { 95 switch (errorType) {
(...skipping 18 matching lines...) Expand all
109 CryptoResultImpl::~CryptoResultImpl() 114 CryptoResultImpl::~CryptoResultImpl()
110 { 115 {
111 ASSERT(!m_resolver); 116 ASSERT(!m_resolver);
112 } 117 }
113 118
114 void CryptoResultImpl::clearResolver() 119 void CryptoResultImpl::clearResolver()
115 { 120 {
116 m_resolver = nullptr; 121 m_resolver = nullptr;
117 } 122 }
118 123
119 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* scriptState) 124 PassRefPtrWillBeRawPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* s criptState)
120 { 125 {
121 return adoptRef(new CryptoResultImpl(scriptState)); 126 return adoptRefWillBeNoop(new CryptoResultImpl(scriptState));
122 } 127 }
123 128
124 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails) 129 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails)
125 { 130 {
126 if (m_resolver) { 131 if (m_resolver) {
132 ScriptPromiseResolver* resolver = m_resolver;
haraken 2014/12/16 13:52:45 This is unnecessary.
tasak 2014/12/17 08:40:08 Done.
127 ExceptionCode ec = webCryptoErrorToExceptionCode(errorType); 133 ExceptionCode ec = webCryptoErrorToExceptionCode(errorType);
128 134
129 // Handle TypeError separately, as it cannot be created using 135 // Handle TypeError separately, as it cannot be created using
130 // DOMException. 136 // DOMException.
131 if (ec == V8TypeError) 137 if (ec == V8TypeError)
132 rejectWithTypeError(errorDetails, m_resolver); 138 rejectWithTypeError(errorDetails, resolver);
133 else 139 else
134 m_resolver->reject(DOMException::create(ec, errorDetails)); 140 resolver->reject(DOMException::create(ec, errorDetails));
135 } 141 }
136 clearResolver(); 142 clearResolver();
137 } 143 }
138 144
139 void CryptoResultImpl::completeWithBuffer(const void* bytes, unsigned bytesSize) 145 void CryptoResultImpl::completeWithBuffer(const void* bytes, unsigned bytesSize)
140 { 146 {
141 if (m_resolver) 147 if (m_resolver)
142 m_resolver->resolve(DOMArrayBuffer::create(bytes, bytesSize)); 148 m_resolver->resolve(DOMArrayBuffer::create(bytes, bytesSize));
143 clearResolver(); 149 clearResolver();
144 } 150 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 m_resolver = Resolver::create(scriptState, this).get(); 225 m_resolver = Resolver::create(scriptState, this).get();
220 } 226 }
221 } 227 }
222 228
223 ScriptPromise CryptoResultImpl::promise() 229 ScriptPromise CryptoResultImpl::promise()
224 { 230 {
225 return m_resolver ? m_resolver->promise() : ScriptPromise(); 231 return m_resolver ? m_resolver->promise() : ScriptPromise();
226 } 232 }
227 233
228 } // namespace blink 234 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698