Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
| 2 /* | |
| 3 * 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.
| |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are | |
| 7 * met: | |
| 8 * | |
| 9 * * Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * * Redistributions in binary form must reproduce the above | |
| 12 * copyright notice, this list of conditions and the following disclaimer | |
| 13 * in the documentation and/or other materials provided with the | |
| 14 * distribution. | |
| 15 * * Neither the name of Google Inc. nor the names of its | |
| 16 * contributors may be used to endorse or promote products derived from | |
| 17 * this software without specific prior written permission. | |
| 18 * | |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 30 */ | |
| 31 | |
| 32 #include "config.h" | |
| 33 #include "core/inspector/PromiseOfficer.h" | |
| 34 | |
| 35 namespace WebCore { | |
| 36 | |
| 37 PromiseOfficer::PromiseOfficer() { } | |
| 38 | |
| 39 void PromiseOfficer::addPromise(ExecutionContext* context, v8::Handle<v8::Object > promise, v8::Handle<v8::Object> parentPromise, V8PromiseCustom::PromiseState s tate) { | |
| 40 int promiseHash = promise->GetIdentityHash(); | |
| 41 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); | |
| 42 if (it != m_promiseDataMap.end()) { | |
| 43 PromiseDataVector& vector = it->value; | |
| 44 for (size_t index = 0; index < vector.size(); index++) { | |
| 45 RefPtr<PromiseData> data = vector.at(index); | |
| 46 ASSERT(data->getPromise() != promise); // Because we add a new promi se (and don't update existing ones). | |
| 47 } | |
| 48 vector.append(adoptRef(new PromiseData(promise, parentPromise, state, co ntext))); | |
| 49 } else { | |
| 50 PromiseDataVector vector; | |
| 51 vector.append(adoptRef(new PromiseData(promise, parentPromise, state, co ntext))); | |
| 52 m_promiseDataMap.set(promiseHash, vector); | |
| 53 } | |
| 54 | |
| 55 printf("Added promise: hash %d, state %d\n", promiseHash, state); | |
| 56 if (!parentPromise->IsNull()) { | |
| 57 printf("Promise with hash %d has parent with hash %d\n", promiseHash, pa rentPromise->GetIdentityHash()); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 // TODO: Do we need this method? | |
| 62 void PromiseOfficer::updatePromise(ExecutionContext* context, v8::Handle<v8::Obj ect> promise, v8::Handle<v8::Object> newParentPromise, V8PromiseCustom::PromiseS tate newState) { | |
| 63 int promiseHash = promise->GetIdentityHash(); | |
| 64 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); | |
| 65 ASSERT(it != m_promiseDataMap.end()); // This must be a promise that's alrea dy been tracked. | |
| 66 PromiseDataVector& vector = it->value; | |
| 67 for (size_t index = 0; index < vector.size(); index++) { | |
| 68 if (vector.at(index)->getPromise() == promise) { | |
| 69 vector.remove(index); | |
| 70 vector.append(adoptRef(new PromiseData(promise, newParentPromise, ne wState, context))); | |
| 71 | |
| 72 printf("Updated promise: hash %d, state %d\n", promiseHash, newState ); | |
| 73 if (!newParentPromise->IsNull()) { | |
| 74 printf("Promise with hash %d has parent with hash %d\n", promise Hash, newParentPromise->GetIdentityHash()); | |
| 75 } | |
| 76 | |
| 77 break; | |
| 78 } | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void PromiseOfficer::updatePromiseParent(ExecutionContext* context, v8::Handle<v 8::Object> promise, v8::Handle<v8::Object> newParentPromise) { | |
| 83 int promiseHash = promise->GetIdentityHash(); | |
| 84 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); | |
| 85 ASSERT(it != m_promiseDataMap.end()); // This must be a promise that's alrea dy been tracked. | |
| 86 PromiseDataVector& vector = it->value; | |
| 87 for (size_t index = 0; index < vector.size(); index++) { | |
| 88 RefPtr<PromiseData> data = vector.at(index); | |
| 89 if (data->getPromise() == promise && data->getParentPromise() != newPare ntPromise) { | |
| 90 v8::Handle<v8::Object> parentPromise = data->getParentPromise(); // For printf below. | |
| 91 | |
| 92 vector.remove(index); | |
| 93 vector.append(adoptRef(new PromiseData(promise, newParentPromise, da ta->getState(), context))); | |
| 94 | |
| 95 if (!parentPromise->IsNull()) { | |
| 96 printf("Updated promise PARENT: hash %d, old parent hash %d, new parent hash %d\n", promiseHash, parentPromise->GetIdentityHash(), newParentProm ise->GetIdentityHash()); | |
| 97 } else { | |
| 98 printf("Updated promise PARENT: hash %d, old parent NULL, new pa rent hash %d\n", promiseHash, newParentPromise->GetIdentityHash()); | |
| 99 } | |
| 100 | |
| 101 break; | |
| 102 } | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 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
| |
| 107 int promiseHash = promise->GetIdentityHash(); | |
| 108 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); | |
| 109 ASSERT(it != m_promiseDataMap.end()); // This must be a promise that's alrea dy been tracked. | |
| 110 PromiseDataVector& vector = it->value; | |
| 111 for (size_t index = 0; index < vector.size(); index++) { | |
| 112 RefPtr<PromiseData> data = vector.at(index); | |
| 113 if (data->getPromise() == promise && data->getState() != newState) { | |
| 114 vector.remove(index); | |
| 115 vector.append(adoptRef(new PromiseData(promise, data->getParentPromi se(), newState, context))); | |
| 116 | |
| 117 printf("Updated promise STATE: hash %d, old state %d, new state %d\n ", promiseHash, data->getState(), newState); | |
| 118 | |
| 119 break; | |
| 120 } | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 } // namespace WebCore | |
| OLD | NEW |