Chromium Code Reviews| 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 #include "config.h" | 5 #include "config.h" |
| 6 #include "bindings/core/v8/ScriptPromisePropertyBase.h" | 6 #include "bindings/core/v8/ScriptPromisePropertyBase.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScopedPersistent.h" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 { | 30 { |
| 31 data.GetParameter()->clear(); | 31 data.GetParameter()->clear(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 ScriptPromise ScriptPromisePropertyBase::promise(DOMWrapperWorld& world) | 34 ScriptPromise ScriptPromisePropertyBase::promise(DOMWrapperWorld& world) |
| 35 { | 35 { |
| 36 if (!executionContext()) | 36 if (!executionContext()) |
| 37 return ScriptPromise(); | 37 return ScriptPromise(); |
| 38 | 38 |
| 39 v8::HandleScope handleScope(m_isolate); | 39 v8::HandleScope handleScope(m_isolate); |
| 40 v8::Handle<v8::Context> context = toV8Context(executionContext(), world); | 40 v8::Local<v8::Context> context = toV8Context(executionContext(), world); |
| 41 if (context.IsEmpty()) | 41 if (context.IsEmpty()) |
| 42 return ScriptPromise(); | 42 return ScriptPromise(); |
| 43 ScriptState* scriptState = ScriptState::from(context); | 43 ScriptState* scriptState = ScriptState::from(context); |
| 44 ScriptState::Scope scope(scriptState); | 44 ScriptState::Scope scope(scriptState); |
| 45 | 45 |
| 46 v8::Handle<v8::Object> wrapper = ensureHolderWrapper(scriptState); | 46 v8::Local<v8::Object> wrapper = ensureHolderWrapper(scriptState); |
| 47 ASSERT(wrapper->CreationContext() == context); | 47 ASSERT(wrapper->CreationContext() == context); |
| 48 | 48 |
| 49 v8::Handle<v8::Value> cachedPromise = V8HiddenValue::getHiddenValue(m_isolat e, wrapper, promiseName()); | 49 v8::Local<v8::Value> cachedPromise = V8HiddenValue::getHiddenValue(m_isolate , wrapper, promiseName()); |
| 50 if (!cachedPromise.IsEmpty()) | 50 if (!cachedPromise.IsEmpty()) |
| 51 return ScriptPromise(scriptState, cachedPromise); | 51 return ScriptPromise(scriptState, cachedPromise); |
| 52 | 52 |
| 53 // Create and cache the Promise | 53 // Create and cache the Promise |
| 54 v8::Handle<v8::Promise::Resolver> resolver = v8::Promise::Resolver::New(m_is olate); | 54 v8::Local<v8::Promise::Resolver> resolver; |
| 55 v8::Handle<v8::Promise> promise = resolver->GetPromise(); | 55 if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) |
| 56 return ScriptPromise(); | |
| 57 v8::Local<v8::Promise> promise = resolver->GetPromise(); | |
| 56 V8HiddenValue::setHiddenValue(m_isolate, wrapper, promiseName(), promise); | 58 V8HiddenValue::setHiddenValue(m_isolate, wrapper, promiseName(), promise); |
| 57 | 59 |
| 58 switch (m_state) { | 60 switch (m_state) { |
| 59 case Pending: | 61 case Pending: |
| 60 // Cache the resolver too | 62 // Cache the resolver too |
| 61 V8HiddenValue::setHiddenValue(m_isolate, wrapper, resolverName(), resolv er); | 63 V8HiddenValue::setHiddenValue(m_isolate, wrapper, resolverName(), resolv er); |
| 62 break; | 64 break; |
| 63 case Resolved: | 65 case Resolved: |
| 64 case Rejected: | 66 case Rejected: |
| 65 resolveOrRejectInternal(resolver); | 67 resolveOrRejectInternal(resolver); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 102 } |
| 101 | 103 |
| 102 void ScriptPromisePropertyBase::resetBase() | 104 void ScriptPromisePropertyBase::resetBase() |
| 103 { | 105 { |
| 104 clearWrappers(); | 106 clearWrappers(); |
| 105 m_state = Pending; | 107 m_state = Pending; |
| 106 } | 108 } |
| 107 | 109 |
| 108 void ScriptPromisePropertyBase::resolveOrRejectInternal(v8::Handle<v8::Promise:: Resolver> resolver) | 110 void ScriptPromisePropertyBase::resolveOrRejectInternal(v8::Handle<v8::Promise:: Resolver> resolver) |
| 109 { | 111 { |
| 112 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); | |
|
haraken
2015/03/25 04:29:59
Not directly related to your CL, ScriptPromiseProp
bashi
2015/03/25 04:56:00
Added a todo comment.
yhirano
2015/03/25 07:39:08
No, I don't think so. ScriptPromiseProperty is des
bashi
2015/03/25 08:01:46
Ah, I should have read the code carefully. Thanks.
haraken
2015/03/25 09:04:23
Thanks for the catch, you're right :)
| |
| 110 switch (m_state) { | 113 switch (m_state) { |
| 111 case Pending: | 114 case Pending: |
| 112 ASSERT_NOT_REACHED(); | 115 ASSERT_NOT_REACHED(); |
| 113 break; | 116 break; |
| 114 case Resolved: | 117 case Resolved: |
| 115 resolver->Resolve(resolvedValue(m_isolate, resolver->CreationContext()-> Global())); | 118 resolver->Resolve(context, resolvedValue(m_isolate, resolver->CreationCo ntext()->Global())); |
|
yhirano
2015/03/25 07:39:08
resolver->CreationContext() can be replaced with |
bashi
2015/03/25 08:01:46
Done.
| |
| 116 break; | 119 break; |
| 117 case Rejected: | 120 case Rejected: |
| 118 resolver->Reject(rejectedValue(m_isolate, resolver->CreationContext()->G lobal())); | 121 resolver->Reject(context, rejectedValue(m_isolate, resolver->CreationCon text()->Global())); |
| 119 break; | 122 break; |
| 120 } | 123 } |
| 121 } | 124 } |
| 122 | 125 |
| 123 v8::Local<v8::Object> ScriptPromisePropertyBase::ensureHolderWrapper(ScriptState * scriptState) | 126 v8::Local<v8::Object> ScriptPromisePropertyBase::ensureHolderWrapper(ScriptState * scriptState) |
| 124 { | 127 { |
| 125 v8::Local<v8::Context> context = scriptState->context(); | 128 v8::Local<v8::Context> context = scriptState->context(); |
| 126 size_t i = 0; | 129 size_t i = 0; |
| 127 while (i < m_wrappers.size()) { | 130 while (i < m_wrappers.size()) { |
| 128 const OwnPtr<ScopedPersistent<v8::Object>>& persistent = m_wrappers[i]; | 131 const OwnPtr<ScopedPersistent<v8::Object>>& persistent = m_wrappers[i]; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 ASSERT_NOT_REACHED(); | 192 ASSERT_NOT_REACHED(); |
| 190 return v8::Handle<v8::String>(); | 193 return v8::Handle<v8::String>(); |
| 191 } | 194 } |
| 192 | 195 |
| 193 DEFINE_TRACE(ScriptPromisePropertyBase) | 196 DEFINE_TRACE(ScriptPromisePropertyBase) |
| 194 { | 197 { |
| 195 ContextLifecycleObserver::trace(visitor); | 198 ContextLifecycleObserver::trace(visitor); |
| 196 } | 199 } |
| 197 | 200 |
| 198 } // namespace blink | 201 } // namespace blink |
| OLD | NEW |