| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 "platform/v8_inspector/V8InjectedScriptHost.h" | 5 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/String16.h" | 7 #include "platform/inspector_protocol/String16.h" |
| 8 #include "platform/inspector_protocol/Values.h" | 8 #include "platform/inspector_protocol/Values.h" |
| 9 #include "platform/v8_inspector/InjectedScript.h" | 9 #include "platform/v8_inspector/InjectedScript.h" |
| 10 #include "platform/v8_inspector/InjectedScriptHost.h" | 10 #include "platform/v8_inspector/InjectedScriptHost.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 | 37 |
| 38 template<typename CallbackInfo> | 38 template<typename CallbackInfo> |
| 39 inline void v8SetReturnValue(const CallbackInfo& info, bool value) | 39 inline void v8SetReturnValue(const CallbackInfo& info, bool value) |
| 40 { | 40 { |
| 41 info.GetReturnValue().Set(value); | 41 info.GetReturnValue().Set(value); |
| 42 } | 42 } |
| 43 | 43 |
| 44 } | 44 } |
| 45 | 45 |
| 46 void V8InjectedScriptHost::clearConsoleMessagesCallback(const v8::FunctionCallba
ckInfo<v8::Value>& info) | |
| 47 { | |
| 48 InjectedScriptHost* impl = V8InjectedScriptHost::unwrap(info.GetIsolate()->G
etCurrentContext(), info.Holder()); | |
| 49 impl->clearConsoleMessages(); | |
| 50 } | |
| 51 | |
| 52 void V8InjectedScriptHost::inspectedObjectCallback(const v8::FunctionCallbackInf
o<v8::Value>& info) | 46 void V8InjectedScriptHost::inspectedObjectCallback(const v8::FunctionCallbackInf
o<v8::Value>& info) |
| 53 { | 47 { |
| 54 if (info.Length() < 1) | 48 if (info.Length() < 1) |
| 55 return; | 49 return; |
| 56 | 50 |
| 57 v8::Isolate* isolate = info.GetIsolate(); | 51 v8::Isolate* isolate = info.GetIsolate(); |
| 58 if (!info[0]->IsInt32() && !isolate->IsExecutionTerminating()) { | 52 if (!info[0]->IsInt32() && !isolate->IsExecutionTerminating()) { |
| 59 isolate->ThrowException(v8::Exception::TypeError(toV8String(isolate, "ar
gument has to be an integer"))); | 53 isolate->ThrowException(v8::Exception::TypeError(toV8String(isolate, "ar
gument has to be an integer"))); |
| 60 return; | 54 return; |
| 61 } | 55 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) | 209 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
| 216 { | 210 { |
| 217 if (info.Length() < 2) | 211 if (info.Length() < 2) |
| 218 return; | 212 return; |
| 219 | 213 |
| 220 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); | 214 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
| 221 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder
()); | 215 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder
()); |
| 222 host->inspectImpl(toProtocolValue(context, info[0]), toProtocolValue(context
, info[1])); | 216 host->inspectImpl(toProtocolValue(context, info[0]), toProtocolValue(context
, info[1])); |
| 223 } | 217 } |
| 224 | 218 |
| 225 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info,
String16* scriptId, int* lineNumber, int* columnNumber) | |
| 226 { | |
| 227 if (info.Length() < 1 || !info[0]->IsFunction()) | |
| 228 return false; | |
| 229 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); | |
| 230 *lineNumber = function->GetScriptLineNumber(); | |
| 231 *columnNumber = function->GetScriptColumnNumber(); | |
| 232 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8:
:Function::kLineOffsetNotFound) | |
| 233 return false; | |
| 234 *scriptId = String16::number(function->ScriptId()); | |
| 235 return true; | |
| 236 } | |
| 237 | |
| 238 void V8InjectedScriptHost::debugFunctionCallback(const v8::FunctionCallbackInfo<
v8::Value>& info) | |
| 239 { | |
| 240 String16 scriptId; | |
| 241 int lineNumber; | |
| 242 int columnNumber; | |
| 243 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | |
| 244 return; | |
| 245 | |
| 246 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G
etCurrentContext(), info.Holder()); | |
| 247 host->debugFunction(scriptId, lineNumber, columnNumber); | |
| 248 } | |
| 249 | |
| 250 void V8InjectedScriptHost::undebugFunctionCallback(const v8::FunctionCallbackInf
o<v8::Value>& info) | |
| 251 { | |
| 252 String16 scriptId; | |
| 253 int lineNumber; | |
| 254 int columnNumber; | |
| 255 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | |
| 256 return; | |
| 257 | |
| 258 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G
etCurrentContext(), info.Holder()); | |
| 259 host->undebugFunction(scriptId, lineNumber, columnNumber); | |
| 260 } | |
| 261 | |
| 262 void V8InjectedScriptHost::monitorFunctionCallback(const v8::FunctionCallbackInf
o<v8::Value>& info) | |
| 263 { | |
| 264 String16 scriptId; | |
| 265 int lineNumber; | |
| 266 int columnNumber; | |
| 267 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | |
| 268 return; | |
| 269 | |
| 270 v8::Local<v8::Value> name; | |
| 271 if (info.Length() > 0 && info[0]->IsFunction()) { | |
| 272 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]
); | |
| 273 name = function->GetName(); | |
| 274 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) | |
| 275 name = function->GetInferredName(); | |
| 276 } | |
| 277 | |
| 278 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G
etCurrentContext(), info.Holder()); | |
| 279 host->monitorFunction(scriptId, lineNumber, columnNumber, toProtocolStringWi
thTypeCheck(name)); | |
| 280 } | |
| 281 | |
| 282 void V8InjectedScriptHost::unmonitorFunctionCallback(const v8::FunctionCallbackI
nfo<v8::Value>& info) | |
| 283 { | |
| 284 String16 scriptId; | |
| 285 int lineNumber; | |
| 286 int columnNumber; | |
| 287 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | |
| 288 return; | |
| 289 | |
| 290 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G
etCurrentContext(), info.Holder()); | |
| 291 host->unmonitorFunction(scriptId, lineNumber, columnNumber); | |
| 292 } | |
| 293 | |
| 294 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v
8::Value>& info) | 219 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v
8::Value>& info) |
| 295 { | 220 { |
| 296 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { | 221 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { |
| 297 ASSERT_NOT_REACHED(); | 222 ASSERT_NOT_REACHED(); |
| 298 return; | 223 return; |
| 299 } | 224 } |
| 300 | 225 |
| 301 v8::MicrotasksScope microtasks(info.GetIsolate(), v8::MicrotasksScope::kDoNo
tRunMicrotasks); | 226 v8::MicrotasksScope microtasks(info.GetIsolate(), v8::MicrotasksScope::kDoNo
tRunMicrotasks); |
| 302 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); | 227 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); |
| 303 v8::Local<v8::Value> receiver = info[1]; | 228 v8::Local<v8::Value> receiver = info[1]; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); | 277 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); |
| 353 if (!injectedScriptNative) | 278 if (!injectedScriptNative) |
| 354 return; | 279 return; |
| 355 | 280 |
| 356 v8::Local<v8::String> v8groupName = info[1]->ToString(info.GetIsolate()); | 281 v8::Local<v8::String> v8groupName = info[1]->ToString(info.GetIsolate()); |
| 357 String16 groupName = toProtocolStringWithTypeCheck(v8groupName); | 282 String16 groupName = toProtocolStringWithTypeCheck(v8groupName); |
| 358 int id = injectedScriptNative->bind(info[0], groupName); | 283 int id = injectedScriptNative->bind(info[0], groupName); |
| 359 info.GetReturnValue().Set(id); | 284 info.GetReturnValue().Set(id); |
| 360 } | 285 } |
| 361 | 286 |
| 362 v8::Local<v8::Symbol> V8Debugger::scopeExtensionSymbol(v8::Isolate* isolate) | 287 v8::Local<v8::Private> V8Debugger::scopeExtensionPrivate(v8::Isolate* isolate) |
| 363 { | 288 { |
| 364 return v8::Symbol::ForApi(isolate, toV8StringInternalized(isolate, "scopeExt
ension")); | 289 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Debug
ger#scopeExtension")); |
| 365 } | |
| 366 | |
| 367 bool V8Debugger::isCommandLineAPIMethod(const String16& name) | |
| 368 { | |
| 369 DEFINE_STATIC_LOCAL(protocol::HashSet<String16>, methods, ()); | |
| 370 if (methods.size() == 0) { | |
| 371 const char* members[] = { "$", "$$", "$x", "dir", "dirxml", "keys", "val
ues", "profile", "profileEnd", | |
| 372 "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "get
EventListeners", | |
| 373 "debug", "undebug", "monitor", "unmonitor", "table", "$_" }; | |
| 374 for (size_t i = 0; i < sizeof(members) / sizeof(const char*); ++i) | |
| 375 methods.add(members[i]); | |
| 376 } | |
| 377 return methods.find(name) != methods.end(); | |
| 378 } | |
| 379 | |
| 380 bool V8Debugger::isCommandLineAPIGetter(const String16& name) | |
| 381 { | |
| 382 DEFINE_STATIC_LOCAL(protocol::HashSet<String16>, getters, ()); | |
| 383 if (getters.size() == 0) { | |
| 384 const char* members[] = { "$0", "$1", "$2", "$3", "$4" }; | |
| 385 for (size_t i = 0; i < sizeof(members) / sizeof(const char*); ++i) | |
| 386 getters.add(members[i]); | |
| 387 } | |
| 388 return getters.find(name) != getters.end(); | |
| 389 } | 290 } |
| 390 | 291 |
| 391 bool V8Debugger::isRemoteObjectAPIMethod(const String16& name) | 292 bool V8Debugger::isRemoteObjectAPIMethod(const String16& name) |
| 392 { | 293 { |
| 393 return name == "bindRemoteObject"; | 294 return name == "bindRemoteObject"; |
| 394 } | 295 } |
| 395 | 296 |
| 396 namespace { | 297 namespace { |
| 397 | 298 |
| 398 char hiddenPropertyName[] = "v8inspector::InjectedScriptHost"; | 299 char hiddenPropertyName[] = "v8inspector::InjectedScriptHost"; |
| 399 char className[] = "V8InjectedScriptHost"; | 300 char className[] = "V8InjectedScriptHost"; |
| 400 using InjectedScriptHostWrapper = InspectorWrapper<InjectedScriptHost, hiddenPro
pertyName, className>; | 301 using InjectedScriptHostWrapper = InspectorWrapper<InjectedScriptHost, hiddenPro
pertyName, className>; |
| 401 | 302 |
| 402 const InjectedScriptHostWrapper::V8MethodConfiguration V8InjectedScriptHostMetho
ds[] = { | 303 const InjectedScriptHostWrapper::V8MethodConfiguration V8InjectedScriptHostMetho
ds[] = { |
| 403 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback}
, | |
| 404 {"inspect", V8InjectedScriptHost::inspectCallback}, | 304 {"inspect", V8InjectedScriptHost::inspectCallback}, |
| 405 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, | 305 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, |
| 406 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal
lback}, | 306 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal
lback}, |
| 407 {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsPrope
rties}, | 307 {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsPrope
rties}, |
| 408 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, | 308 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, |
| 409 {"subtype", V8InjectedScriptHost::subtypeCallback}, | 309 {"subtype", V8InjectedScriptHost::subtypeCallback}, |
| 410 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, | 310 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, |
| 411 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac
k}, | 311 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac
k}, |
| 412 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, | 312 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, |
| 413 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, | |
| 414 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, | |
| 415 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, | |
| 416 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, | |
| 417 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, | 313 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, |
| 418 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn
dCallFunctionCallback}, | 314 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn
dCallFunctionCallback}, |
| 419 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, | 315 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, |
| 420 {"bind", V8InjectedScriptHost::bindCallback} | 316 {"bind", V8InjectedScriptHost::bindCallback} |
| 421 }; | 317 }; |
| 422 | 318 |
| 423 } // namespace | 319 } // namespace |
| 424 | 320 |
| 425 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8::
Isolate* isolate) | 321 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8::
Isolate* isolate) |
| 426 { | 322 { |
| 427 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR
RAY_LENGTH(V8InjectedScriptHostMethods)); | 323 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR
RAY_LENGTH(V8InjectedScriptHostMethods)); |
| 428 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR
AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); | 324 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR
AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); |
| 429 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; | 325 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; |
| 430 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at
tributes); | 326 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at
tributes); |
| 431 } | 327 } |
| 432 | 328 |
| 433 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate>
constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host) | 329 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate>
constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host) |
| 434 { | 330 { |
| 435 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); | 331 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); |
| 436 } | 332 } |
| 437 | 333 |
| 438 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context,
v8::Local<v8::Object> object) | 334 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context,
v8::Local<v8::Object> object) |
| 439 { | 335 { |
| 440 return InjectedScriptHostWrapper::unwrap(context, object); | 336 return InjectedScriptHostWrapper::unwrap(context, object); |
| 441 } | 337 } |
| 442 | 338 |
| 443 } // namespace blink | 339 } // namespace blink |
| OLD | NEW |