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

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

Issue 2516553002: Never resolve promises inside ScriptForbiddenScopes. (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 13 #include "core/dom/ActiveDOMObject.h"
14 #include "core/dom/ExecutionContext.h" 14 #include "core/dom/ExecutionContext.h"
15 #include "platform/ScriptForbiddenScope.h"
15 #include "platform/Timer.h" 16 #include "platform/Timer.h"
16 #include "platform/heap/Handle.h" 17 #include "platform/heap/Handle.h"
17 #include "platform/heap/SelfKeepAlive.h" 18 #include "platform/heap/SelfKeepAlive.h"
18 #include <v8.h> 19 #include <v8.h>
19 20
20 namespace blink { 21 namespace blink {
21 22
22 // This class wraps v8::Promise::Resolver and provides the following 23 // This class wraps v8::Promise::Resolver and provides the following
23 // functionalities. 24 // functionalities.
24 // - A ScriptPromiseResolver retains a ScriptState. A caller 25 // - A ScriptPromiseResolver retains a ScriptState. A caller
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ScriptState::Scope scope(m_scriptState.get()); 129 ScriptState::Scope scope(m_scriptState.get());
129 m_value.set(m_scriptState->isolate(), 130 m_value.set(m_scriptState->isolate(),
130 toV8(value, m_scriptState->context()->Global(), 131 toV8(value, m_scriptState->context()->Global(),
131 m_scriptState->isolate())); 132 m_scriptState->isolate()));
132 133
133 if (getExecutionContext()->activeDOMObjectsAreSuspended()) { 134 if (getExecutionContext()->activeDOMObjectsAreSuspended()) {
134 // Retain this object until it is actually resolved or rejected. 135 // Retain this object until it is actually resolved or rejected.
135 keepAliveWhilePending(); 136 keepAliveWhilePending();
136 return; 137 return;
137 } 138 }
139 // TODO(esprehn): This is a hack, instead we should RELEASE_ASSERT that
140 // script is allowed, and v8 should be running the entry hooks below and
141 // crashing if script is forbidden. We should then audit all users of
142 // ScriptPromiseResolver and the related specs and switch to an async
143 // resolve.
144 // See: http://crbug.com/663476
145 if (ScriptForbiddenScope::isScriptForbidden()) {
146 m_timer.startOneShot(0, BLINK_FROM_HERE);
147 return;
148 }
138 resolveOrRejectImmediately(); 149 resolveOrRejectImmediately();
139 } 150 }
140 151
141 void resolveOrRejectImmediately(); 152 void resolveOrRejectImmediately();
142 void onTimerFired(TimerBase*); 153 void onTimerFired(TimerBase*);
143 154
144 ResolutionState m_state; 155 ResolutionState m_state;
145 const RefPtr<ScriptState> m_scriptState; 156 const RefPtr<ScriptState> m_scriptState;
146 Timer<ScriptPromiseResolver> m_timer; 157 Timer<ScriptPromiseResolver> m_timer;
147 Resolver m_resolver; 158 Resolver m_resolver;
148 ScopedPersistent<v8::Value> m_value; 159 ScopedPersistent<v8::Value> m_value;
149 160
150 // To support keepAliveWhilePending(), this object needs to keep itself 161 // To support keepAliveWhilePending(), this object needs to keep itself
151 // alive while in that state. 162 // alive while in that state.
152 SelfKeepAlive<ScriptPromiseResolver> m_keepAlive; 163 SelfKeepAlive<ScriptPromiseResolver> m_keepAlive;
153 164
154 #if ENABLE(ASSERT) 165 #if ENABLE(ASSERT)
155 // True if promise() is called. 166 // True if promise() is called.
156 bool m_isPromiseCalled; 167 bool m_isPromiseCalled;
157 #endif 168 #endif
158 }; 169 };
159 170
160 } // namespace blink 171 } // namespace blink
161 172
162 #endif // ScriptPromiseResolver_h 173 #endif // ScriptPromiseResolver_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698