Chromium Code Reviews| Index: Source/core/inspector/PromiseOfficer.cpp |
| diff --git a/Source/core/inspector/PromiseOfficer.cpp b/Source/core/inspector/PromiseOfficer.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..da533b75767fdccaba60732c2676d98e111b8f96 |
| --- /dev/null |
| +++ b/Source/core/inspector/PromiseOfficer.cpp |
| @@ -0,0 +1,124 @@ |
| + |
| +/* |
| + * Copyright (C) 2013 Google Inc. All rights reserved. |
|
aandrey
2014/02/25 12:36:07
2014
Alexandra Mikhaylova
2014/02/26 14:08:41
Done.
|
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "core/inspector/PromiseOfficer.h" |
| + |
| +namespace WebCore { |
| + |
| +PromiseOfficer::PromiseOfficer() { } |
| + |
| +void PromiseOfficer::addPromise(ExecutionContext* context, v8::Handle<v8::Object> promise, v8::Handle<v8::Object> parentPromise, V8PromiseCustom::PromiseState state) { |
| + int promiseHash = promise->GetIdentityHash(); |
| + PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); |
| + if (it != m_promiseDataMap.end()) { |
| + PromiseDataVector& vector = it->value; |
| + for (size_t index = 0; index < vector.size(); index++) { |
| + RefPtr<PromiseData> data = vector.at(index); |
| + ASSERT(data->getPromise() != promise); // Because we add a new promise (and don't update existing ones). |
| + } |
| + vector.append(adoptRef(new PromiseData(promise, parentPromise, state, context))); |
| + } else { |
| + PromiseDataVector vector; |
| + vector.append(adoptRef(new PromiseData(promise, parentPromise, state, context))); |
| + m_promiseDataMap.set(promiseHash, vector); |
| + } |
| + |
| + printf("Added promise: hash %d, state %d\n", promiseHash, state); |
| + if (!parentPromise->IsNull()) { |
| + printf("Promise with hash %d has parent with hash %d\n", promiseHash, parentPromise->GetIdentityHash()); |
| + } |
| +} |
| + |
| +// TODO: Do we need this method? |
| +void PromiseOfficer::updatePromise(ExecutionContext* context, v8::Handle<v8::Object> promise, v8::Handle<v8::Object> newParentPromise, V8PromiseCustom::PromiseState newState) { |
| + int promiseHash = promise->GetIdentityHash(); |
| + PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); |
| + ASSERT(it != m_promiseDataMap.end()); // This must be a promise that's already been tracked. |
| + PromiseDataVector& vector = it->value; |
| + for (size_t index = 0; index < vector.size(); index++) { |
| + if (vector.at(index)->getPromise() == promise) { |
| + vector.remove(index); |
| + vector.append(adoptRef(new PromiseData(promise, newParentPromise, newState, context))); |
| + |
| + printf("Updated promise: hash %d, state %d\n", promiseHash, newState); |
| + if (!newParentPromise->IsNull()) { |
| + printf("Promise with hash %d has parent with hash %d\n", promiseHash, newParentPromise->GetIdentityHash()); |
| + } |
| + |
| + break; |
| + } |
| + } |
| +} |
| + |
| +void PromiseOfficer::updatePromiseParent(ExecutionContext* context, v8::Handle<v8::Object> promise, v8::Handle<v8::Object> newParentPromise) { |
| + int promiseHash = promise->GetIdentityHash(); |
| + PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); |
| + ASSERT(it != m_promiseDataMap.end()); // This must be a promise that's already been tracked. |
| + PromiseDataVector& vector = it->value; |
| + for (size_t index = 0; index < vector.size(); index++) { |
| + RefPtr<PromiseData> data = vector.at(index); |
| + if (data->getPromise() == promise && data->getParentPromise() != newParentPromise) { |
| + v8::Handle<v8::Object> parentPromise = data->getParentPromise(); // For printf below. |
| + |
| + vector.remove(index); |
| + vector.append(adoptRef(new PromiseData(promise, newParentPromise, data->getState(), context))); |
| + |
| + if (!parentPromise->IsNull()) { |
| + printf("Updated promise PARENT: hash %d, old parent hash %d, new parent hash %d\n", promiseHash, parentPromise->GetIdentityHash(), newParentPromise->GetIdentityHash()); |
| + } else { |
| + printf("Updated promise PARENT: hash %d, old parent NULL, new parent hash %d\n", promiseHash, newParentPromise->GetIdentityHash()); |
| + } |
| + |
| + break; |
| + } |
| + } |
| +} |
| + |
| +void PromiseOfficer::updatePromiseState(ExecutionContext* context, v8::Handle<v8::Object> promise, V8PromiseCustom::PromiseState newState) { |
|
aandrey
2014/02/25 12:36:07
remove code dups
Alexandra Mikhaylova
2014/02/26 14:08:41
Done, but updatePromiseParent and updatePromiseSta
|
| + int promiseHash = promise->GetIdentityHash(); |
| + PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); |
| + ASSERT(it != m_promiseDataMap.end()); // This must be a promise that's already been tracked. |
| + PromiseDataVector& vector = it->value; |
| + for (size_t index = 0; index < vector.size(); index++) { |
| + RefPtr<PromiseData> data = vector.at(index); |
| + if (data->getPromise() == promise && data->getState() != newState) { |
| + vector.remove(index); |
| + vector.append(adoptRef(new PromiseData(promise, data->getParentPromise(), newState, context))); |
| + |
| + printf("Updated promise STATE: hash %d, old state %d, new state %d\n", promiseHash, data->getState(), newState); |
| + |
| + break; |
| + } |
| + } |
| +} |
| + |
| +} // namespace WebCore |