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

Side by Side Diff: Source/bindings/core/v8/ScriptPromisePropertyBase.cpp

Issue 1035623002: bindings: Use Maybe APIs in ScriptPromise (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « Source/bindings/core/v8/ScriptPromise.cpp ('k') | Source/bindings/core/v8/ScriptValue.h » ('j') | 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 #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
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
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 = resolver->CreationContext();
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, context->Global()));
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, context->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
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
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptPromise.cpp ('k') | Source/bindings/core/v8/ScriptValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698