OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 |
| 33 #include "bindings/v8/ScriptCallStackFactory.h" |
| 34 #include "core/inspector/PromiseTracker.h" |
| 35 #include "wtf/CurrentTime.h" |
| 36 |
| 37 namespace WebCore { |
| 38 |
| 39 PromiseTracker::PromiseData::PromiseData(const ScriptObject& promise, const Scri
ptObject& parentPromise, const ScriptValue& result, V8PromiseCustom::PromiseStat
e state, double timestamp) |
| 40 : m_promise(promise) |
| 41 , m_parentPromise(parentPromise) |
| 42 , m_result(result) |
| 43 , m_state(state) |
| 44 , m_timeOnCreate(timestamp) |
| 45 , m_timeOnSettle(-1) |
| 46 , m_callStackOnCreate(createScriptCallStack(ScriptCallStack::maxCallStackSiz
eToCapture, true)) |
| 47 { |
| 48 } |
| 49 |
| 50 void PromiseTracker::PromiseData::didSettlePromise(double timestamp) |
| 51 { |
| 52 m_timeOnSettle = timestamp; |
| 53 m_callStackOnSettle = createScriptCallStack(ScriptCallStack::maxCallStackSiz
eToCapture, true); |
| 54 } |
| 55 |
| 56 void PromiseTracker::enable() |
| 57 { |
| 58 m_isEnabled = true; |
| 59 } |
| 60 |
| 61 void PromiseTracker::disable() |
| 62 { |
| 63 m_isEnabled = false; |
| 64 clear(); |
| 65 } |
| 66 |
| 67 void PromiseTracker::clear() |
| 68 { |
| 69 m_promiseDataMap.clear(); |
| 70 } |
| 71 |
| 72 void PromiseTracker::didCreatePromise(const ScriptObject& promise) |
| 73 { |
| 74 ASSERT(isEnabled()); |
| 75 |
| 76 double timestamp = currentTimeMS(); |
| 77 m_promiseDataMap.set(promise, adoptRef(new PromiseData(promise, ScriptObject
(), ScriptValue(), V8PromiseCustom::Pending, timestamp))); |
| 78 } |
| 79 |
| 80 void PromiseTracker::didUpdatePromiseParent(const ScriptObject& promise, const S
criptObject& parentPromise) |
| 81 { |
| 82 ASSERT(isEnabled()); |
| 83 |
| 84 RefPtr<PromiseData> data = m_promiseDataMap.get(promise); |
| 85 ASSERT(data != NULL && data->m_promise == promise); |
| 86 data->m_parentPromise = parentPromise; |
| 87 } |
| 88 |
| 89 void PromiseTracker::didUpdatePromiseState(const ScriptObject& promise, V8Promis
eCustom::PromiseState state, const ScriptValue& result) |
| 90 { |
| 91 ASSERT(isEnabled()); |
| 92 |
| 93 double timestamp = currentTimeMS(); |
| 94 RefPtr<PromiseData> data = m_promiseDataMap.get(promise); |
| 95 ASSERT(data != NULL && data->m_promise == promise); |
| 96 data->m_state = state; |
| 97 data->m_result = result; |
| 98 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte
d) |
| 99 data->didSettlePromise(timestamp); |
| 100 } |
| 101 |
| 102 } // namespace WebCore |
OLD | NEW |