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

Side by Side Diff: Source/bindings/v8/ScriptPromiseResolverWithContext.h

Issue 263163006: Fix crash when ExecutionContext is torn down before a crypto operation has completed. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix comment typo Created 6 years, 7 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 | Annotate | Revision Log
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 ScriptPromiseResolverWithContext_h 5 #ifndef ScriptPromiseResolverWithContext_h
6 #define ScriptPromiseResolverWithContext_h 6 #define ScriptPromiseResolverWithContext_h
7 7
8 #include "bindings/v8/ScopedPersistent.h" 8 #include "bindings/v8/ScopedPersistent.h"
9 #include "bindings/v8/ScriptPromise.h" 9 #include "bindings/v8/ScriptPromise.h"
10 #include "bindings/v8/ScriptPromiseResolver.h" 10 #include "bindings/v8/ScriptPromiseResolver.h"
11 #include "bindings/v8/ScriptState.h" 11 #include "bindings/v8/ScriptState.h"
12 #include "bindings/v8/V8Binding.h" 12 #include "bindings/v8/V8Binding.h"
13 #include "core/dom/ActiveDOMObject.h" 13 #include "core/dom/ActiveDOMObject.h"
14 #include "core/dom/ExecutionContext.h" 14 #include "core/dom/ExecutionContext.h"
15 #include "platform/Timer.h" 15 #include "platform/Timer.h"
16 #include "wtf/RefCounted.h" 16 #include "wtf/RefCounted.h"
17 #include "wtf/Vector.h" 17 #include "wtf/Vector.h"
18 #include <v8.h> 18 #include <v8.h>
19 19
20 namespace WebCore { 20 namespace WebCore {
21 21
22 // This class wraps ScriptPromiseResolver and provides the following 22 // This class wraps ScriptPromiseResolver and provides the following
23 // functionalities in addition to ScriptPromiseResolver's. 23 // functionalities in addition to ScriptPromiseResolver's.
24 // - A ScriptPromiseResolverWithContext retains a ScriptState. A caller 24 // - A ScriptPromiseResolverWithContext retains a ScriptState. A caller
25 // can call resolve or reject from outside of a V8 context. 25 // can call resolve or reject from outside of a V8 context.
26 // - This class is an ActiveDOMObject and keeps track of the associated 26 // - This class is an ActiveDOMObject and keeps track of the associated
27 // ExecutionContext state. When the ExecutionContext is suspended, 27 // ExecutionContext state. When the ExecutionContext is suspended,
28 // resolve or reject will be delayed. When it is stopped, resolve or reject 28 // resolve or reject will be delayed. When it is stopped, resolve or reject
29 // will be ignored. 29 // will be ignored.
30 class ScriptPromiseResolverWithContext FINAL : public ActiveDOMObject, public Re fCounted<ScriptPromiseResolverWithContext> { 30 class ScriptPromiseResolverWithContext : public ActiveDOMObject, public RefCount ed<ScriptPromiseResolverWithContext> {
31 WTF_MAKE_NONCOPYABLE(ScriptPromiseResolverWithContext); 31 WTF_MAKE_NONCOPYABLE(ScriptPromiseResolverWithContext);
32 32
33 public: 33 public:
34 static PassRefPtr<ScriptPromiseResolverWithContext> create(ScriptState* scri ptState) 34 static PassRefPtr<ScriptPromiseResolverWithContext> create(ScriptState* scri ptState)
35 { 35 {
36 RefPtr<ScriptPromiseResolverWithContext> resolver = adoptRef(new ScriptP romiseResolverWithContext(scriptState)); 36 RefPtr<ScriptPromiseResolverWithContext> resolver = adoptRef(new ScriptP romiseResolverWithContext(scriptState));
37 resolver->suspendIfNeeded(); 37 resolver->suspendIfNeeded();
38 return resolver.release(); 38 return resolver.release();
39 } 39 }
40 40
(...skipping 26 matching lines...) Expand all
67 virtual void suspend() OVERRIDE; 67 virtual void suspend() OVERRIDE;
68 virtual void resume() OVERRIDE; 68 virtual void resume() OVERRIDE;
69 virtual void stop() OVERRIDE; 69 virtual void stop() OVERRIDE;
70 70
71 // Used by ToV8Value<ScriptPromiseResolverWithContext, ScriptState*>. 71 // Used by ToV8Value<ScriptPromiseResolverWithContext, ScriptState*>.
72 static v8::Handle<v8::Object> getCreationContext(ScriptState* scriptState) 72 static v8::Handle<v8::Object> getCreationContext(ScriptState* scriptState)
73 { 73 {
74 return scriptState->context()->Global(); 74 return scriptState->context()->Global();
75 } 75 }
76 76
77 protected:
78 explicit ScriptPromiseResolverWithContext(ScriptState*);
79
77 private: 80 private:
78 enum ResolutionState { 81 enum ResolutionState {
79 Pending, 82 Pending,
80 Resolving, 83 Resolving,
81 Rejecting, 84 Rejecting,
82 ResolvedOrRejected, 85 ResolvedOrRejected,
83 }; 86 };
84 87
85 explicit ScriptPromiseResolverWithContext(ScriptState*);
86
87 template<typename T> 88 template<typename T>
88 v8::Handle<v8::Value> toV8Value(const T& value) 89 v8::Handle<v8::Value> toV8Value(const T& value)
89 { 90 {
90 return ToV8Value<ScriptPromiseResolverWithContext, ScriptState*>::toV8Va lue(value, m_scriptState.get(), m_scriptState->isolate()); 91 return ToV8Value<ScriptPromiseResolverWithContext, ScriptState*>::toV8Va lue(value, m_scriptState.get(), m_scriptState->isolate());
91 } 92 }
92 93
93 template <typename T> 94 template <typename T>
94 void resolveOrReject(T value, ResolutionState newState) 95 void resolveOrReject(T value, ResolutionState newState)
95 { 96 {
96 if (m_state != Pending || !executionContext() || executionContext()->act iveDOMObjectsAreStopped()) 97 if (m_state != Pending || !executionContext() || executionContext()->act iveDOMObjectsAreStopped())
(...skipping 21 matching lines...) Expand all
118 ResolutionState m_state; 119 ResolutionState m_state;
119 const RefPtr<ScriptState> m_scriptState; 120 const RefPtr<ScriptState> m_scriptState;
120 Timer<ScriptPromiseResolverWithContext> m_timer; 121 Timer<ScriptPromiseResolverWithContext> m_timer;
121 RefPtr<ScriptPromiseResolver> m_resolver; 122 RefPtr<ScriptPromiseResolver> m_resolver;
122 ScopedPersistent<v8::Value> m_value; 123 ScopedPersistent<v8::Value> m_value;
123 }; 124 };
124 125
125 } // namespace WebCore 126 } // namespace WebCore
126 127
127 #endif // #ifndef ScriptPromiseResolverWithContext_h 128 #endif // #ifndef ScriptPromiseResolverWithContext_h
OLDNEW
« no previous file with comments | « LayoutTests/crypto/resources/worker-infinite-loop-generateKey.js ('k') | Source/modules/crypto/CryptoResultImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698