Chromium Code Reviews| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 { | 176 { |
| 177 if (m_resolver.isEmpty()) | 177 if (m_resolver.isEmpty()) |
| 178 return ScriptPromise(); | 178 return ScriptPromise(); |
| 179 return ScriptPromise(m_resolver.getScriptState(), v8Promise()); | 179 return ScriptPromise(m_resolver.getScriptState(), v8Promise()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ScriptPromise::InternalResolver::resolve(v8::Local<v8::Value> value) | 182 void ScriptPromise::InternalResolver::resolve(v8::Local<v8::Value> value) |
| 183 { | 183 { |
| 184 if (m_resolver.isEmpty()) | 184 if (m_resolver.isEmpty()) |
| 185 return; | 185 return; |
| 186 m_resolver.v8Value().As<v8::Promise::Resolver>()->Resolve(m_resolver.context (), value); | 186 if (m_resolver.v8Value().As<v8::Promise::Resolver>()->Resolve( |
|
haraken
2016/07/15 02:38:41
Can you use v8Call macros in V8BindingMacros.h?
Y
| |
| 187 m_resolver.context(), value).IsNothing()) | |
| 188 return; | |
| 187 clear(); | 189 clear(); |
| 188 } | 190 } |
| 189 | 191 |
| 190 void ScriptPromise::InternalResolver::reject(v8::Local<v8::Value> value) | 192 void ScriptPromise::InternalResolver::reject(v8::Local<v8::Value> value) |
| 191 { | 193 { |
| 192 if (m_resolver.isEmpty()) | 194 if (m_resolver.isEmpty()) |
| 193 return; | 195 return; |
| 194 m_resolver.v8Value().As<v8::Promise::Resolver>()->Reject(m_resolver.context( ), value); | 196 if (m_resolver.v8Value().As<v8::Promise::Resolver>()->Reject( |
| 197 m_resolver.context(), value).IsNothing()) | |
| 198 return; | |
| 195 clear(); | 199 clear(); |
| 196 } | 200 } |
| 197 | 201 |
| 198 ScriptPromise::ScriptPromise() | 202 ScriptPromise::ScriptPromise() |
| 199 { | 203 { |
| 200 increaseInstanceCount(); | 204 increaseInstanceCount(); |
| 201 } | 205 } |
| 202 | 206 |
| 203 ScriptPromise::ScriptPromise(ScriptState* scriptState, v8::Local<v8::Value> valu e) | 207 ScriptPromise::ScriptPromise(ScriptState* scriptState, v8::Local<v8::Value> valu e) |
| 204 : m_scriptState(scriptState) | 208 : m_scriptState(scriptState) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 } | 302 } |
| 299 | 303 |
| 300 v8::Local<v8::Promise> ScriptPromise::rejectRaw(ScriptState* scriptState, v8::Lo cal<v8::Value> value) | 304 v8::Local<v8::Promise> ScriptPromise::rejectRaw(ScriptState* scriptState, v8::Lo cal<v8::Value> value) |
| 301 { | 305 { |
| 302 if (value.IsEmpty()) | 306 if (value.IsEmpty()) |
| 303 return v8::Local<v8::Promise>(); | 307 return v8::Local<v8::Promise>(); |
| 304 v8::Local<v8::Promise::Resolver> resolver; | 308 v8::Local<v8::Promise::Resolver> resolver; |
| 305 if (!v8::Promise::Resolver::New(scriptState->context()).ToLocal(&resolver)) | 309 if (!v8::Promise::Resolver::New(scriptState->context()).ToLocal(&resolver)) |
| 306 return v8::Local<v8::Promise>(); | 310 return v8::Local<v8::Promise>(); |
| 307 v8::Local<v8::Promise> promise = resolver->GetPromise(); | 311 v8::Local<v8::Promise> promise = resolver->GetPromise(); |
| 308 resolver->Reject(scriptState->context(), value); | 312 if (resolver->Reject(scriptState->context(), value).IsNothing()) |
| 313 return v8::Local<v8::Promise>(); | |
| 309 return promise; | 314 return promise; |
| 310 } | 315 } |
| 311 | 316 |
| 312 ScriptPromise ScriptPromise::all(ScriptState* scriptState, const Vector<ScriptPr omise>& promises) | 317 ScriptPromise ScriptPromise::all(ScriptState* scriptState, const Vector<ScriptPr omise>& promises) |
| 313 { | 318 { |
| 314 return PromiseAllHandler::all(scriptState, promises); | 319 return PromiseAllHandler::all(scriptState, promises); |
| 315 } | 320 } |
| 316 | 321 |
| 317 void ScriptPromise::increaseInstanceCount() | 322 void ScriptPromise::increaseInstanceCount() |
| 318 { | 323 { |
| 319 // An instance is only counted only on the main thread. This is because the | 324 // An instance is only counted only on the main thread. This is because the |
| 320 // leak detector can detect leaks on the main thread so far. We plan to fix | 325 // leak detector can detect leaks on the main thread so far. We plan to fix |
| 321 // the leak detector to work on worker threads (crbug.com/507224). | 326 // the leak detector to work on worker threads (crbug.com/507224). |
| 322 if (isMainThread()) | 327 if (isMainThread()) |
| 323 InstanceCounters::incrementCounter(InstanceCounters::ScriptPromiseCounte r); | 328 InstanceCounters::incrementCounter(InstanceCounters::ScriptPromiseCounte r); |
| 324 } | 329 } |
| 325 | 330 |
| 326 void ScriptPromise::decreaseInstanceCount() | 331 void ScriptPromise::decreaseInstanceCount() |
| 327 { | 332 { |
| 328 if (isMainThread()) | 333 if (isMainThread()) |
| 329 InstanceCounters::decrementCounter(InstanceCounters::ScriptPromiseCounte r); | 334 InstanceCounters::decrementCounter(InstanceCounters::ScriptPromiseCounte r); |
| 330 } | 335 } |
| 331 | 336 |
| 332 } // namespace blink | 337 } // namespace blink |
| OLD | NEW |