Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(857)

Side by Side Diff: Source/core/inspector/PromiseOfficer.cpp

Issue 177773002: Support Promises instrumentation on backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "bindings/v8/V8Binding.h"
35 #include "core/inspector/PromiseOfficer.h"
36 #include "wtf/CurrentTime.h"
37
38 namespace WebCore {
39
40 PromiseOfficer::PromiseData::PromiseData(v8::Handle<v8::Object> promise, v8::Han dle<v8::Object> parentPromise, v8::Handle<v8::Value> result, V8PromiseCustom::Pr omiseState state, double timestamp, v8::Isolate* isolate)
41 : m_isolate(isolate)
42 , m_promise(m_isolate, promise)
43 , m_parentPromise(m_isolate, parentPromise)
44 , m_result(m_isolate, result)
45 , m_state(state)
46 , m_timeOnCreate(timestamp)
47 , m_timeOnSettle(-1)
48 , m_callStackOnCreate(createScriptCallStack(ScriptCallStack::maxCallStackSiz eToCapture, true))
49 , m_callStackOnSettle(RefPtr<ScriptCallStack>())
yurys 2014/03/05 15:23:35 compiler will generate this automatically
Alexandra Mikhaylova 2014/03/07 11:11:44 Done.
50 {
51 }
52
53 void PromiseOfficer::PromiseData::didSettlePromise(double timestamp)
54 {
55 m_timeOnSettle = timestamp;
56 m_callStackOnSettle = createScriptCallStack(ScriptCallStack::maxCallStackSiz eToCapture, true);
57 }
58
59 void PromiseOfficer::enable()
60 {
61 m_isEnabled = true;
62 }
63
64 void PromiseOfficer::disable()
65 {
66 m_isEnabled = false;
67 clear();
68 }
69
70 void PromiseOfficer::clear()
71 {
72 m_promiseDataMap.clear();
73 }
74
75 void PromiseOfficer::didCreatePromise(ExecutionContext* context, v8::Handle<v8:: Object> promise)
76 {
77 ASSERT(isEnabled());
78
79 double timestamp = currentTimeMS();
80
81 int promiseHash = promise->GetIdentityHash();
82 PromiseDataVector* vector;
83 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash);
yurys 2014/03/05 15:23:35 Why not use a HashMap (with appropriate HashTraits
Alexandra Mikhaylova 2014/03/07 11:11:44 Thanks, fixed it.
84 if (it != m_promiseDataMap.end())
85 vector = &it->value;
86 else
87 vector = &m_promiseDataMap.add(promiseHash, PromiseDataVector()).storedV alue->value;
88 v8::Isolate* isolate = toIsolate(context);
89 vector->append(adoptRef(new PromiseData(promise, v8::Handle<v8::Object>(), v 8::Undefined(isolate), V8PromiseCustom::Pending, timestamp, isolate)));
90 }
91
92 void PromiseOfficer::didUpdatePromiseParent(v8::Handle<v8::Object> promise, v8:: Handle<v8::Object> parentPromise)
93 {
94 ASSERT(isEnabled());
95
96 int promiseHash = promise->GetIdentityHash();
97 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash);
98 PromiseDataVector& vector = it->value;
99 for (size_t index = 0; index < vector.size(); ++index) {
100 RefPtr<PromiseData> data = vector[index];
101 if (data->m_promise == promise) {
102 data->m_parentPromise.set(data->m_isolate, parentPromise);
103 break;
104 }
105 }
106 }
107
108 void PromiseOfficer::didUpdatePromiseState(v8::Handle<v8::Object> promise, V8Pro miseCustom::PromiseState state, v8::Handle<v8::Value> result)
109 {
110 ASSERT(isEnabled());
111
112 double timestamp = currentTimeMS();
113
114 int promiseHash = promise->GetIdentityHash();
115 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash);
116 PromiseDataVector& vector = it->value;
117 for (size_t index = 0; index < vector.size(); ++index) {
118 RefPtr<PromiseData> data = vector[index];
119 if (data->m_promise == promise) {
120 data->m_state = state;
121 data->m_result.set(data->m_isolate, result);
122 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom: :Rejected)
123 data->didSettlePromise(timestamp);
124 break;
125 }
126 }
127 }
128
129 } // namespace WebCore
OLDNEW
« Source/core/inspector/InspectorInstrumentation.idl ('K') | « Source/core/inspector/PromiseOfficer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698