OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/inspector/v8-console.h" | 5 #include "src/inspector/v8-console.h" |
6 | 6 |
7 #include "src/base/macros.h" | 7 #include "src/base/macros.h" |
8 #include "src/inspector/injected-script.h" | 8 #include "src/inspector/injected-script.h" |
9 #include "src/inspector/inspected-context.h" | 9 #include "src/inspector/inspected-context.h" |
10 #include "src/inspector/string-util.h" | 10 #include "src/inspector/string-util.h" |
11 #include "src/inspector/v8-console-message.h" | 11 #include "src/inspector/v8-console-message.h" |
12 #include "src/inspector/v8-debugger-agent-impl.h" | 12 #include "src/inspector/v8-debugger-agent-impl.h" |
13 #include "src/inspector/v8-inspector-impl.h" | 13 #include "src/inspector/v8-inspector-impl.h" |
14 #include "src/inspector/v8-inspector-session-impl.h" | 14 #include "src/inspector/v8-inspector-session-impl.h" |
15 #include "src/inspector/v8-profiler-agent-impl.h" | 15 #include "src/inspector/v8-profiler-agent-impl.h" |
16 #include "src/inspector/v8-runtime-agent-impl.h" | 16 #include "src/inspector/v8-runtime-agent-impl.h" |
17 #include "src/inspector/v8-stack-trace-impl.h" | 17 #include "src/inspector/v8-stack-trace-impl.h" |
18 #include "src/inspector/v8-value-copier.h" | 18 #include "src/inspector/v8-value-copier.h" |
19 | 19 |
20 #include "include/v8-inspector.h" | 20 #include "include/v8-inspector.h" |
21 | 21 |
22 namespace v8_inspector { | 22 namespace v8_inspector { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
| 26 v8::Local<v8::Private> inspectedContextPrivateKey(v8::Isolate* isolate) { |
| 27 return v8::Private::ForApi( |
| 28 isolate, toV8StringInternalized(isolate, "V8Console#InspectedContext")); |
| 29 } |
| 30 |
26 class ConsoleHelper { | 31 class ConsoleHelper { |
27 public: | 32 public: |
28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info) | 33 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info) |
29 : m_info(info), | 34 : m_info(info), |
30 m_isolate(info.GetIsolate()), | 35 m_isolate(info.GetIsolate()), |
31 m_context(info.GetIsolate()->GetCurrentContext()), | 36 m_context(info.GetIsolate()->GetCurrentContext()), |
32 m_contextId(InspectedContext::contextId(m_context)) { | 37 m_inspectedContext(nullptr), |
33 m_inspector = static_cast<V8InspectorImpl*>( | 38 m_inspectorClient(nullptr) {} |
34 m_info.Data().As<v8::External>()->Value()); | 39 |
35 m_groupId = m_inspector->contextGroupId(m_contextId); | 40 v8::Local<v8::Object> ensureConsole() { |
| 41 if (m_console.IsEmpty()) { |
| 42 DCHECK(!m_info.Data().IsEmpty()); |
| 43 DCHECK(!m_info.Data()->IsUndefined()); |
| 44 m_console = m_info.Data().As<v8::Object>(); |
| 45 } |
| 46 return m_console; |
36 } | 47 } |
37 | 48 |
38 V8InspectorImpl* inspector() { return m_inspector; } | 49 InspectedContext* ensureInspectedContext() { |
| 50 if (m_inspectedContext) return m_inspectedContext; |
| 51 v8::Local<v8::Object> console = ensureConsole(); |
39 | 52 |
40 int contextId() const { return m_contextId; } | 53 v8::Local<v8::Private> key = inspectedContextPrivateKey(m_isolate); |
41 int groupId() const { return m_groupId; } | 54 v8::Local<v8::Value> inspectedContextValue; |
42 | 55 if (!console->GetPrivate(m_context, key).ToLocal(&inspectedContextValue)) |
43 InjectedScript* injectedScript() { | 56 return nullptr; |
44 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId); | 57 DCHECK(inspectedContextValue->IsExternal()); |
45 if (!context) return nullptr; | 58 m_inspectedContext = static_cast<InspectedContext*>( |
46 return context->getInjectedScript(); | 59 inspectedContextValue.As<v8::External>()->Value()); |
| 60 return m_inspectedContext; |
47 } | 61 } |
48 | 62 |
49 V8ConsoleMessageStorage* consoleMessageStorage() { | 63 V8InspectorClient* ensureDebuggerClient() { |
50 return inspector()->ensureConsoleMessageStorage(m_groupId); | 64 if (m_inspectorClient) return m_inspectorClient; |
| 65 InspectedContext* inspectedContext = ensureInspectedContext(); |
| 66 if (!inspectedContext) return nullptr; |
| 67 m_inspectorClient = inspectedContext->inspector()->client(); |
| 68 return m_inspectorClient; |
51 } | 69 } |
52 | 70 |
53 void reportCall(ConsoleAPIType type) { | 71 void reportCall(ConsoleAPIType type) { |
54 if (!m_info.Length()) return; | 72 if (!m_info.Length()) return; |
55 std::vector<v8::Local<v8::Value>> arguments; | 73 std::vector<v8::Local<v8::Value>> arguments; |
56 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); | 74 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); |
57 reportCall(type, arguments); | 75 reportCall(type, arguments); |
58 } | 76 } |
59 | 77 |
60 void reportCallWithDefaultArgument(ConsoleAPIType type, | 78 void reportCallWithDefaultArgument(ConsoleAPIType type, |
61 const String16& message) { | 79 const String16& message) { |
62 std::vector<v8::Local<v8::Value>> arguments; | 80 std::vector<v8::Local<v8::Value>> arguments; |
63 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); | 81 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); |
64 if (!m_info.Length()) arguments.push_back(toV8String(m_isolate, message)); | 82 if (!m_info.Length()) arguments.push_back(toV8String(m_isolate, message)); |
65 reportCall(type, arguments); | 83 reportCall(type, arguments); |
66 } | 84 } |
67 | 85 |
68 void reportCallWithArgument(ConsoleAPIType type, const String16& message) { | 86 void reportCallWithArgument(ConsoleAPIType type, const String16& message) { |
69 std::vector<v8::Local<v8::Value>> arguments(1, | 87 std::vector<v8::Local<v8::Value>> arguments(1, |
70 toV8String(m_isolate, message)); | 88 toV8String(m_isolate, message)); |
71 reportCall(type, arguments); | 89 reportCall(type, arguments); |
72 } | 90 } |
73 | 91 |
74 void reportCall(ConsoleAPIType type, | 92 void reportCall(ConsoleAPIType type, |
75 const std::vector<v8::Local<v8::Value>>& arguments) { | 93 const std::vector<v8::Local<v8::Value>>& arguments) { |
| 94 InspectedContext* inspectedContext = ensureInspectedContext(); |
| 95 if (!inspectedContext) return; |
| 96 int contextGroupId = inspectedContext->contextGroupId(); |
| 97 V8InspectorImpl* inspector = inspectedContext->inspector(); |
76 std::unique_ptr<V8ConsoleMessage> message = | 98 std::unique_ptr<V8ConsoleMessage> message = |
77 V8ConsoleMessage::createForConsoleAPI( | 99 V8ConsoleMessage::createForConsoleAPI( |
78 m_context, m_contextId, m_groupId, m_inspector, | 100 inspector->client()->currentTimeMS(), type, arguments, |
79 m_inspector->client()->currentTimeMS(), type, arguments, | 101 inspector->debugger()->captureStackTrace(false), inspectedContext); |
80 m_inspector->debugger()->captureStackTrace(false)); | 102 inspector->ensureConsoleMessageStorage(contextGroupId) |
81 consoleMessageStorage()->addMessage(std::move(message)); | 103 ->addMessage(std::move(message)); |
82 } | 104 } |
83 | 105 |
84 void reportDeprecatedCall(const char* id, const String16& message) { | 106 void reportDeprecatedCall(const char* id, const String16& message) { |
85 if (!consoleMessageStorage()->shouldReportDeprecationMessage(m_contextId, | 107 if (checkAndSetPrivateFlagOnConsole(id, false)) return; |
86 id)) { | |
87 return; | |
88 } | |
89 std::vector<v8::Local<v8::Value>> arguments(1, | 108 std::vector<v8::Local<v8::Value>> arguments(1, |
90 toV8String(m_isolate, message)); | 109 toV8String(m_isolate, message)); |
91 reportCall(ConsoleAPIType::kWarning, arguments); | 110 reportCall(ConsoleAPIType::kWarning, arguments); |
92 } | 111 } |
93 | 112 |
94 bool firstArgToBoolean(bool defaultValue) { | 113 bool firstArgToBoolean(bool defaultValue) { |
95 if (m_info.Length() < 1) return defaultValue; | 114 if (m_info.Length() < 1) return defaultValue; |
96 if (m_info[0]->IsBoolean()) return m_info[0].As<v8::Boolean>()->Value(); | 115 if (m_info[0]->IsBoolean()) return m_info[0].As<v8::Boolean>()->Value(); |
97 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue); | 116 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue); |
98 } | 117 } |
(...skipping 20 matching lines...) Expand all Loading... |
119 | 138 |
120 v8::MaybeLocal<v8::Function> firstArgAsFunction() { | 139 v8::MaybeLocal<v8::Function> firstArgAsFunction() { |
121 if (m_info.Length() < 1 || !m_info[0]->IsFunction()) | 140 if (m_info.Length() < 1 || !m_info[0]->IsFunction()) |
122 return v8::MaybeLocal<v8::Function>(); | 141 return v8::MaybeLocal<v8::Function>(); |
123 v8::Local<v8::Function> func = m_info[0].As<v8::Function>(); | 142 v8::Local<v8::Function> func = m_info[0].As<v8::Function>(); |
124 while (func->GetBoundFunction()->IsFunction()) | 143 while (func->GetBoundFunction()->IsFunction()) |
125 func = func->GetBoundFunction().As<v8::Function>(); | 144 func = func->GetBoundFunction().As<v8::Function>(); |
126 return func; | 145 return func; |
127 } | 146 } |
128 | 147 |
| 148 v8::MaybeLocal<v8::Map> privateMap(const char* name) { |
| 149 v8::Local<v8::Object> console = ensureConsole(); |
| 150 v8::Local<v8::Private> privateKey = |
| 151 v8::Private::ForApi(m_isolate, toV8StringInternalized(m_isolate, name)); |
| 152 v8::Local<v8::Value> mapValue; |
| 153 if (!console->GetPrivate(m_context, privateKey).ToLocal(&mapValue)) |
| 154 return v8::MaybeLocal<v8::Map>(); |
| 155 if (mapValue->IsUndefined()) { |
| 156 v8::Local<v8::Map> map = v8::Map::New(m_isolate); |
| 157 if (!console->SetPrivate(m_context, privateKey, map).FromMaybe(false)) |
| 158 return v8::MaybeLocal<v8::Map>(); |
| 159 return map; |
| 160 } |
| 161 return mapValue->IsMap() ? mapValue.As<v8::Map>() |
| 162 : v8::MaybeLocal<v8::Map>(); |
| 163 } |
| 164 |
| 165 int32_t getIntFromMap(v8::Local<v8::Map> map, const String16& key, |
| 166 int32_t defaultValue) { |
| 167 v8::Local<v8::String> v8Key = toV8String(m_isolate, key); |
| 168 if (!map->Has(m_context, v8Key).FromMaybe(false)) return defaultValue; |
| 169 v8::Local<v8::Value> intValue; |
| 170 if (!map->Get(m_context, v8Key).ToLocal(&intValue)) return defaultValue; |
| 171 return static_cast<int32_t>(intValue.As<v8::Integer>()->Value()); |
| 172 } |
| 173 |
| 174 void setIntOnMap(v8::Local<v8::Map> map, const String16& key, int32_t value) { |
| 175 v8::Local<v8::String> v8Key = toV8String(m_isolate, key); |
| 176 if (!map->Set(m_context, v8Key, v8::Integer::New(m_isolate, value)) |
| 177 .ToLocal(&map)) |
| 178 return; |
| 179 } |
| 180 |
| 181 double getDoubleFromMap(v8::Local<v8::Map> map, const String16& key, |
| 182 double defaultValue) { |
| 183 v8::Local<v8::String> v8Key = toV8String(m_isolate, key); |
| 184 if (!map->Has(m_context, v8Key).FromMaybe(false)) return defaultValue; |
| 185 v8::Local<v8::Value> intValue; |
| 186 if (!map->Get(m_context, v8Key).ToLocal(&intValue)) return defaultValue; |
| 187 return intValue.As<v8::Number>()->Value(); |
| 188 } |
| 189 |
| 190 void setDoubleOnMap(v8::Local<v8::Map> map, const String16& key, |
| 191 double value) { |
| 192 v8::Local<v8::String> v8Key = toV8String(m_isolate, key); |
| 193 if (!map->Set(m_context, v8Key, v8::Number::New(m_isolate, value)) |
| 194 .ToLocal(&map)) |
| 195 return; |
| 196 } |
| 197 |
129 V8ProfilerAgentImpl* profilerAgent() { | 198 V8ProfilerAgentImpl* profilerAgent() { |
130 if (V8InspectorSessionImpl* session = currentSession()) { | 199 if (V8InspectorSessionImpl* session = currentSession()) { |
131 if (session && session->profilerAgent()->enabled()) | 200 if (session && session->profilerAgent()->enabled()) |
132 return session->profilerAgent(); | 201 return session->profilerAgent(); |
133 } | 202 } |
134 return nullptr; | 203 return nullptr; |
135 } | 204 } |
136 | 205 |
137 V8DebuggerAgentImpl* debuggerAgent() { | 206 V8DebuggerAgentImpl* debuggerAgent() { |
138 if (V8InspectorSessionImpl* session = currentSession()) { | 207 if (V8InspectorSessionImpl* session = currentSession()) { |
139 if (session && session->debuggerAgent()->enabled()) | 208 if (session && session->debuggerAgent()->enabled()) |
140 return session->debuggerAgent(); | 209 return session->debuggerAgent(); |
141 } | 210 } |
142 return nullptr; | 211 return nullptr; |
143 } | 212 } |
144 | 213 |
145 V8InspectorSessionImpl* currentSession() { | 214 V8InspectorSessionImpl* currentSession() { |
146 return m_inspector->sessionForContextGroup(m_groupId); | 215 InspectedContext* inspectedContext = ensureInspectedContext(); |
| 216 if (!inspectedContext) return nullptr; |
| 217 return inspectedContext->inspector()->sessionForContextGroup( |
| 218 inspectedContext->contextGroupId()); |
147 } | 219 } |
148 | 220 |
149 private: | 221 private: |
150 const v8::FunctionCallbackInfo<v8::Value>& m_info; | 222 const v8::FunctionCallbackInfo<v8::Value>& m_info; |
151 v8::Isolate* m_isolate; | 223 v8::Isolate* m_isolate; |
152 v8::Local<v8::Context> m_context; | 224 v8::Local<v8::Context> m_context; |
153 v8::Local<v8::Object> m_console; | 225 v8::Local<v8::Object> m_console; |
154 V8InspectorImpl* m_inspector = nullptr; | 226 InspectedContext* m_inspectedContext; |
155 int m_contextId; | 227 V8InspectorClient* m_inspectorClient; |
156 int m_groupId; | 228 |
| 229 bool checkAndSetPrivateFlagOnConsole(const char* name, bool defaultValue) { |
| 230 v8::Local<v8::Object> console = ensureConsole(); |
| 231 v8::Local<v8::Private> key = |
| 232 v8::Private::ForApi(m_isolate, toV8StringInternalized(m_isolate, name)); |
| 233 v8::Local<v8::Value> flagValue; |
| 234 if (!console->GetPrivate(m_context, key).ToLocal(&flagValue)) |
| 235 return defaultValue; |
| 236 DCHECK(flagValue->IsUndefined() || flagValue->IsBoolean()); |
| 237 if (flagValue->IsBoolean()) { |
| 238 DCHECK(flagValue.As<v8::Boolean>()->Value()); |
| 239 return true; |
| 240 } |
| 241 if (!console->SetPrivate(m_context, key, v8::True(m_isolate)) |
| 242 .FromMaybe(false)) |
| 243 return defaultValue; |
| 244 return false; |
| 245 } |
157 | 246 |
158 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); | 247 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); |
159 }; | 248 }; |
160 | 249 |
161 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 250 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
162 info.GetReturnValue().Set(info.Data()); | 251 info.GetReturnValue().Set(info.Data()); |
163 } | 252 } |
164 | 253 |
165 void createBoundFunctionProperty(v8::Local<v8::Context> context, | 254 void createBoundFunctionProperty(v8::Local<v8::Context> context, |
166 v8::Local<v8::Object> console, | 255 v8::Local<v8::Object> console, |
167 v8::Local<v8::Value> data, const char* name, | 256 const char* name, |
168 v8::FunctionCallback callback, | 257 v8::FunctionCallback callback, |
169 const char* description = nullptr) { | 258 const char* description = nullptr) { |
170 v8::Local<v8::String> funcName = | 259 v8::Local<v8::String> funcName = |
171 toV8StringInternalized(context->GetIsolate(), name); | 260 toV8StringInternalized(context->GetIsolate(), name); |
172 v8::Local<v8::Function> func; | 261 v8::Local<v8::Function> func; |
173 if (!v8::Function::New(context, callback, data, 0, | 262 if (!v8::Function::New(context, callback, console, 0, |
174 v8::ConstructorBehavior::kThrow) | 263 v8::ConstructorBehavior::kThrow) |
175 .ToLocal(&func)) | 264 .ToLocal(&func)) |
176 return; | 265 return; |
177 func->SetName(funcName); | 266 func->SetName(funcName); |
178 if (description) { | 267 if (description) { |
179 v8::Local<v8::String> returnValue = | 268 v8::Local<v8::String> returnValue = |
180 toV8String(context->GetIsolate(), description); | 269 toV8String(context->GetIsolate(), description); |
181 v8::Local<v8::Function> toStringFunction; | 270 v8::Local<v8::Function> toStringFunction; |
182 if (v8::Function::New(context, returnDataCallback, returnValue, 0, | 271 if (v8::Function::New(context, returnDataCallback, returnValue, 0, |
183 v8::ConstructorBehavior::kThrow) | 272 v8::ConstructorBehavior::kThrow) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 330 } |
242 | 331 |
243 void V8Console::groupEndCallback( | 332 void V8Console::groupEndCallback( |
244 const v8::FunctionCallbackInfo<v8::Value>& info) { | 333 const v8::FunctionCallbackInfo<v8::Value>& info) { |
245 ConsoleHelper(info).reportCallWithDefaultArgument( | 334 ConsoleHelper(info).reportCallWithDefaultArgument( |
246 ConsoleAPIType::kEndGroup, String16("console.groupEnd")); | 335 ConsoleAPIType::kEndGroup, String16("console.groupEnd")); |
247 } | 336 } |
248 | 337 |
249 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 338 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
250 ConsoleHelper helper(info); | 339 ConsoleHelper helper(info); |
251 helper.inspector()->client()->consoleClear(helper.groupId()); | 340 InspectedContext* context = helper.ensureInspectedContext(); |
| 341 if (!context) return; |
| 342 int contextGroupId = context->contextGroupId(); |
| 343 if (V8InspectorClient* client = helper.ensureDebuggerClient()) |
| 344 client->consoleClear(contextGroupId); |
252 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, | 345 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, |
253 String16("console.clear")); | 346 String16("console.clear")); |
254 } | 347 } |
255 | 348 |
256 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 349 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
257 ConsoleHelper helper(info); | 350 ConsoleHelper helper(info); |
| 351 |
258 String16 title = helper.firstArgToString(String16()); | 352 String16 title = helper.firstArgToString(String16()); |
259 String16 identifier; | 353 String16 identifier; |
260 if (title.isEmpty()) { | 354 if (title.isEmpty()) { |
261 std::unique_ptr<V8StackTraceImpl> stackTrace = | 355 std::unique_ptr<V8StackTraceImpl> stackTrace = |
262 V8StackTraceImpl::capture(nullptr, 0, 1); | 356 V8StackTraceImpl::capture(nullptr, 0, 1); |
263 if (stackTrace && !stackTrace->isEmpty()) { | 357 if (stackTrace && !stackTrace->isEmpty()) { |
264 identifier = toString16(stackTrace->topSourceURL()) + ":" + | 358 identifier = toString16(stackTrace->topSourceURL()) + ":" + |
265 String16::fromInteger(stackTrace->topLineNumber()); | 359 String16::fromInteger(stackTrace->topLineNumber()); |
266 } | 360 } |
267 } else { | 361 } else { |
268 identifier = title + "@"; | 362 identifier = title + "@"; |
269 } | 363 } |
270 | 364 |
271 int count = | 365 v8::Local<v8::Map> countMap; |
272 helper.consoleMessageStorage()->count(helper.contextId(), identifier); | 366 if (!helper.privateMap("V8Console#countMap").ToLocal(&countMap)) return; |
| 367 int32_t count = helper.getIntFromMap(countMap, identifier, 0) + 1; |
| 368 helper.setIntOnMap(countMap, identifier, count); |
273 String16 countString = String16::fromInteger(count); | 369 String16 countString = String16::fromInteger(count); |
274 helper.reportCallWithArgument( | 370 helper.reportCallWithArgument( |
275 ConsoleAPIType::kCount, | 371 ConsoleAPIType::kCount, |
276 title.isEmpty() ? countString : (title + ": " + countString)); | 372 title.isEmpty() ? countString : (title + ": " + countString)); |
277 } | 373 } |
278 | 374 |
279 void V8Console::assertCallback( | 375 void V8Console::assertCallback( |
280 const v8::FunctionCallbackInfo<v8::Value>& info) { | 376 const v8::FunctionCallbackInfo<v8::Value>& info) { |
281 ConsoleHelper helper(info); | 377 ConsoleHelper helper(info); |
282 if (helper.firstArgToBoolean(false)) return; | 378 if (helper.firstArgToBoolean(false)) return; |
(...skipping 29 matching lines...) Expand all Loading... |
312 void V8Console::profileEndCallback( | 408 void V8Console::profileEndCallback( |
313 const v8::FunctionCallbackInfo<v8::Value>& info) { | 409 const v8::FunctionCallbackInfo<v8::Value>& info) { |
314 ConsoleHelper helper(info); | 410 ConsoleHelper helper(info); |
315 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) | 411 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) |
316 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); | 412 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); |
317 } | 413 } |
318 | 414 |
319 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, | 415 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, |
320 bool timelinePrefix) { | 416 bool timelinePrefix) { |
321 ConsoleHelper helper(info); | 417 ConsoleHelper helper(info); |
322 V8InspectorClient* client = helper.inspector()->client(); | 418 if (V8InspectorClient* client = helper.ensureDebuggerClient()) { |
323 String16 protocolTitle = helper.firstArgToString("default"); | 419 String16 protocolTitle = helper.firstArgToString("default"); |
324 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; | 420 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; |
325 client->consoleTime(toStringView(protocolTitle)); | 421 client->consoleTime(toStringView(protocolTitle)); |
326 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle); | 422 |
| 423 v8::Local<v8::Map> timeMap; |
| 424 if (!helper.privateMap("V8Console#timeMap").ToLocal(&timeMap)) return; |
| 425 helper.setDoubleOnMap(timeMap, protocolTitle, client->currentTimeMS()); |
| 426 } |
327 } | 427 } |
328 | 428 |
329 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, | 429 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, |
330 bool timelinePrefix) { | 430 bool timelinePrefix) { |
331 ConsoleHelper helper(info); | 431 ConsoleHelper helper(info); |
332 V8InspectorClient* client = helper.inspector()->client(); | 432 if (V8InspectorClient* client = helper.ensureDebuggerClient()) { |
333 String16 protocolTitle = helper.firstArgToString("default"); | 433 String16 protocolTitle = helper.firstArgToString("default"); |
334 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; | 434 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; |
335 client->consoleTimeEnd(toStringView(protocolTitle)); | 435 client->consoleTimeEnd(toStringView(protocolTitle)); |
336 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(), | 436 |
337 protocolTitle); | 437 v8::Local<v8::Map> timeMap; |
338 String16 message = | 438 if (!helper.privateMap("V8Console#timeMap").ToLocal(&timeMap)) return; |
339 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; | 439 double elapsed = client->currentTimeMS() - |
340 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); | 440 helper.getDoubleFromMap(timeMap, protocolTitle, 0.0); |
| 441 String16 message = |
| 442 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; |
| 443 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); |
| 444 } |
341 } | 445 } |
342 | 446 |
343 void V8Console::timelineCallback( | 447 void V8Console::timelineCallback( |
344 const v8::FunctionCallbackInfo<v8::Value>& info) { | 448 const v8::FunctionCallbackInfo<v8::Value>& info) { |
345 ConsoleHelper(info).reportDeprecatedCall( | 449 ConsoleHelper(info).reportDeprecatedCall( |
346 "V8Console#timeline", | 450 "V8Console#timeline", |
347 "'console.timeline' is deprecated. Please use 'console.time' instead."); | 451 "'console.timeline' is deprecated. Please use 'console.time' instead."); |
348 timeFunction(info, true); | 452 timeFunction(info, true); |
349 } | 453 } |
350 | 454 |
(...skipping 11 matching lines...) Expand all Loading... |
362 } | 466 } |
363 | 467 |
364 void V8Console::timeEndCallback( | 468 void V8Console::timeEndCallback( |
365 const v8::FunctionCallbackInfo<v8::Value>& info) { | 469 const v8::FunctionCallbackInfo<v8::Value>& info) { |
366 timeEndFunction(info, false); | 470 timeEndFunction(info, false); |
367 } | 471 } |
368 | 472 |
369 void V8Console::timeStampCallback( | 473 void V8Console::timeStampCallback( |
370 const v8::FunctionCallbackInfo<v8::Value>& info) { | 474 const v8::FunctionCallbackInfo<v8::Value>& info) { |
371 ConsoleHelper helper(info); | 475 ConsoleHelper helper(info); |
372 String16 title = helper.firstArgToString(String16()); | 476 if (V8InspectorClient* client = helper.ensureDebuggerClient()) { |
373 helper.inspector()->client()->consoleTimeStamp(toStringView(title)); | 477 String16 title = helper.firstArgToString(String16()); |
| 478 client->consoleTimeStamp(toStringView(title)); |
| 479 } |
374 } | 480 } |
375 | 481 |
376 void V8Console::memoryGetterCallback( | 482 void V8Console::memoryGetterCallback( |
377 const v8::FunctionCallbackInfo<v8::Value>& info) { | 483 const v8::FunctionCallbackInfo<v8::Value>& info) { |
378 V8InspectorClient* client = ConsoleHelper(info).inspector()->client(); | 484 if (V8InspectorClient* client = ConsoleHelper(info).ensureDebuggerClient()) { |
379 v8::Local<v8::Value> memoryValue; | 485 v8::Local<v8::Value> memoryValue; |
380 if (!client | 486 if (!client |
381 ->memoryInfo(info.GetIsolate(), | 487 ->memoryInfo(info.GetIsolate(), |
382 info.GetIsolate()->GetCurrentContext()) | 488 info.GetIsolate()->GetCurrentContext()) |
383 .ToLocal(&memoryValue)) | 489 .ToLocal(&memoryValue)) |
384 return; | 490 return; |
385 info.GetReturnValue().Set(memoryValue); | 491 info.GetReturnValue().Set(memoryValue); |
| 492 } |
386 } | 493 } |
387 | 494 |
388 void V8Console::memorySetterCallback( | 495 void V8Console::memorySetterCallback( |
389 const v8::FunctionCallbackInfo<v8::Value>& info) { | 496 const v8::FunctionCallbackInfo<v8::Value>& info) { |
390 // We can't make the attribute readonly as it breaks existing code that relies | 497 // We can't make the attribute readonly as it breaks existing code that relies |
391 // on being able to assign to console.memory in strict mode. Instead, the | 498 // on being able to assign to console.memory in strict mode. Instead, the |
392 // setter just ignores the passed value. http://crbug.com/468611 | 499 // setter just ignores the passed value. http://crbug.com/468611 |
393 } | 500 } |
394 | 501 |
395 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 502 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 v8::Local<v8::Function> function; | 603 v8::Local<v8::Function> function; |
497 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 604 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
498 setFunctionBreakpoint(helper, function, | 605 setFunctionBreakpoint(helper, function, |
499 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 606 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
500 String16(), false); | 607 String16(), false); |
501 } | 608 } |
502 | 609 |
503 void V8Console::lastEvaluationResultCallback( | 610 void V8Console::lastEvaluationResultCallback( |
504 const v8::FunctionCallbackInfo<v8::Value>& info) { | 611 const v8::FunctionCallbackInfo<v8::Value>& info) { |
505 ConsoleHelper helper(info); | 612 ConsoleHelper helper(info); |
506 InjectedScript* injectedScript = helper.injectedScript(); | 613 InspectedContext* context = helper.ensureInspectedContext(); |
507 if (!injectedScript) return; | 614 if (!context) return; |
508 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); | 615 if (InjectedScript* injectedScript = context->getInjectedScript()) |
| 616 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); |
509 } | 617 } |
510 | 618 |
511 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, | 619 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, |
512 bool copyToClipboard) { | 620 bool copyToClipboard) { |
513 if (info.Length() < 1) return; | 621 if (info.Length() < 1) return; |
514 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); | 622 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); |
515 | 623 |
516 ConsoleHelper helper(info); | 624 ConsoleHelper helper(info); |
517 InjectedScript* injectedScript = helper.injectedScript(); | 625 InspectedContext* context = helper.ensureInspectedContext(); |
| 626 if (!context) return; |
| 627 InjectedScript* injectedScript = context->getInjectedScript(); |
518 if (!injectedScript) return; | 628 if (!injectedScript) return; |
519 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; | 629 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; |
520 protocol::Response response = | 630 protocol::Response response = |
521 injectedScript->wrapObject(info[0], "", false /** forceValueType */, | 631 injectedScript->wrapObject(info[0], "", false /** forceValueType */, |
522 false /** generatePreview */, &wrappedObject); | 632 false /** generatePreview */, &wrappedObject); |
523 if (!response.isSuccess()) return; | 633 if (!response.isSuccess()) return; |
524 | 634 |
525 std::unique_ptr<protocol::DictionaryValue> hints = | 635 std::unique_ptr<protocol::DictionaryValue> hints = |
526 protocol::DictionaryValue::create(); | 636 protocol::DictionaryValue::create(); |
527 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); | 637 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); |
528 if (V8InspectorSessionImpl* session = helper.currentSession()) { | 638 if (V8InspectorSessionImpl* session = helper.currentSession()) |
529 session->runtimeAgent()->inspect(std::move(wrappedObject), | 639 session->runtimeAgent()->inspect(std::move(wrappedObject), |
530 std::move(hints)); | 640 std::move(hints)); |
531 } | |
532 } | 641 } |
533 | 642 |
534 void V8Console::inspectCallback( | 643 void V8Console::inspectCallback( |
535 const v8::FunctionCallbackInfo<v8::Value>& info) { | 644 const v8::FunctionCallbackInfo<v8::Value>& info) { |
536 inspectImpl(info, false); | 645 inspectImpl(info, false); |
537 } | 646 } |
538 | 647 |
539 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 648 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
540 inspectImpl(info, true); | 649 inspectImpl(info, true); |
541 } | 650 } |
(...skipping 19 matching lines...) Expand all Loading... |
561 v8::Isolate* isolate = context->GetIsolate(); | 670 v8::Isolate* isolate = context->GetIsolate(); |
562 v8::MicrotasksScope microtasksScope(isolate, | 671 v8::MicrotasksScope microtasksScope(isolate, |
563 v8::MicrotasksScope::kDoNotRunMicrotasks); | 672 v8::MicrotasksScope::kDoNotRunMicrotasks); |
564 | 673 |
565 v8::Local<v8::Object> console = v8::Object::New(isolate); | 674 v8::Local<v8::Object> console = v8::Object::New(isolate); |
566 bool success = | 675 bool success = |
567 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); | 676 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); |
568 DCHECK(success); | 677 DCHECK(success); |
569 USE(success); | 678 USE(success); |
570 | 679 |
571 v8::Local<v8::External> data = | 680 createBoundFunctionProperty(context, console, "debug", |
572 v8::External::New(isolate, inspectedContext->inspector()); | |
573 createBoundFunctionProperty(context, console, data, "debug", | |
574 V8Console::debugCallback); | 681 V8Console::debugCallback); |
575 createBoundFunctionProperty(context, console, data, "error", | 682 createBoundFunctionProperty(context, console, "error", |
576 V8Console::errorCallback); | 683 V8Console::errorCallback); |
577 createBoundFunctionProperty(context, console, data, "info", | 684 createBoundFunctionProperty(context, console, "info", |
578 V8Console::infoCallback); | 685 V8Console::infoCallback); |
579 createBoundFunctionProperty(context, console, data, "log", | 686 createBoundFunctionProperty(context, console, "log", V8Console::logCallback); |
580 V8Console::logCallback); | 687 createBoundFunctionProperty(context, console, "warn", |
581 createBoundFunctionProperty(context, console, data, "warn", | |
582 V8Console::warnCallback); | 688 V8Console::warnCallback); |
583 createBoundFunctionProperty(context, console, data, "dir", | 689 createBoundFunctionProperty(context, console, "dir", V8Console::dirCallback); |
584 V8Console::dirCallback); | 690 createBoundFunctionProperty(context, console, "dirxml", |
585 createBoundFunctionProperty(context, console, data, "dirxml", | |
586 V8Console::dirxmlCallback); | 691 V8Console::dirxmlCallback); |
587 createBoundFunctionProperty(context, console, data, "table", | 692 createBoundFunctionProperty(context, console, "table", |
588 V8Console::tableCallback); | 693 V8Console::tableCallback); |
589 createBoundFunctionProperty(context, console, data, "trace", | 694 createBoundFunctionProperty(context, console, "trace", |
590 V8Console::traceCallback); | 695 V8Console::traceCallback); |
591 createBoundFunctionProperty(context, console, data, "group", | 696 createBoundFunctionProperty(context, console, "group", |
592 V8Console::groupCallback); | 697 V8Console::groupCallback); |
593 createBoundFunctionProperty(context, console, data, "groupCollapsed", | 698 createBoundFunctionProperty(context, console, "groupCollapsed", |
594 V8Console::groupCollapsedCallback); | 699 V8Console::groupCollapsedCallback); |
595 createBoundFunctionProperty(context, console, data, "groupEnd", | 700 createBoundFunctionProperty(context, console, "groupEnd", |
596 V8Console::groupEndCallback); | 701 V8Console::groupEndCallback); |
597 createBoundFunctionProperty(context, console, data, "clear", | 702 createBoundFunctionProperty(context, console, "clear", |
598 V8Console::clearCallback); | 703 V8Console::clearCallback); |
599 createBoundFunctionProperty(context, console, data, "count", | 704 createBoundFunctionProperty(context, console, "count", |
600 V8Console::countCallback); | 705 V8Console::countCallback); |
601 createBoundFunctionProperty(context, console, data, "assert", | 706 createBoundFunctionProperty(context, console, "assert", |
602 V8Console::assertCallback); | 707 V8Console::assertCallback); |
603 createBoundFunctionProperty(context, console, data, "markTimeline", | 708 createBoundFunctionProperty(context, console, "markTimeline", |
604 V8Console::markTimelineCallback); | 709 V8Console::markTimelineCallback); |
605 createBoundFunctionProperty(context, console, data, "profile", | 710 createBoundFunctionProperty(context, console, "profile", |
606 V8Console::profileCallback); | 711 V8Console::profileCallback); |
607 createBoundFunctionProperty(context, console, data, "profileEnd", | 712 createBoundFunctionProperty(context, console, "profileEnd", |
608 V8Console::profileEndCallback); | 713 V8Console::profileEndCallback); |
609 createBoundFunctionProperty(context, console, data, "timeline", | 714 createBoundFunctionProperty(context, console, "timeline", |
610 V8Console::timelineCallback); | 715 V8Console::timelineCallback); |
611 createBoundFunctionProperty(context, console, data, "timelineEnd", | 716 createBoundFunctionProperty(context, console, "timelineEnd", |
612 V8Console::timelineEndCallback); | 717 V8Console::timelineEndCallback); |
613 createBoundFunctionProperty(context, console, data, "time", | 718 createBoundFunctionProperty(context, console, "time", |
614 V8Console::timeCallback); | 719 V8Console::timeCallback); |
615 createBoundFunctionProperty(context, console, data, "timeEnd", | 720 createBoundFunctionProperty(context, console, "timeEnd", |
616 V8Console::timeEndCallback); | 721 V8Console::timeEndCallback); |
617 createBoundFunctionProperty(context, console, data, "timeStamp", | 722 createBoundFunctionProperty(context, console, "timeStamp", |
618 V8Console::timeStampCallback); | 723 V8Console::timeStampCallback); |
619 | 724 |
620 const char* jsConsoleAssert = | 725 const char* jsConsoleAssert = |
621 "(function(){\n" | 726 "(function(){\n" |
622 " var originAssert = this.assert;\n" | 727 " var originAssert = this.assert;\n" |
623 " originAssert.apply = Function.prototype.apply;\n" | 728 " originAssert.apply = Function.prototype.apply;\n" |
624 " this.assert = assertWrapper;\n" | 729 " this.assert = assertWrapper;\n" |
625 " assertWrapper.toString = () => originAssert.toString();\n" | 730 " assertWrapper.toString = () => originAssert.toString();\n" |
626 " function assertWrapper(){\n" | 731 " function assertWrapper(){\n" |
627 " if (!!arguments[0]) return;\n" | 732 " if (!!arguments[0]) return;\n" |
628 " originAssert.apply(null, arguments);\n" | 733 " originAssert.apply(null, arguments);\n" |
629 " }\n" | 734 " }\n" |
630 "})"; | 735 "})"; |
631 | 736 |
632 v8::Local<v8::String> assertSource = toV8String(isolate, jsConsoleAssert); | 737 v8::Local<v8::String> assertSource = toV8String(isolate, jsConsoleAssert); |
633 V8InspectorImpl* inspector = inspectedContext->inspector(); | 738 V8InspectorImpl* inspector = inspectedContext->inspector(); |
634 v8::Local<v8::Value> setupFunction; | 739 v8::Local<v8::Value> setupFunction; |
635 if (inspector->compileAndRunInternalScript(context, assertSource) | 740 if (inspector->compileAndRunInternalScript(context, assertSource) |
636 .ToLocal(&setupFunction) && | 741 .ToLocal(&setupFunction) && |
637 setupFunction->IsFunction()) { | 742 setupFunction->IsFunction()) { |
638 v8::MicrotasksScope microtasksScope( | 743 v8::MicrotasksScope microtasksScope( |
639 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); | 744 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); |
640 v8::MaybeLocal<v8::Value> result; | 745 v8::MaybeLocal<v8::Value> result; |
641 result = v8::Local<v8::Function>::Cast(setupFunction) | 746 result = v8::Local<v8::Function>::Cast(setupFunction) |
642 ->Call(context, console, 0, nullptr); | 747 ->Call(context, console, 0, nullptr); |
643 } | 748 } |
644 | 749 |
645 if (hasMemoryAttribute) { | 750 if (hasMemoryAttribute) |
646 console->SetAccessorProperty( | 751 console->SetAccessorProperty( |
647 toV8StringInternalized(isolate, "memory"), | 752 toV8StringInternalized(isolate, "memory"), |
648 v8::Function::New(context, V8Console::memoryGetterCallback, data, 0, | 753 v8::Function::New(context, V8Console::memoryGetterCallback, console, 0, |
649 v8::ConstructorBehavior::kThrow) | 754 v8::ConstructorBehavior::kThrow) |
650 .ToLocalChecked(), | 755 .ToLocalChecked(), |
651 v8::Function::New(context, V8Console::memorySetterCallback, data, 0, | 756 v8::Function::New(context, V8Console::memorySetterCallback, |
| 757 v8::Local<v8::Value>(), 0, |
652 v8::ConstructorBehavior::kThrow) | 758 v8::ConstructorBehavior::kThrow) |
653 .ToLocalChecked(), | 759 .ToLocalChecked(), |
654 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); | 760 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); |
655 } | |
656 | 761 |
| 762 console->SetPrivate(context, inspectedContextPrivateKey(isolate), |
| 763 v8::External::New(isolate, inspectedContext)); |
657 return console; | 764 return console; |
658 } | 765 } |
659 | 766 |
| 767 void V8Console::clearInspectedContextIfNeeded(v8::Local<v8::Context> context, |
| 768 v8::Local<v8::Object> console) { |
| 769 v8::Isolate* isolate = context->GetIsolate(); |
| 770 console->SetPrivate(context, inspectedContextPrivateKey(isolate), |
| 771 v8::External::New(isolate, nullptr)); |
| 772 } |
| 773 |
660 v8::Local<v8::Object> V8Console::createCommandLineAPI( | 774 v8::Local<v8::Object> V8Console::createCommandLineAPI( |
661 InspectedContext* inspectedContext) { | 775 InspectedContext* inspectedContext) { |
662 v8::Local<v8::Context> context = inspectedContext->context(); | 776 v8::Local<v8::Context> context = inspectedContext->context(); |
663 v8::Isolate* isolate = context->GetIsolate(); | 777 v8::Isolate* isolate = context->GetIsolate(); |
664 v8::MicrotasksScope microtasksScope(isolate, | 778 v8::MicrotasksScope microtasksScope(isolate, |
665 v8::MicrotasksScope::kDoNotRunMicrotasks); | 779 v8::MicrotasksScope::kDoNotRunMicrotasks); |
666 | 780 |
667 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); | 781 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); |
668 bool success = | 782 bool success = |
669 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); | 783 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); |
670 DCHECK(success); | 784 DCHECK(success); |
671 USE(success); | 785 USE(success); |
672 | 786 |
673 v8::Local<v8::External> data = | 787 createBoundFunctionProperty(context, commandLineAPI, "dir", |
674 v8::External::New(isolate, inspectedContext->inspector()); | |
675 createBoundFunctionProperty(context, commandLineAPI, data, "dir", | |
676 V8Console::dirCallback, | 788 V8Console::dirCallback, |
677 "function dir(value) { [Command Line API] }"); | 789 "function dir(value) { [Command Line API] }"); |
678 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", | 790 createBoundFunctionProperty(context, commandLineAPI, "dirxml", |
679 V8Console::dirxmlCallback, | 791 V8Console::dirxmlCallback, |
680 "function dirxml(value) { [Command Line API] }"); | 792 "function dirxml(value) { [Command Line API] }"); |
681 createBoundFunctionProperty(context, commandLineAPI, data, "profile", | 793 createBoundFunctionProperty(context, commandLineAPI, "profile", |
682 V8Console::profileCallback, | 794 V8Console::profileCallback, |
683 "function profile(title) { [Command Line API] }"); | 795 "function profile(title) { [Command Line API] }"); |
684 createBoundFunctionProperty( | 796 createBoundFunctionProperty( |
685 context, commandLineAPI, data, "profileEnd", | 797 context, commandLineAPI, "profileEnd", V8Console::profileEndCallback, |
686 V8Console::profileEndCallback, | |
687 "function profileEnd(title) { [Command Line API] }"); | 798 "function profileEnd(title) { [Command Line API] }"); |
688 createBoundFunctionProperty(context, commandLineAPI, data, "clear", | 799 createBoundFunctionProperty(context, commandLineAPI, "clear", |
689 V8Console::clearCallback, | 800 V8Console::clearCallback, |
690 "function clear() { [Command Line API] }"); | 801 "function clear() { [Command Line API] }"); |
691 createBoundFunctionProperty( | 802 createBoundFunctionProperty( |
692 context, commandLineAPI, data, "table", V8Console::tableCallback, | 803 context, commandLineAPI, "table", V8Console::tableCallback, |
693 "function table(data, [columns]) { [Command Line API] }"); | 804 "function table(data, [columns]) { [Command Line API] }"); |
694 | 805 |
695 createBoundFunctionProperty(context, commandLineAPI, data, "keys", | 806 createBoundFunctionProperty(context, commandLineAPI, "keys", |
696 V8Console::keysCallback, | 807 V8Console::keysCallback, |
697 "function keys(object) { [Command Line API] }"); | 808 "function keys(object) { [Command Line API] }"); |
698 createBoundFunctionProperty(context, commandLineAPI, data, "values", | 809 createBoundFunctionProperty(context, commandLineAPI, "values", |
699 V8Console::valuesCallback, | 810 V8Console::valuesCallback, |
700 "function values(object) { [Command Line API] }"); | 811 "function values(object) { [Command Line API] }"); |
701 createBoundFunctionProperty( | 812 createBoundFunctionProperty( |
702 context, commandLineAPI, data, "debug", V8Console::debugFunctionCallback, | 813 context, commandLineAPI, "debug", V8Console::debugFunctionCallback, |
703 "function debug(function) { [Command Line API] }"); | 814 "function debug(function) { [Command Line API] }"); |
704 createBoundFunctionProperty( | 815 createBoundFunctionProperty( |
705 context, commandLineAPI, data, "undebug", | 816 context, commandLineAPI, "undebug", V8Console::undebugFunctionCallback, |
706 V8Console::undebugFunctionCallback, | |
707 "function undebug(function) { [Command Line API] }"); | 817 "function undebug(function) { [Command Line API] }"); |
708 createBoundFunctionProperty( | 818 createBoundFunctionProperty( |
709 context, commandLineAPI, data, "monitor", | 819 context, commandLineAPI, "monitor", V8Console::monitorFunctionCallback, |
710 V8Console::monitorFunctionCallback, | |
711 "function monitor(function) { [Command Line API] }"); | 820 "function monitor(function) { [Command Line API] }"); |
712 createBoundFunctionProperty( | 821 createBoundFunctionProperty( |
713 context, commandLineAPI, data, "unmonitor", | 822 context, commandLineAPI, "unmonitor", |
714 V8Console::unmonitorFunctionCallback, | 823 V8Console::unmonitorFunctionCallback, |
715 "function unmonitor(function) { [Command Line API] }"); | 824 "function unmonitor(function) { [Command Line API] }"); |
716 createBoundFunctionProperty( | 825 createBoundFunctionProperty( |
717 context, commandLineAPI, data, "inspect", V8Console::inspectCallback, | 826 context, commandLineAPI, "inspect", V8Console::inspectCallback, |
718 "function inspect(object) { [Command Line API] }"); | 827 "function inspect(object) { [Command Line API] }"); |
719 createBoundFunctionProperty(context, commandLineAPI, data, "copy", | 828 createBoundFunctionProperty(context, commandLineAPI, "copy", |
720 V8Console::copyCallback, | 829 V8Console::copyCallback, |
721 "function copy(value) { [Command Line API] }"); | 830 "function copy(value) { [Command Line API] }"); |
722 createBoundFunctionProperty(context, commandLineAPI, data, "$_", | 831 createBoundFunctionProperty(context, commandLineAPI, "$_", |
723 V8Console::lastEvaluationResultCallback); | 832 V8Console::lastEvaluationResultCallback); |
724 createBoundFunctionProperty(context, commandLineAPI, data, "$0", | 833 createBoundFunctionProperty(context, commandLineAPI, "$0", |
725 V8Console::inspectedObject0); | 834 V8Console::inspectedObject0); |
726 createBoundFunctionProperty(context, commandLineAPI, data, "$1", | 835 createBoundFunctionProperty(context, commandLineAPI, "$1", |
727 V8Console::inspectedObject1); | 836 V8Console::inspectedObject1); |
728 createBoundFunctionProperty(context, commandLineAPI, data, "$2", | 837 createBoundFunctionProperty(context, commandLineAPI, "$2", |
729 V8Console::inspectedObject2); | 838 V8Console::inspectedObject2); |
730 createBoundFunctionProperty(context, commandLineAPI, data, "$3", | 839 createBoundFunctionProperty(context, commandLineAPI, "$3", |
731 V8Console::inspectedObject3); | 840 V8Console::inspectedObject3); |
732 createBoundFunctionProperty(context, commandLineAPI, data, "$4", | 841 createBoundFunctionProperty(context, commandLineAPI, "$4", |
733 V8Console::inspectedObject4); | 842 V8Console::inspectedObject4); |
734 | 843 |
735 inspectedContext->inspector()->client()->installAdditionalCommandLineAPI( | 844 inspectedContext->inspector()->client()->installAdditionalCommandLineAPI( |
736 context, commandLineAPI); | 845 context, commandLineAPI); |
| 846 |
| 847 commandLineAPI->SetPrivate(context, inspectedContextPrivateKey(isolate), |
| 848 v8::External::New(isolate, inspectedContext)); |
737 return commandLineAPI; | 849 return commandLineAPI; |
738 } | 850 } |
739 | 851 |
740 static bool isCommandLineAPIGetter(const String16& name) { | 852 static bool isCommandLineAPIGetter(const String16& name) { |
741 if (name.length() != 2) return false; | 853 if (name.length() != 2) return false; |
742 // $0 ... $4, $_ | 854 // $0 ... $4, $_ |
743 return name[0] == '$' && | 855 return name[0] == '$' && |
744 ((name[1] >= '0' && name[1] <= '4') || name[1] == '_'); | 856 ((name[1] >= '0' && name[1] <= '4') || name[1] == '_'); |
745 } | 857 } |
746 | 858 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 ->GetOwnPropertyDescriptor( | 945 ->GetOwnPropertyDescriptor( |
834 m_context, v8::Local<v8::String>::Cast(name)) | 946 m_context, v8::Local<v8::String>::Cast(name)) |
835 .ToLocal(&descriptor); | 947 .ToLocal(&descriptor); |
836 DCHECK(success); | 948 DCHECK(success); |
837 USE(success); | 949 USE(success); |
838 } | 950 } |
839 } | 951 } |
840 } | 952 } |
841 | 953 |
842 } // namespace v8_inspector | 954 } // namespace v8_inspector |
OLD | NEW |