OLD | NEW |
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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // Eagerly finalized so as to ensure valid access to getExecutionContext() | 45 // Eagerly finalized so as to ensure valid access to getExecutionContext() |
46 // from the destructor's assert. | 46 // from the destructor's assert. |
47 EAGERLY_FINALIZE(); | 47 EAGERLY_FINALIZE(); |
48 | 48 |
49 ~ScriptPromiseResolver() override { | 49 ~ScriptPromiseResolver() override { |
50 // This assertion fails if: | 50 // This assertion fails if: |
51 // - promise() is called at least once and | 51 // - promise() is called at least once and |
52 // - this resolver is destructed before it is resolved, rejected, | 52 // - this resolver is destructed before it is resolved, rejected, |
53 // detached, the V8 isolate is terminated or the associated | 53 // detached, the V8 isolate is terminated or the associated |
54 // ExecutionContext is stopped. | 54 // ExecutionContext is stopped. |
55 ASSERT(state_ == kDetached || !is_promise_called_ || | 55 DCHECK(state_ == kDetached || !is_promise_called_ || |
56 !GetScriptState()->ContextIsValid() || !GetExecutionContext() || | 56 !GetScriptState()->ContextIsValid() || !GetExecutionContext() || |
57 GetExecutionContext()->IsContextDestroyed()); | 57 GetExecutionContext()->IsContextDestroyed()); |
58 } | 58 } |
59 #endif | 59 #endif |
60 | 60 |
61 // Anything that can be passed to toV8 can be passed to this function. | 61 // Anything that can be passed to toV8 can be passed to this function. |
62 template <typename T> | 62 template <typename T> |
63 void Resolve(T value) { | 63 void Resolve(T value) { |
64 ResolveOrReject(value, kResolving); | 64 ResolveOrReject(value, kResolving); |
65 } | 65 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 kResolving, | 115 kResolving, |
116 kRejecting, | 116 kRejecting, |
117 kDetached, | 117 kDetached, |
118 }; | 118 }; |
119 | 119 |
120 template <typename T> | 120 template <typename T> |
121 void ResolveOrReject(T value, ResolutionState new_state) { | 121 void ResolveOrReject(T value, ResolutionState new_state) { |
122 if (state_ != kPending || !GetScriptState()->ContextIsValid() || | 122 if (state_ != kPending || !GetScriptState()->ContextIsValid() || |
123 !GetExecutionContext() || GetExecutionContext()->IsContextDestroyed()) | 123 !GetExecutionContext() || GetExecutionContext()->IsContextDestroyed()) |
124 return; | 124 return; |
125 ASSERT(new_state == kResolving || new_state == kRejecting); | 125 DCHECK(new_state == kResolving || new_state == kRejecting); |
126 state_ = new_state; | 126 state_ = new_state; |
127 | 127 |
128 ScriptState::Scope scope(script_state_.Get()); | 128 ScriptState::Scope scope(script_state_.Get()); |
129 | 129 |
130 // Calling ToV8 in a ScriptForbiddenScope will trigger a RELEASE_ASSERT and | 130 // Calling ToV8 in a ScriptForbiddenScope will trigger a RELEASE_ASSERT and |
131 // cause a crash. ToV8 just invokes a constructor for wrapper creation, | 131 // cause a crash. ToV8 just invokes a constructor for wrapper creation, |
132 // which is safe (no author script can be run). Adding AllowUserAgentScript | 132 // which is safe (no author script can be run). Adding AllowUserAgentScript |
133 // directly inside createWrapper could cause a perf impact (calling | 133 // directly inside createWrapper could cause a perf impact (calling |
134 // isMainThread() every time a wrapper is created is expensive). Ideally, | 134 // isMainThread() every time a wrapper is created is expensive). Ideally, |
135 // resolveOrReject shouldn't be called inside a ScriptForbiddenScope. | 135 // resolveOrReject shouldn't be called inside a ScriptForbiddenScope. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 #if DCHECK_IS_ON() | 174 #if DCHECK_IS_ON() |
175 // True if promise() is called. | 175 // True if promise() is called. |
176 bool is_promise_called_ = false; | 176 bool is_promise_called_ = false; |
177 #endif | 177 #endif |
178 }; | 178 }; |
179 | 179 |
180 } // namespace blink | 180 } // namespace blink |
181 | 181 |
182 #endif // ScriptPromiseResolver_h | 182 #endif // ScriptPromiseResolver_h |
OLD | NEW |