| OLD | NEW |
| 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 21 matching lines...) Expand all Loading... |
| 32 #include "ScriptDebugServer.h" | 32 #include "ScriptDebugServer.h" |
| 33 | 33 |
| 34 | 34 |
| 35 #include "DebuggerScriptSource.h" | 35 #include "DebuggerScriptSource.h" |
| 36 #include "JavaScriptCallFrame.h" | 36 #include "JavaScriptCallFrame.h" |
| 37 #include "ScopedPersistent.h" | 37 #include "ScopedPersistent.h" |
| 38 #include "ScriptDebugListener.h" | 38 #include "ScriptDebugListener.h" |
| 39 #include "ScriptObject.h" | 39 #include "ScriptObject.h" |
| 40 #include "V8Binding.h" | 40 #include "V8Binding.h" |
| 41 #include "V8JavaScriptCallFrame.h" | 41 #include "V8JavaScriptCallFrame.h" |
| 42 #include "V8PerContextDebugData.h" |
| 42 #include "V8RecursionScope.h" | 43 #include "V8RecursionScope.h" |
| 43 #include <wtf/StdLibExtras.h> | 44 #include <wtf/StdLibExtras.h> |
| 44 #include <wtf/Vector.h> | 45 #include <wtf/Vector.h> |
| 45 | 46 |
| 46 namespace WebCore { | 47 namespace WebCore { |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 class ClientDataImpl : public v8::Debug::ClientData { | 51 class ClientDataImpl : public v8::Debug::ClientData { |
| 51 public: | 52 public: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 class ScriptDebugServer::ScriptPreprocessor { | 86 class ScriptDebugServer::ScriptPreprocessor { |
| 86 WTF_MAKE_NONCOPYABLE(ScriptPreprocessor); | 87 WTF_MAKE_NONCOPYABLE(ScriptPreprocessor); |
| 87 public: | 88 public: |
| 88 explicit ScriptPreprocessor(const String& preprocessorScript) | 89 explicit ScriptPreprocessor(const String& preprocessorScript) |
| 89 { | 90 { |
| 90 v8::HandleScope scope; | 91 v8::HandleScope scope; |
| 91 | 92 |
| 92 m_utilityContext.set(v8::Context::New()); | 93 m_utilityContext.set(v8::Context::New()); |
| 93 if (m_utilityContext.isEmpty()) | 94 if (m_utilityContext.isEmpty()) |
| 94 return; | 95 return; |
| 95 | 96 |
| 97 V8PerContextDebugData::setDebugDataForSystemUtility(m_utilityContext.get
()); |
| 98 |
| 96 v8::Context::Scope contextScope(m_utilityContext.get()); | 99 v8::Context::Scope contextScope(m_utilityContext.get()); |
| 97 | 100 |
| 98 v8::TryCatch tryCatch; | 101 v8::TryCatch tryCatch; |
| 99 | 102 |
| 100 String wrappedScript = makeString("(", preprocessorScript, ")"); | 103 String wrappedScript = makeString("(", preprocessorScript, ")"); |
| 101 v8::Handle<v8::String> preprocessor = v8::String::New(wrappedScript.utf8
().data(), wrappedScript.utf8().length()); | 104 v8::Handle<v8::String> preprocessor = v8::String::New(wrappedScript.utf8
().data(), wrappedScript.utf8().length()); |
| 102 | 105 |
| 103 v8::Handle<v8::Script> script = v8::Script::Compile(preprocessor); | 106 v8::Handle<v8::Script> script = v8::Script::Compile(preprocessor); |
| 104 | 107 |
| 105 if (tryCatch.HasCaught()) | 108 if (tryCatch.HasCaught()) |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() }; | 472 v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() }; |
| 470 v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_deb
uggerScript.get(), 1, argv1); | 473 v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_deb
uggerScript.get(), 1, argv1); |
| 471 | 474 |
| 472 v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Fun
ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource"))); | 475 v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Fun
ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource"))); |
| 473 String patchedScript = preprocessor->preprocessSourceCode(toWebCoreS
tringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(s
criptName)); | 476 String patchedScript = preprocessor->preprocessSourceCode(toWebCoreS
tringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(s
criptName)); |
| 474 | 477 |
| 475 v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8Str
ing(patchedScript, debugContext->GetIsolate()) }; | 478 v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8Str
ing(patchedScript, debugContext->GetIsolate()) }; |
| 476 setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2); | 479 setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2); |
| 477 m_scriptPreprocessor = preprocessor.release(); | 480 m_scriptPreprocessor = preprocessor.release(); |
| 478 } else if (event == v8::AfterCompile) { | 481 } else if (event == v8::AfterCompile) { |
| 479 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); | 482 onAfterCompile(listener, eventDetails); |
| 480 v8::Handle<v8::Function> onAfterCompileFunction = v8::Local<v8::Func
tion>::Cast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getAfterCompileSc
ript"))); | |
| 481 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; | |
| 482 v8::Handle<v8::Value> value = onAfterCompileFunction->Call(m_debugge
rScript.get(), 1, argv); | |
| 483 ASSERT(value->IsObject()); | |
| 484 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value); | |
| 485 dispatchDidParseSource(listener, object); | |
| 486 } else if (event == v8::Break || event == v8::Exception) { | 483 } else if (event == v8::Break || event == v8::Exception) { |
| 487 v8::Handle<v8::Value> exception; | 484 v8::Handle<v8::Value> exception; |
| 488 if (event == v8::Exception) { | 485 if (event == v8::Exception) { |
| 489 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentSt
ackTrace(1); | 486 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentSt
ackTrace(1); |
| 490 // Stack trace is empty in case of syntax error. Silently contin
ue execution in such cases. | 487 // Stack trace is empty in case of syntax error. Silently contin
ue execution in such cases. |
| 491 if (!stackTrace->GetFrameCount()) | 488 if (!stackTrace->GetFrameCount()) |
| 492 return; | 489 return; |
| 493 v8::Handle<v8::Object> eventData = eventDetails.GetEventData(); | 490 v8::Handle<v8::Object> eventData = eventDetails.GetEventData(); |
| 494 v8::Handle<v8::Value> exceptionGetterValue = eventData->Get(v8::
String::NewSymbol("exception")); | 491 v8::Handle<v8::Value> exceptionGetterValue = eventData->Get(v8::
String::NewSymbol("exception")); |
| 495 ASSERT(!exceptionGetterValue.IsEmpty() && exceptionGetterValue->
IsFunction()); | 492 ASSERT(!exceptionGetterValue.IsEmpty() && exceptionGetterValue->
IsFunction()); |
| 496 v8::Handle<v8::Value> argv[] = { v8Undefined() }; | 493 v8::Handle<v8::Value> argv[] = { v8Undefined() }; |
| 497 V8RecursionScope::MicrotaskSuppression scope; | 494 V8RecursionScope::MicrotaskSuppression scope; |
| 498 exception = v8::Handle<v8::Function>::Cast(exceptionGetterValue)
->Call(eventData, 0, argv); | 495 exception = v8::Handle<v8::Function>::Cast(exceptionGetterValue)
->Call(eventData, 0, argv); |
| 499 } | 496 } |
| 500 | 497 |
| 501 m_pausedContext = *eventContext; | 498 m_pausedContext = *eventContext; |
| 502 breakProgram(eventDetails.GetExecutionState(), exception); | 499 breakProgram(eventDetails.GetExecutionState(), exception); |
| 503 m_pausedContext.Clear(); | 500 m_pausedContext.Clear(); |
| 504 } | 501 } |
| 505 } | 502 } |
| 506 } | 503 } |
| 507 | 504 |
| 505 void ScriptDebugServer::onAfterCompile(ScriptDebugListener* listener, const v8::
Debug::EventDetails& eventDetails) |
| 506 { |
| 507 v8::HandleScope scope; |
| 508 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); |
| 509 v8::Handle<v8::Function> onAfterCompileFunction = v8::Local<v8::Function>::C
ast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getAfterCompileScript")))
; |
| 510 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; |
| 511 v8::Handle<v8::Value> value = onAfterCompileFunction->Call(m_debuggerScript.
get(), 1, argv); |
| 512 ASSERT(value->IsObject()); |
| 513 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value); |
| 514 dispatchDidParseSource(listener, object); |
| 515 } |
| 516 |
| 508 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8
::Handle<v8::Object> object) | 517 void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8
::Handle<v8::Object> object) |
| 509 { | 518 { |
| 519 |
| 510 String sourceID = toWebCoreStringWithUndefinedOrNullCheck(object->Get(v8::St
ring::NewSymbol("id"))); | 520 String sourceID = toWebCoreStringWithUndefinedOrNullCheck(object->Get(v8::St
ring::NewSymbol("id"))); |
| 511 | 521 |
| 512 ScriptDebugListener::Script script; | 522 ScriptDebugListener::Script script; |
| 513 script.url = toWebCoreStringWithUndefinedOrNullCheck(object->Get(v8::String:
:NewSymbol("name"))); | 523 script.url = toWebCoreStringWithUndefinedOrNullCheck(object->Get(v8::String:
:NewSymbol("name"))); |
| 514 script.source = toWebCoreStringWithUndefinedOrNullCheck(object->Get(v8::Stri
ng::NewSymbol("source"))); | 524 script.source = toWebCoreStringWithUndefinedOrNullCheck(object->Get(v8::Stri
ng::NewSymbol("source"))); |
| 515 script.sourceMappingURL = toWebCoreStringWithUndefinedOrNullCheck(object->Ge
t(v8::String::NewSymbol("sourceMappingURL"))); | 525 script.sourceMappingURL = toWebCoreStringWithUndefinedOrNullCheck(object->Ge
t(v8::String::NewSymbol("sourceMappingURL"))); |
| 516 script.startLine = object->Get(v8::String::NewSymbol("startLine"))->ToIntege
r()->Value(); | 526 script.startLine = object->Get(v8::String::NewSymbol("startLine"))->ToIntege
r()->Value(); |
| 517 script.startColumn = object->Get(v8::String::NewSymbol("startColumn"))->ToIn
teger()->Value(); | 527 script.startColumn = object->Get(v8::String::NewSymbol("startColumn"))->ToIn
teger()->Value(); |
| 518 script.endLine = object->Get(v8::String::NewSymbol("endLine"))->ToInteger()-
>Value(); | 528 script.endLine = object->Get(v8::String::NewSymbol("endLine"))->ToInteger()-
>Value(); |
| 519 script.endColumn = object->Get(v8::String::NewSymbol("endColumn"))->ToIntege
r()->Value(); | 529 script.endColumn = object->Get(v8::String::NewSymbol("endColumn"))->ToIntege
r()->Value(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 *result = ScriptValue(tryCatch.Exception()); | 643 *result = ScriptValue(tryCatch.Exception()); |
| 634 v8::Local<v8::Message> message = tryCatch.Message(); | 644 v8::Local<v8::Message> message = tryCatch.Message(); |
| 635 if (!message.IsEmpty()) | 645 if (!message.IsEmpty()) |
| 636 *exceptionMessage = toWebCoreStringWithUndefinedOrNullCheck(message-
>Get()); | 646 *exceptionMessage = toWebCoreStringWithUndefinedOrNullCheck(message-
>Get()); |
| 637 } else | 647 } else |
| 638 *result = ScriptValue(value); | 648 *result = ScriptValue(value); |
| 639 } | 649 } |
| 640 | 650 |
| 641 } // namespace WebCore | 651 } // namespace WebCore |
| 642 | 652 |
| OLD | NEW |