OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
aandrey
2014/08/01 08:28:12
use new
Alexandra Mikhaylova
2014/08/04 14:25:06
Done.
| |
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 #include "core/inspector/PromiseTracker.h" | |
33 | |
34 #include "bindings/core/v8/ScriptCallStackFactory.h" | |
35 #include "bindings/core/v8/V8Binding.h" | |
36 | |
37 namespace blink { | |
38 | |
39 PromiseTracker::PromiseData::PromiseData(v8::Handle<v8::Object> promise, v8::Han dle<v8::Object> parentPromise, int status, v8::Handle<v8::Value> value, v8::Isol ate* isolate, PromiseTracker* tracker, bool getStack) | |
40 : m_isolate(isolate) | |
41 , m_promiseTracker(tracker) | |
42 , m_promise(m_isolate, promise) | |
43 , m_functionDetails(*(new ScriptCallFrame("", "", "", 0, 0))) | |
aandrey
2014/08/01 08:28:12
memory leak. just remove
Alexandra Mikhaylova
2014/08/04 14:25:06
Done.
| |
44 , m_parentPromise(m_isolate, parentPromise) | |
45 , m_status(status) | |
46 , m_value(m_isolate, value) | |
47 , m_weakPtrFactory(this) | |
48 { | |
49 if (getStack) { | |
aandrey
2014/08/01 08:28:12
captureStack
Alexandra Mikhaylova
2014/08/04 14:25:06
Done.
| |
50 RefPtrWillBeRawPtr<ScriptCallStack> stack = createScriptCallStack(1, tru e); | |
aandrey
2014/08/01 08:28:12
should create stack on the given isolate
Alexandra Mikhaylova
2014/08/04 14:25:06
Done.
| |
51 if (stack->size()) | |
52 m_functionDetails = stack->at(0); | |
53 } | |
54 PromiseDataWrapper* wrapper = new PromiseDataWrapper(m_weakPtrFactory.create WeakPtr()); | |
55 m_promise.setWeak(wrapper, &PromiseTracker::PromiseDataWrapper::didRemovePro mise); | |
56 } | |
57 | |
58 void PromiseTracker::enable() | |
59 { | |
60 m_isEnabled = true; | |
61 } | |
62 | |
63 void PromiseTracker::disable() | |
64 { | |
65 m_isEnabled = false; | |
66 clear(); | |
67 } | |
68 | |
69 void PromiseTracker::clear() | |
70 { | |
71 m_promiseDataMap.clear(); | |
72 } | |
73 | |
74 PromiseTracker::PromiseDataVector* PromiseTracker::getPromiseVector(v8::Handle<v 8::Object> promise) | |
75 { | |
76 ASSERT(isEnabled()); | |
77 | |
78 int promiseHash = promise->GetIdentityHash(); | |
79 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash); | |
80 if (it != m_promiseDataMap.end()) | |
81 return &it->value; | |
82 return &m_promiseDataMap.add(promiseHash, PromiseDataVector()).storedValue-> value; | |
83 } | |
84 | |
85 void PromiseTracker::didCreatePromise(ExecutionContext* context, v8::Handle<v8:: Object> promise) | |
86 { | |
87 ASSERT(isEnabled()); | |
88 | |
89 PromiseDataVector* vector = getPromiseVector(promise); | |
90 v8::Isolate* isolate = toIsolate(context); | |
91 vector->append(adoptRef(new PromiseData(promise, v8::Handle<v8::Object>(), 0 , v8::Undefined(isolate), isolate, this, true))); | |
92 } | |
93 | |
94 void PromiseTracker::didUpdatePromiseParent(ExecutionContext* context, v8::Handl e<v8::Object> promise, v8::Handle<v8::Object> parentPromise) | |
95 { | |
96 ASSERT(isEnabled()); | |
97 | |
98 PromiseDataVector* vector = getPromiseVector(promise); | |
99 bool found = false; | |
100 for (size_t index = 0; index < vector->size(); ++index) { | |
101 RefPtr<PromiseData> data = (*vector)[index]; | |
102 if (data->m_promise == promise) { | |
103 found = true; | |
104 data->m_parentPromise.set(data->m_isolate, parentPromise); | |
105 break; | |
106 } | |
107 } | |
108 if (!found) { | |
109 v8::Isolate* isolate = toIsolate(context); | |
110 vector->append(adoptRef(new PromiseData(promise, parentPromise, 0, v8::U ndefined(isolate), isolate, this))); | |
111 } | |
112 } | |
113 | |
114 void PromiseTracker::didUpdatePromiseStatus(ExecutionContext* context, v8::Handl e<v8::Object> promise, int status, v8::Handle<v8::Value> value) | |
115 { | |
116 ASSERT(isEnabled()); | |
117 | |
118 PromiseDataVector* vector = getPromiseVector(promise); | |
119 bool found = false; | |
120 for (size_t index = 0; index < vector->size(); ++index) { | |
121 RefPtr<PromiseData> data = (*vector)[index]; | |
122 if (data->m_promise == promise) { | |
123 found = true; | |
124 data->m_status = status; | |
125 data->m_value.set(data->m_isolate, value); | |
126 break; | |
127 } | |
128 } | |
129 if (!found) | |
130 vector->append(adoptRef(new PromiseData(promise, v8::Handle<v8::Object>( ), status, value, toIsolate(context), this))); | |
131 } | |
132 | |
133 void PromiseTracker::didRemovePromise(v8::Handle<v8::Object> promise) | |
134 { | |
135 ASSERT(isEnabled()); | |
136 | |
137 PromiseDataVector* vector = getPromiseVector(promise); | |
138 ASSERT(vector->size() >= 1); | |
139 bool found = false; | |
140 for (size_t index = 0; index < vector->size(); ++index) { | |
141 RefPtr<PromiseData> data = (*vector)[index]; | |
142 if (data->m_promise == promise) { | |
143 found = true; | |
144 vector->remove(index); | |
145 break; | |
146 } | |
147 } | |
148 if (vector->size() == 0) | |
149 m_promiseDataMap.remove(promise->GetIdentityHash()); | |
150 } | |
151 | |
152 void PromiseTracker::PromiseDataWrapper::didRemovePromise(const v8::WeakCallback Data<v8::Object, PromiseDataWrapper>& data) | |
153 { | |
aandrey
2014/08/01 08:28:12
memory leak for PromiseDataWrapper. use OwnPtr
Alexandra Mikhaylova
2014/08/04 14:25:06
Thanks, done.
| |
154 | |
155 PromiseData* promiseData = data.GetParameter()->m_data.get(); | |
aandrey
2014/08/01 08:28:12
use WeakPtr<PromiseData>
Alexandra Mikhaylova
2014/08/04 14:25:06
Done.
| |
156 if (!(promiseData && promiseData->m_promiseTracker->isEnabled())) | |
157 return; | |
158 | |
159 promiseData->m_promiseTracker->didRemovePromise(promiseData->m_promise.newLo cal(promiseData->m_isolate)); | |
160 } | |
161 | |
162 } // namespace blink | |
OLD | NEW |