Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: Source/bindings/core/v8/ScriptDebugServer.cpp

Issue 433653003: Support Promises event-based instrumentation on backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address comments + REBASE Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD etails) 464 void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD etails)
465 { 465 {
466 v8::DebugEvent event = eventDetails.GetEvent(); 466 v8::DebugEvent event = eventDetails.GetEvent();
467 467
468 if (event == v8::BreakForCommand) { 468 if (event == v8::BreakForCommand) {
469 ClientDataImpl* data = static_cast<ClientDataImpl*>(eventDetails.GetClie ntData()); 469 ClientDataImpl* data = static_cast<ClientDataImpl*>(eventDetails.GetClie ntData());
470 data->task()->run(); 470 data->task()->run();
471 return; 471 return;
472 } 472 }
473 473
474 if (event != v8::AsyncTaskEvent && event != v8::Break && event != v8::Except ion && event != v8::AfterCompile && event != v8::BeforeCompile && event != v8::C ompileError) 474 if (event != v8::AsyncTaskEvent && event != v8::Break && event != v8::Except ion && event != v8::AfterCompile && event != v8::BeforeCompile && event != v8::C ompileError && event != v8::PromiseEvent)
475 return; 475 return;
476 476
477 v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext(); 477 v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext();
478 ASSERT(!eventContext.IsEmpty()); 478 ASSERT(!eventContext.IsEmpty());
479 479
480 ScriptDebugListener* listener = getDebugListenerForContext(eventContext); 480 ScriptDebugListener* listener = getDebugListenerForContext(eventContext);
481 if (listener) { 481 if (listener) {
482 v8::HandleScope scope(m_isolate); 482 v8::HandleScope scope(m_isolate);
483 v8::Handle<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isol ate); 483 v8::Handle<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isol ate);
484 if (event == v8::BeforeCompile) { 484 if (event == v8::BeforeCompile) {
(...skipping 11 matching lines...) Expand all
496 v8::Handle<v8::Value> exception = callInternalGetterFunction(eventDa ta, "exception", m_isolate); 496 v8::Handle<v8::Value> exception = callInternalGetterFunction(eventDa ta, "exception", m_isolate);
497 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get ExecutionState(), exception, v8::Handle<v8::Array>()); 497 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get ExecutionState(), exception, v8::Handle<v8::Array>());
498 } else if (event == v8::Break) { 498 } else if (event == v8::Break) {
499 v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8 ::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getBreakpointNu mbers"))); 499 v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8 ::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getBreakpointNu mbers")));
500 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; 500 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
501 v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalF unction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), ar gv, m_isolate); 501 v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalF unction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), ar gv, m_isolate);
502 ASSERT(hitBreakpoints->IsArray()); 502 ASSERT(hitBreakpoints->IsArray());
503 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get ExecutionState(), v8::Handle<v8::Value>(), hitBreakpoints.As<v8::Array>()); 503 handleProgramBreak(ScriptState::from(eventContext), eventDetails.Get ExecutionState(), v8::Handle<v8::Value>(), hitBreakpoints.As<v8::Array>());
504 } else if (event == v8::AsyncTaskEvent) { 504 } else if (event == v8::AsyncTaskEvent) {
505 handleV8AsyncTaskEvent(listener, ScriptState::from(eventContext), ev entDetails.GetExecutionState(), eventDetails.GetEventData()); 505 handleV8AsyncTaskEvent(listener, ScriptState::from(eventContext), ev entDetails.GetExecutionState(), eventDetails.GetEventData());
506 } else if (event == v8::PromiseEvent) {
507 handleV8PromiseEvent(listener, ScriptState::from(eventContext), even tDetails.GetExecutionState(), eventDetails.GetEventData());
506 } 508 }
507 } 509 }
508 } 510 }
509 511
510 void ScriptDebugServer::handleV8AsyncTaskEvent(ScriptDebugListener* listener, Sc riptState* pausedScriptState, v8::Handle<v8::Object> executionState, v8::Handle< v8::Object> eventData) 512 void ScriptDebugServer::handleV8AsyncTaskEvent(ScriptDebugListener* listener, Sc riptState* pausedScriptState, v8::Handle<v8::Object> executionState, v8::Handle< v8::Object> eventData)
511 { 513 {
512 String type = toCoreStringWithUndefinedOrNullCheck(callInternalGetterFunctio n(eventData, "type", m_isolate)); 514 String type = toCoreStringWithUndefinedOrNullCheck(callInternalGetterFunctio n(eventData, "type", m_isolate));
513 String name = toCoreStringWithUndefinedOrNullCheck(callInternalGetterFunctio n(eventData, "name", m_isolate)); 515 String name = toCoreStringWithUndefinedOrNullCheck(callInternalGetterFunctio n(eventData, "name", m_isolate));
514 int id = callInternalGetterFunction(eventData, "id", m_isolate)->ToInteger() ->Value(); 516 int id = callInternalGetterFunction(eventData, "id", m_isolate)->ToInteger() ->Value();
515 517
516 // FIXME: Remove when not needed. 518 // FIXME: Remove when not needed.
517 if (name == "Promise.Resolved") 519 if (name == "Promise.Resolved")
518 name = "Promise.resolve"; 520 name = "Promise.resolve";
519 else if (name == "Promise.Rejected") 521 else if (name == "Promise.Rejected")
520 name = "Promise.reject"; 522 name = "Promise.reject";
521 523
522 m_pausedScriptState = pausedScriptState; 524 m_pausedScriptState = pausedScriptState;
523 m_executionState = executionState; 525 m_executionState = executionState;
524 listener->didReceiveV8AsyncTaskEvent(pausedScriptState->executionContext(), type, name, id); 526 listener->didReceiveV8AsyncTaskEvent(pausedScriptState->executionContext(), type, name, id);
525 m_pausedScriptState.clear(); 527 m_pausedScriptState.clear();
526 m_executionState.Clear(); 528 m_executionState.Clear();
527 } 529 }
528 530
531 void ScriptDebugServer::handleV8PromiseEvent(ScriptDebugListener* listener, Scri ptState* pausedScriptState, v8::Handle<v8::Object> executionState, v8::Handle<v8 ::Object> eventData)
532 {
533 m_pausedScriptState = pausedScriptState;
534 m_executionState = executionState;
535 v8::Isolate* isolate = m_pausedScriptState->isolate();
536 v8::Handle<v8::Value> argv[] = { eventData };
537 v8::Local<v8::Object> promiseDetails = callDebuggerMethod("getPromiseDetails ", 1, argv)->ToObject();
538 ScopedPersistent<v8::Object> promise(isolate, promiseDetails->Get(v8AtomicSt ring(m_isolate, "promise"))->ToObject());
539 int status = static_cast<int>(promiseDetails->Get(v8AtomicString(m_isolate, "status"))->ToInteger()->Value());
aandrey 2014/08/04 16:58:47 why static_cast<int>?
Alexandra Mikhaylova 2014/08/06 13:28:38 Removed it.
540 v8::Handle<v8::Value> parentPromiseHandle = promiseDetails->Get(v8AtomicStri ng(m_isolate, "parentPromise"));
541 ScopedPersistent<v8::Object> parentPromise(isolate, parentPromiseHandle->IsU ndefined() ? v8::Handle<v8::Object>() : parentPromiseHandle->ToObject());
aandrey 2014/08/04 16:58:47 use IsObject() instead of IsUndefined()
Alexandra Mikhaylova 2014/08/06 13:28:39 Done.
542 listener->didReceiveV8PromiseEvent(pausedScriptState, promise, parentPromise , status);
aandrey 2014/08/04 16:58:47 nit: line break before, assign m_pausedScriptState
Alexandra Mikhaylova 2014/08/06 13:28:38 Done.
543 m_pausedScriptState.clear();
544 m_executionState.Clear();
545 }
546
529 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8 ::Handle<v8::Object> object, CompileResult compileResult) 547 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8 ::Handle<v8::Object> object, CompileResult compileResult)
530 { 548 {
531 v8::Handle<v8::Value> id = object->Get(v8AtomicString(m_isolate, "id")); 549 v8::Handle<v8::Value> id = object->Get(v8AtomicString(m_isolate, "id"));
532 ASSERT(!id.IsEmpty() && id->IsInt32()); 550 ASSERT(!id.IsEmpty() && id->IsInt32());
533 String sourceID = String::number(id->Int32Value()); 551 String sourceID = String::number(id->Int32Value());
534 552
535 ScriptDebugListener::Script script; 553 ScriptDebugListener::Script script;
536 script.url = toCoreStringWithUndefinedOrNullCheck(object->Get(v8AtomicString (m_isolate, "name"))); 554 script.url = toCoreStringWithUndefinedOrNullCheck(object->Get(v8AtomicString (m_isolate, "name")));
537 script.sourceURL = toCoreStringWithUndefinedOrNullCheck(object->Get(v8Atomic String(m_isolate, "sourceURL"))); 555 script.sourceURL = toCoreStringWithUndefinedOrNullCheck(object->Get(v8Atomic String(m_isolate, "sourceURL")));
538 script.sourceMappingURL = toCoreStringWithUndefinedOrNullCheck(object->Get(v 8AtomicString(m_isolate, "sourceMappingURL"))); 556 script.sourceMappingURL = toCoreStringWithUndefinedOrNullCheck(object->Get(v 8AtomicString(m_isolate, "sourceMappingURL")));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 { 690 {
673 return PassOwnPtr<ScriptSourceCode>(); 691 return PassOwnPtr<ScriptSourceCode>();
674 } 692 }
675 693
676 String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& sou rce, const String& url, const String& functionName) 694 String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& sou rce, const String& url, const String& functionName)
677 { 695 {
678 return source; 696 return source;
679 } 697 }
680 698
681 } // namespace blink 699 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698