OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 struct WithScriptState { | 45 struct WithScriptState { |
46 // Used by ToV8Value<WithScriptState, ScriptState*>. | 46 // Used by ToV8Value<WithScriptState, ScriptState*>. |
47 static v8::Local<v8::Object> getCreationContext(ScriptState* scriptState) | 47 static v8::Local<v8::Object> getCreationContext(ScriptState* scriptState) |
48 { | 48 { |
49 return scriptState->context()->Global(); | 49 return scriptState->context()->Global(); |
50 } | 50 } |
51 }; | 51 }; |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
| 55 unsigned ScriptPromise::s_instanceCount = 0; |
| 56 |
55 ScriptPromise::InternalResolver::InternalResolver(ScriptState* scriptState) | 57 ScriptPromise::InternalResolver::InternalResolver(ScriptState* scriptState) |
56 : m_resolver(scriptState, v8::Promise::Resolver::New(scriptState->context())
) { } | 58 : m_resolver(scriptState, v8::Promise::Resolver::New(scriptState->context())
) { } |
57 | 59 |
58 v8::Local<v8::Promise> ScriptPromise::InternalResolver::v8Promise() const | 60 v8::Local<v8::Promise> ScriptPromise::InternalResolver::v8Promise() const |
59 { | 61 { |
60 if (m_resolver.isEmpty()) | 62 if (m_resolver.isEmpty()) |
61 return v8::Local<v8::Promise>(); | 63 return v8::Local<v8::Promise>(); |
62 return m_resolver.v8Value().As<v8::Promise::Resolver>()->GetPromise(); | 64 return m_resolver.v8Value().As<v8::Promise::Resolver>()->GetPromise(); |
63 } | 65 } |
64 | 66 |
(...skipping 13 matching lines...) Expand all Loading... |
78 } | 80 } |
79 | 81 |
80 void ScriptPromise::InternalResolver::reject(v8::Local<v8::Value> value) | 82 void ScriptPromise::InternalResolver::reject(v8::Local<v8::Value> value) |
81 { | 83 { |
82 if (m_resolver.isEmpty()) | 84 if (m_resolver.isEmpty()) |
83 return; | 85 return; |
84 m_resolver.v8Value().As<v8::Promise::Resolver>()->Reject(m_resolver.context(
), value); | 86 m_resolver.v8Value().As<v8::Promise::Resolver>()->Reject(m_resolver.context(
), value); |
85 clear(); | 87 clear(); |
86 } | 88 } |
87 | 89 |
| 90 ScriptPromise::ScriptPromise() |
| 91 { |
| 92 ++s_instanceCount; |
| 93 } |
| 94 |
88 ScriptPromise::ScriptPromise(ScriptState* scriptState, v8::Local<v8::Value> valu
e) | 95 ScriptPromise::ScriptPromise(ScriptState* scriptState, v8::Local<v8::Value> valu
e) |
89 : m_scriptState(scriptState) | 96 : m_scriptState(scriptState) |
90 { | 97 { |
| 98 ++s_instanceCount; |
| 99 |
91 if (value.IsEmpty()) | 100 if (value.IsEmpty()) |
92 return; | 101 return; |
93 | 102 |
94 if (!value->IsPromise()) { | 103 if (!value->IsPromise()) { |
95 m_promise = ScriptValue(scriptState, v8::Local<v8::Value>()); | 104 m_promise = ScriptValue(scriptState, v8::Local<v8::Value>()); |
96 V8ThrowException::throwTypeError(scriptState->isolate(), "the given valu
e is not a Promise"); | 105 V8ThrowException::throwTypeError(scriptState->isolate(), "the given valu
e is not a Promise"); |
97 return; | 106 return; |
98 } | 107 } |
99 m_promise = ScriptValue(scriptState, value); | 108 m_promise = ScriptValue(scriptState, value); |
100 } | 109 } |
101 | 110 |
| 111 ScriptPromise::ScriptPromise(const ScriptPromise& other) |
| 112 { |
| 113 ++s_instanceCount; |
| 114 |
| 115 this->m_scriptState = other.m_scriptState; |
| 116 this->m_promise = other.m_promise; |
| 117 } |
| 118 |
| 119 ScriptPromise::~ScriptPromise() |
| 120 { |
| 121 --s_instanceCount; |
| 122 } |
| 123 |
102 ScriptPromise ScriptPromise::then(v8::Local<v8::Function> onFulfilled, v8::Local
<v8::Function> onRejected) | 124 ScriptPromise ScriptPromise::then(v8::Local<v8::Function> onFulfilled, v8::Local
<v8::Function> onRejected) |
103 { | 125 { |
104 if (m_promise.isEmpty()) | 126 if (m_promise.isEmpty()) |
105 return ScriptPromise(); | 127 return ScriptPromise(); |
106 | 128 |
107 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); | 129 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); |
108 | 130 |
109 ASSERT(promise->IsPromise()); | 131 ASSERT(promise->IsPromise()); |
110 // Return this Promise if no handlers are given. | 132 // Return this Promise if no handlers are given. |
111 // In fact it is not the exact bahavior of Promise.prototype.then | 133 // In fact it is not the exact bahavior of Promise.prototype.then |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return v8::Local<v8::Promise>(); | 190 return v8::Local<v8::Promise>(); |
169 v8::Local<v8::Promise::Resolver> resolver; | 191 v8::Local<v8::Promise::Resolver> resolver; |
170 if (!v8::Promise::Resolver::New(scriptState->context()).ToLocal(&resolver)) | 192 if (!v8::Promise::Resolver::New(scriptState->context()).ToLocal(&resolver)) |
171 return v8::Local<v8::Promise>(); | 193 return v8::Local<v8::Promise>(); |
172 v8::Local<v8::Promise> promise = resolver->GetPromise(); | 194 v8::Local<v8::Promise> promise = resolver->GetPromise(); |
173 resolver->Reject(scriptState->context(), value); | 195 resolver->Reject(scriptState->context(), value); |
174 return promise; | 196 return promise; |
175 } | 197 } |
176 | 198 |
177 } // namespace blink | 199 } // namespace blink |
OLD | NEW |