Chromium Code Reviews| 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 #ifndef PromiseOfficer_h | |
| 32 #define PromiseOfficer_h | |
| 33 | |
| 34 #include <v8.h> | |
| 35 #include "bindings/v8/custom/V8PromiseCustom.h" | |
| 36 #include "bindings/v8/ScopedPersistent.h" | |
| 37 #include "bindings/v8/ScriptCallStackFactory.h" | |
| 38 #include "wtf/HashMap.h" | |
| 39 #include "wtf/Noncopyable.h" | |
| 40 #include "wtf/RefPtr.h" | |
| 41 #include "wtf/Vector.h" | |
| 42 | |
| 43 namespace WebCore { | |
| 44 | |
| 45 class ExecutionContext; | |
| 46 class ScriptCallStack; | |
| 47 | |
| 48 class PromiseOfficer { | |
| 49 WTF_MAKE_NONCOPYABLE(PromiseOfficer); | |
| 50 public: | |
| 51 PromiseOfficer() | |
| 52 : m_isEnabled(false) | |
|
aandrey
2014/02/28 16:08:13
make all in one line:
PromiseOfficer() : m_isEnabl
Alexandra Mikhaylova
2014/03/03 14:04:25
Done.
| |
| 53 { | |
| 54 } | |
| 55 | |
| 56 bool isEnabled() const { return m_isEnabled; } | |
| 57 void enable(); | |
| 58 void disable(); | |
| 59 | |
| 60 void clear(); | |
| 61 | |
| 62 void didCreatePromise(ExecutionContext* context, v8::Handle<v8::Object> prom ise, v8::Handle<v8::Object> parentPromise, V8PromiseCustom::PromiseState state); | |
|
aandrey
2014/02/28 16:08:13
nit: remove "state", leave just V8PromiseCustom::P
Alexandra Mikhaylova
2014/03/03 14:04:25
Done.
| |
| 63 void didUpdatePromiseParent(v8::Handle<v8::Object> promise, v8::Handle<v8::O bject> parentPromise); | |
| 64 void didUpdatePromiseState(v8::Handle<v8::Object> promise, V8PromiseCustom:: PromiseState state, v8::Handle<v8::Value> result); | |
|
aandrey
2014/02/28 16:08:13
remove "state"
Alexandra Mikhaylova
2014/03/03 14:04:25
Done.
| |
| 65 | |
| 66 private: | |
| 67 class PromiseData { | |
| 68 public: | |
| 69 PromiseData(v8::Handle<v8::Object> promise, v8::Handle<v8::Object> paren tPromise, v8::Handle<v8::Value> result, V8PromiseCustom::PromiseState state, dou ble timestamp, v8::Isolate* isolate) | |
|
aandrey
2014/02/28 16:08:13
move to cpp
Alexandra Mikhaylova
2014/03/03 14:04:25
Done.
| |
| 70 : m_isolate(isolate) | |
| 71 , m_promise(m_isolate, promise) | |
| 72 , m_parentPromise(m_isolate, parentPromise) | |
| 73 , m_result(m_isolate, result) | |
| 74 , m_state(state) | |
| 75 , m_timeOnCreate(timestamp) | |
| 76 , m_timeOnSettle(-1) | |
| 77 , m_callStackOnCreate(createScriptCallStack(ScriptCallStack::maxCall StackSizeToCapture, true)) | |
| 78 , m_callStackOnSettle(RefPtr<ScriptCallStack>()) | |
| 79 { | |
| 80 } | |
| 81 | |
| 82 v8::Handle<v8::Object> getPromise() | |
|
aandrey
2014/02/28 16:08:13
can you remove all these methods from the header f
Alexandra Mikhaylova
2014/03/03 14:04:25
Done.
| |
| 83 { | |
| 84 return m_promise.newLocal(m_isolate); | |
| 85 } | |
| 86 | |
| 87 v8::Handle<v8::Object> getParentPromise() | |
| 88 { | |
| 89 return m_parentPromise.newLocal(m_isolate); | |
| 90 } | |
| 91 | |
| 92 v8::Handle<v8::Value> getResult() | |
| 93 { | |
| 94 return m_result.newLocal(m_isolate); | |
| 95 } | |
| 96 | |
| 97 V8PromiseCustom::PromiseState getState() | |
| 98 { | |
| 99 return m_state; | |
| 100 } | |
| 101 | |
| 102 void setParentPromise(v8::Handle<v8::Object> parentPromise) | |
| 103 { | |
| 104 m_parentPromise.set(m_isolate, parentPromise); | |
| 105 } | |
| 106 | |
| 107 void setResult(v8::Handle<v8::Value> result) | |
| 108 { | |
| 109 m_result.set(m_isolate, result); | |
| 110 } | |
| 111 | |
| 112 void setState(V8PromiseCustom::PromiseState state) | |
| 113 { | |
| 114 m_state = state; | |
| 115 } | |
| 116 | |
| 117 void didSettlePromise(double timestamp) | |
| 118 { | |
| 119 m_timeOnSettle = timestamp; | |
| 120 m_callStackOnSettle = createScriptCallStack(ScriptCallStack::maxCall StackSizeToCapture, true); | |
| 121 } | |
| 122 | |
| 123 private: | |
| 124 v8::Isolate* m_isolate; | |
| 125 | |
| 126 ScopedPersistent<v8::Object> m_promise; | |
| 127 ScopedPersistent<v8::Object> m_parentPromise; | |
| 128 ScopedPersistent<v8::Value> m_result; | |
| 129 V8PromiseCustom::PromiseState m_state; | |
| 130 | |
| 131 // Time in milliseconds. | |
| 132 double m_timeOnCreate; | |
| 133 double m_timeOnSettle; | |
| 134 | |
| 135 RefPtr<ScriptCallStack> m_callStackOnCreate; | |
| 136 RefPtr<ScriptCallStack> m_callStackOnSettle; | |
| 137 }; | |
| 138 | |
| 139 bool m_isEnabled; | |
| 140 typedef Vector<PromiseData*> PromiseDataVector; | |
|
aandrey
2014/02/28 16:08:13
why Vector<PromiseData*>?
I think Vector<PromiseDa
Alexandra Mikhaylova
2014/03/03 14:04:25
Vector::append copies its argument, so I think it'
| |
| 141 typedef HashMap<int, PromiseDataVector> PromiseDataMap; | |
| 142 PromiseDataMap m_promiseDataMap; | |
| 143 }; | |
| 144 | |
| 145 } // namespace WebCore | |
| 146 | |
| 147 #endif // !defined(PromiseOfficer_h) | |
| OLD | NEW |