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