| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) | 213 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
| 214 { | 214 { |
| 215 if (info.Length() < 2) | 215 if (info.Length() < 2) |
| 216 return; | 216 return; |
| 217 | 217 |
| 218 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); | 218 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
| 219 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder
()); | 219 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder
()); |
| 220 host->inspectImpl(toProtocolValue(context, info[0]), toProtocolValue(context
, info[1])); | 220 host->inspectImpl(toProtocolValue(context, info[0]), toProtocolValue(context
, info[1])); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void V8InjectedScriptHost::evalCallback(const v8::FunctionCallbackInfo<v8::Value
>& info) | |
| 224 { | |
| 225 v8::Isolate* isolate = info.GetIsolate(); | |
| 226 if (info.Length() < 1) { | |
| 227 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "One argument expected."))); | |
| 228 return; | |
| 229 } | |
| 230 | |
| 231 v8::Local<v8::String> expression = info[0]->ToString(isolate); | |
| 232 if (expression.IsEmpty()) { | |
| 233 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); | |
| 234 return; | |
| 235 } | |
| 236 | |
| 237 ASSERT(isolate->InContext()); | |
| 238 v8::TryCatch tryCatch(isolate); | |
| 239 v8::Local<v8::Value> result; | |
| 240 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(isolate->GetCurrentC
ontext(), info.Holder()); | |
| 241 if (!host->debugger()) | |
| 242 return; | |
| 243 if (!host->debugger()->compileAndRunInternalScript(isolate->GetCurrentContex
t(), expression).ToLocal(&result)) { | |
| 244 v8SetReturnValue(info, tryCatch.ReThrow()); | |
| 245 return; | |
| 246 } | |
| 247 v8SetReturnValue(info, result); | |
| 248 } | |
| 249 | |
| 250 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info,
String16* scriptId, int* lineNumber, int* columnNumber) | 223 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info,
String16* scriptId, int* lineNumber, int* columnNumber) |
| 251 { | 224 { |
| 252 if (info.Length() < 1 || !info[0]->IsFunction()) | 225 if (info.Length() < 1 || !info[0]->IsFunction()) |
| 253 return false; | 226 return false; |
| 254 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]); |
| 255 *lineNumber = function->GetScriptLineNumber(); | 228 *lineNumber = function->GetScriptLineNumber(); |
| 256 *columnNumber = function->GetScriptColumnNumber(); | 229 *columnNumber = function->GetScriptColumnNumber(); |
| 257 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8:
:Function::kLineOffsetNotFound) | 230 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8:
:Function::kLineOffsetNotFound) |
| 258 return false; | 231 return false; |
| 259 *scriptId = String16::number(function->ScriptId()); | 232 *scriptId = String16::number(function->ScriptId()); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); | 350 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); |
| 378 if (!injectedScriptNative) | 351 if (!injectedScriptNative) |
| 379 return; | 352 return; |
| 380 | 353 |
| 381 v8::Local<v8::String> v8groupName = info[1]->ToString(info.GetIsolate()); | 354 v8::Local<v8::String> v8groupName = info[1]->ToString(info.GetIsolate()); |
| 382 String16 groupName = toProtocolStringWithTypeCheck(v8groupName); | 355 String16 groupName = toProtocolStringWithTypeCheck(v8groupName); |
| 383 int id = injectedScriptNative->bind(info[0], groupName); | 356 int id = injectedScriptNative->bind(info[0], groupName); |
| 384 info.GetReturnValue().Set(id); | 357 info.GetReturnValue().Set(id); |
| 385 } | 358 } |
| 386 | 359 |
| 387 void V8InjectedScriptHost::objectForIdCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) | |
| 388 { | |
| 389 if (info.Length() < 1 || !info[0]->IsInt32()) | |
| 390 return; | |
| 391 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); | |
| 392 if (!injectedScriptNative) | |
| 393 return; | |
| 394 int id = info[0].As<v8::Int32>()->Value(); | |
| 395 v8::Local<v8::Value> value = injectedScriptNative->objectForId(id); | |
| 396 if (!value.IsEmpty()) | |
| 397 info.GetReturnValue().Set(value); | |
| 398 } | |
| 399 | |
| 400 void V8InjectedScriptHost::idToObjectGroupNameCallback(const v8::FunctionCallbac
kInfo<v8::Value>& info) | 360 void V8InjectedScriptHost::idToObjectGroupNameCallback(const v8::FunctionCallbac
kInfo<v8::Value>& info) |
| 401 { | 361 { |
| 402 if (info.Length() < 1 || !info[0]->IsInt32()) | 362 if (info.Length() < 1 || !info[0]->IsInt32()) |
| 403 return; | 363 return; |
| 404 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); | 364 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); |
| 405 if (!injectedScriptNative) | 365 if (!injectedScriptNative) |
| 406 return; | 366 return; |
| 407 int id = info[0].As<v8::Int32>()->Value(); | 367 int id = info[0].As<v8::Int32>()->Value(); |
| 408 String16 groupName = injectedScriptNative->groupName(id); | 368 String16 groupName = injectedScriptNative->groupName(id); |
| 409 if (!groupName.isEmpty()) | 369 if (!groupName.isEmpty()) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback}
, | 409 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback}
, |
| 450 {"inspect", V8InjectedScriptHost::inspectCallback}, | 410 {"inspect", V8InjectedScriptHost::inspectCallback}, |
| 451 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, | 411 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, |
| 452 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal
lback}, | 412 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal
lback}, |
| 453 {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsPrope
rties}, | 413 {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsPrope
rties}, |
| 454 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, | 414 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, |
| 455 {"subtype", V8InjectedScriptHost::subtypeCallback}, | 415 {"subtype", V8InjectedScriptHost::subtypeCallback}, |
| 456 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, | 416 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, |
| 457 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac
k}, | 417 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac
k}, |
| 458 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, | 418 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, |
| 459 {"eval", V8InjectedScriptHost::evalCallback}, | |
| 460 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, | 419 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, |
| 461 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, | 420 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, |
| 462 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, | 421 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, |
| 463 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, | 422 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, |
| 464 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, | 423 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, |
| 465 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn
dCallFunctionCallback}, | 424 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn
dCallFunctionCallback}, |
| 466 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, | 425 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, |
| 467 {"bind", V8InjectedScriptHost::bindCallback}, | 426 {"bind", V8InjectedScriptHost::bindCallback}, |
| 468 {"objectForId", V8InjectedScriptHost::objectForIdCallback}, | |
| 469 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback}, | 427 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback}, |
| 470 }; | 428 }; |
| 471 | 429 |
| 472 } // namespace | 430 } // namespace |
| 473 | 431 |
| 474 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8::
Isolate* isolate) | 432 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8::
Isolate* isolate) |
| 475 { | 433 { |
| 476 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR
RAY_LENGTH(V8InjectedScriptHostMethods)); | 434 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR
RAY_LENGTH(V8InjectedScriptHostMethods)); |
| 477 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR
AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); | 435 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR
AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); |
| 478 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; | 436 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; |
| 479 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at
tributes); | 437 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at
tributes); |
| 480 } | 438 } |
| 481 | 439 |
| 482 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate>
constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host) | 440 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate>
constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host) |
| 483 { | 441 { |
| 484 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); | 442 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); |
| 485 } | 443 } |
| 486 | 444 |
| 487 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context,
v8::Local<v8::Object> object) | 445 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context,
v8::Local<v8::Object> object) |
| 488 { | 446 { |
| 489 return InjectedScriptHostWrapper::unwrap(context, object); | 447 return InjectedScriptHostWrapper::unwrap(context, object); |
| 490 } | 448 } |
| 491 | 449 |
| 492 } // namespace blink | 450 } // namespace blink |
| OLD | NEW |