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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptPromiseResolver.h

Issue 2567913002: Rename ActiveDOMObject to SuspendableObject (Closed)
Patch Set: Created 4 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 // 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 #ifndef ScriptPromiseResolver_h 5 #ifndef ScriptPromiseResolver_h
6 #define ScriptPromiseResolver_h 6 #define ScriptPromiseResolver_h
7 7
8 #include "bindings/core/v8/ScopedPersistent.h" 8 #include "bindings/core/v8/ScopedPersistent.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
11 #include "bindings/core/v8/ToV8.h" 11 #include "bindings/core/v8/ToV8.h"
12 #include "core/CoreExport.h" 12 #include "core/CoreExport.h"
13 #include "core/dom/ActiveDOMObject.h"
14 #include "core/dom/ExecutionContext.h" 13 #include "core/dom/ExecutionContext.h"
14 #include "core/dom/SuspendableObject.h"
15 #include "platform/ScriptForbiddenScope.h" 15 #include "platform/ScriptForbiddenScope.h"
16 #include "platform/Timer.h" 16 #include "platform/Timer.h"
17 #include "platform/heap/Handle.h" 17 #include "platform/heap/Handle.h"
18 #include "platform/heap/SelfKeepAlive.h" 18 #include "platform/heap/SelfKeepAlive.h"
19 #include <v8.h> 19 #include <v8.h>
20 20
21 namespace blink { 21 namespace blink {
22 22
23 // This class wraps v8::Promise::Resolver and provides the following 23 // This class wraps v8::Promise::Resolver and provides the following
24 // functionalities. 24 // functionalities.
25 // - A ScriptPromiseResolver retains a ScriptState. A caller 25 // - A ScriptPromiseResolver retains a ScriptState. A caller
26 // can call resolve or reject from outside of a V8 context. 26 // can call resolve or reject from outside of a V8 context.
27 // - This class is an ActiveDOMObject and keeps track of the associated 27 // - This class is an SuspendableObject and keeps track of the associated
28 // ExecutionContext state. When the ExecutionContext is suspended, 28 // ExecutionContext state. When the ExecutionContext is suspended,
29 // resolve or reject will be delayed. When it is stopped, resolve or reject 29 // resolve or reject will be delayed. When it is stopped, resolve or reject
30 // will be ignored. 30 // will be ignored.
31 class CORE_EXPORT ScriptPromiseResolver 31 class CORE_EXPORT ScriptPromiseResolver
32 : public GarbageCollectedFinalized<ScriptPromiseResolver>, 32 : public GarbageCollectedFinalized<ScriptPromiseResolver>,
33 public ActiveDOMObject { 33 public SuspendableObject {
34 USING_GARBAGE_COLLECTED_MIXIN(ScriptPromiseResolver); 34 USING_GARBAGE_COLLECTED_MIXIN(ScriptPromiseResolver);
35 WTF_MAKE_NONCOPYABLE(ScriptPromiseResolver); 35 WTF_MAKE_NONCOPYABLE(ScriptPromiseResolver);
36 36
37 public: 37 public:
38 static ScriptPromiseResolver* create(ScriptState* scriptState) { 38 static ScriptPromiseResolver* create(ScriptState* scriptState) {
39 ScriptPromiseResolver* resolver = new ScriptPromiseResolver(scriptState); 39 ScriptPromiseResolver* resolver = new ScriptPromiseResolver(scriptState);
40 resolver->suspendIfNeeded(); 40 resolver->suspendIfNeeded();
41 return resolver; 41 return resolver;
42 } 42 }
43 43
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // reject is called. 79 // reject is called.
80 ScriptPromise promise() { 80 ScriptPromise promise() {
81 #if ENABLE(ASSERT) 81 #if ENABLE(ASSERT)
82 m_isPromiseCalled = true; 82 m_isPromiseCalled = true;
83 #endif 83 #endif
84 return m_resolver.promise(); 84 return m_resolver.promise();
85 } 85 }
86 86
87 ScriptState* getScriptState() const { return m_scriptState.get(); } 87 ScriptState* getScriptState() const { return m_scriptState.get(); }
88 88
89 // ActiveDOMObject implementation. 89 // SuspendableObject implementation.
90 void suspend() override; 90 void suspend() override;
91 void resume() override; 91 void resume() override;
92 void contextDestroyed() override { detach(); } 92 void contextDestroyed() override { detach(); }
93 93
94 // Calling this function makes the resolver release its internal resources. 94 // Calling this function makes the resolver release its internal resources.
95 // That means the associated promise will never be resolved or rejected 95 // That means the associated promise will never be resolved or rejected
96 // unless it's already been resolved or rejected. 96 // unless it's already been resolved or rejected.
97 // Do not call this function unless you truly need the behavior. 97 // Do not call this function unless you truly need the behavior.
98 void detach(); 98 void detach();
99 99
100 // Once this function is called this resolver stays alive while the 100 // Once this function is called this resolver stays alive while the
101 // promise is pending and the associated ExecutionContext isn't stopped. 101 // promise is pending and the associated ExecutionContext isn't stopped.
102 void keepAliveWhilePending(); 102 void keepAliveWhilePending();
103 103
104 DECLARE_VIRTUAL_TRACE(); 104 DECLARE_VIRTUAL_TRACE();
105 105
106 protected: 106 protected:
107 // You need to call suspendIfNeeded after the construction because 107 // You need to call suspendIfNeeded after the construction because
108 // this is an ActiveDOMObject. 108 // this is an SuspendableObject.
109 explicit ScriptPromiseResolver(ScriptState*); 109 explicit ScriptPromiseResolver(ScriptState*);
110 110
111 private: 111 private:
112 typedef ScriptPromise::InternalResolver Resolver; 112 typedef ScriptPromise::InternalResolver Resolver;
113 enum ResolutionState { 113 enum ResolutionState {
114 Pending, 114 Pending,
115 Resolving, 115 Resolving,
116 Rejecting, 116 Rejecting,
117 Detached, 117 Detached,
118 }; 118 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 #if ENABLE(ASSERT) 164 #if ENABLE(ASSERT)
165 // True if promise() is called. 165 // True if promise() is called.
166 bool m_isPromiseCalled; 166 bool m_isPromiseCalled;
167 #endif 167 #endif
168 }; 168 };
169 169
170 } // namespace blink 170 } // namespace blink
171 171
172 #endif // ScriptPromiseResolver_h 172 #endif // ScriptPromiseResolver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698