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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); | 273 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); |
274 return; | 274 return; |
275 } | 275 } |
276 | 276 |
277 ASSERT(isolate->InContext()); | 277 ASSERT(isolate->InContext()); |
278 v8::TryCatch tryCatch(isolate); | 278 v8::TryCatch tryCatch(isolate); |
279 v8::Local<v8::Value> result; | 279 v8::Local<v8::Value> result; |
280 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(isolate->GetCurrentC
ontext(), info.Holder()); | 280 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(isolate->GetCurrentC
ontext(), info.Holder()); |
281 if (!host->debugger()) | 281 if (!host->debugger()) |
282 return; | 282 return; |
283 if (!host->debugger()->client()->compileAndRunInternalScript(expression).ToL
ocal(&result)) { | 283 if (!host->debugger()->compileAndRunInternalScript(isolate->GetCurrentContex
t(), expression).ToLocal(&result)) { |
284 v8SetReturnValue(info, tryCatch.ReThrow()); | 284 v8SetReturnValue(info, tryCatch.ReThrow()); |
285 return; | 285 return; |
286 } | 286 } |
287 v8SetReturnValue(info, result); | 287 v8SetReturnValue(info, result); |
288 } | 288 } |
289 | 289 |
290 static void setExceptionAsReturnValue(const v8::FunctionCallbackInfo<v8::Value>&
info, v8::Local<v8::Object> returnValue, v8::TryCatch& tryCatch) | 290 static void setExceptionAsReturnValue(const v8::FunctionCallbackInfo<v8::Value>&
info, v8::Local<v8::Object> returnValue, v8::TryCatch& tryCatch) |
291 { | 291 { |
292 v8::Isolate* isolate = info.GetIsolate(); | 292 v8::Isolate* isolate = info.GetIsolate(); |
293 returnValue->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.Except
ion()); | 293 returnValue->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.Except
ion()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 return; | 326 return; |
327 } | 327 } |
328 | 328 |
329 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI
Symbol(isolate); | 329 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI
Symbol(isolate); |
330 v8::Local<v8::Object> global = context->Global(); | 330 v8::Local<v8::Object> global = context->Global(); |
331 if (info.Length() >= 2 && info[1]->IsObject()) { | 331 if (info.Length() >= 2 && info[1]->IsObject()) { |
332 v8::Local<v8::Object> commandLineAPI = info[1]->ToObject(isolate); | 332 v8::Local<v8::Object> commandLineAPI = info[1]->ToObject(isolate); |
333 global->Set(commandLineAPISymbolValue, commandLineAPI); | 333 global->Set(commandLineAPISymbolValue, commandLineAPI); |
334 } | 334 } |
335 | 335 |
336 v8::MaybeLocal<v8::Value> result = host->debugger()->client()->runCompiledSc
ript(context, script); | 336 v8::MaybeLocal<v8::Value> result = host->debugger()->runCompiledScript(conte
xt, script); |
337 if (result.IsEmpty()) { | 337 if (result.IsEmpty()) { |
338 global->Delete(context, commandLineAPISymbolValue); | 338 global->Delete(context, commandLineAPISymbolValue); |
339 setExceptionAsReturnValue(info, wrappedResult, tryCatch); | 339 setExceptionAsReturnValue(info, wrappedResult, tryCatch); |
340 return; | 340 return; |
341 } | 341 } |
342 | 342 |
343 global->Delete(context, commandLineAPISymbolValue); | 343 global->Delete(context, commandLineAPISymbolValue); |
344 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result.ToLoca
lChecked()); | 344 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result.ToLoca
lChecked()); |
345 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8:
:Undefined(isolate)); | 345 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8:
:Undefined(isolate)); |
346 v8SetReturnValue(info, wrappedResult); | 346 v8SetReturnValue(info, wrappedResult); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 host->unmonitorFunction(scriptId, lineNumber, columnNumber); | 415 host->unmonitorFunction(scriptId, lineNumber, columnNumber); |
416 } | 416 } |
417 | 417 |
418 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v
8::Value>& info) | 418 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v
8::Value>& info) |
419 { | 419 { |
420 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { | 420 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { |
421 ASSERT_NOT_REACHED(); | 421 ASSERT_NOT_REACHED(); |
422 return; | 422 return; |
423 } | 423 } |
424 | 424 |
| 425 v8::MicrotasksScope microtasks(info.GetIsolate(), v8::MicrotasksScope::kDoNo
tRunMicrotasks); |
425 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); | 426 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); |
426 v8::Local<v8::Value> receiver = info[1]; | 427 v8::Local<v8::Value> receiver = info[1]; |
427 | 428 |
428 if (info.Length() < 3 || info[2]->IsUndefined()) { | 429 if (info.Length() < 3 || info[2]->IsUndefined()) { |
429 v8::Local<v8::Value> result = function->Call(receiver, 0, 0); | 430 v8::Local<v8::Value> result = function->Call(receiver, 0, 0); |
430 v8SetReturnValue(info, result); | 431 v8SetReturnValue(info, result); |
431 return; | 432 return; |
432 } | 433 } |
433 | 434 |
434 if (!info[2]->IsArray()) { | 435 if (!info[2]->IsArray()) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 } // namespace | 573 } // namespace |
573 | 574 |
574 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8::
Isolate* isolate) | 575 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8::
Isolate* isolate) |
575 { | 576 { |
576 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR
RAY_LENGTH(V8InjectedScriptHostMethods)); | 577 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR
RAY_LENGTH(V8InjectedScriptHostMethods)); |
577 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR
AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); | 578 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR
AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); |
578 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; | 579 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; |
579 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at
tributes); | 580 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at
tributes); |
580 } | 581 } |
581 | 582 |
582 v8::Local<v8::Object> V8InjectedScriptHost::wrap(V8DebuggerClient* client, v8::L
ocal<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context,
InjectedScriptHost* host) | 583 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate>
constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host) |
583 { | 584 { |
584 return InjectedScriptHostWrapper::wrap(client, constructorTemplate, context,
host); | 585 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); |
585 } | 586 } |
586 | 587 |
587 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context,
v8::Local<v8::Object> object) | 588 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context,
v8::Local<v8::Object> object) |
588 { | 589 { |
589 return InjectedScriptHostWrapper::unwrap(context, object); | 590 return InjectedScriptHostWrapper::unwrap(context, object); |
590 } | 591 } |
591 | 592 |
592 } // namespace blink | 593 } // namespace blink |
OLD | NEW |