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

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: Revert blank line 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 : isolate(isolate)
42 , promise(isolate, promise)
43 , parentPromise(isolate, parentPromise)
44 , result(isolate, result)
45 , state(state)
46 , timeOnCreate(timestamp)
47 , timeOnSettle(-1)
48 , callStackOnCreate(createScriptCallStack(ScriptCallStack::maxCallStackSizeT oCapture, true))
49 , callStackOnSettle(RefPtr<ScriptCallStack>())
50 {
51 }
52
53 void PromiseOfficer::PromiseData::didSettlePromise(double timestamp)
54 {
55 timeOnSettle = timestamp;
56 callStackOnSettle = createScriptCallStack(ScriptCallStack::maxCallStackSizeT oCapture, 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 double timestamp = currentTimeMS();
aandrey 2014/03/04 09:26:28 nit: add ASSERT(isEnabled());
Alexandra Mikhaylova 2014/03/05 13:10:39 Done.
78
79 int promiseHash = promise->GetIdentityHash();
80 PromiseDataVector* vector;
81 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash);
82 if (it != m_promiseDataMap.end())
83 vector = &it->value;
84 else
85 vector = &m_promiseDataMap.add(promiseHash, PromiseDataVector()).storedV alue->value;
86 v8::Isolate* isolate = toIsolate(context);
87 vector->append(adoptRef(new PromiseData(promise, v8::Handle<v8::Object>(), v 8::Undefined(isolate), V8PromiseCustom::Pending, timestamp, isolate)));
88 }
89
90 void PromiseOfficer::didUpdatePromiseParent(v8::Handle<v8::Object> promise, v8:: Handle<v8::Object> parentPromise)
91 {
92 int promiseHash = promise->GetIdentityHash();
aandrey 2014/03/04 09:26:28 nit: add ASSERT(isEnabled());
Alexandra Mikhaylova 2014/03/05 13:10:39 Done.
93 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash);
94 PromiseDataVector& vector = it->value;
95 for (size_t index = 0; index < vector.size(); ++index) {
96 RefPtr<PromiseData> data = vector[index];
97 if (data->promise == promise) {
98 data->parentPromise.set(data->isolate, parentPromise);
99 break;
100 }
101 }
102 }
103
104 void PromiseOfficer::didUpdatePromiseState(v8::Handle<v8::Object> promise, V8Pro miseCustom::PromiseState state, v8::Handle<v8::Value> result)
105 {
106 double timestamp = currentTimeMS();
aandrey 2014/03/04 09:26:28 nit: add ASSERT(isEnabled());
Alexandra Mikhaylova 2014/03/05 13:10:39 Done.
107
108 int promiseHash = promise->GetIdentityHash();
109 PromiseDataMap::iterator it = m_promiseDataMap.find(promiseHash);
110 PromiseDataVector& vector = it->value;
111 for (size_t index = 0; index < vector.size(); ++index) {
112 RefPtr<PromiseData> data = vector[index];
113 if (data->promise == promise) {
114 data->state = state;
115 data->result.set(data->isolate, result);
116 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom: :Rejected)
117 data->didSettlePromise(timestamp);
118 break;
119 }
120 }
121 }
122
123 } // namespace WebCore
OLDNEW
« Source/core/inspector/PromiseOfficer.h ('K') | « Source/core/inspector/PromiseOfficer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698