| Index: Source/bindings/v8/ScriptDebugServer.cpp
|
| diff --git a/Source/bindings/v8/ScriptDebugServer.cpp b/Source/bindings/v8/ScriptDebugServer.cpp
|
| index 6a89c771baffb950fb1964175662fdcdabea9adc..403dca5e8f5838eeff83253899caa8103d3827a8 100644
|
| --- a/Source/bindings/v8/ScriptDebugServer.cpp
|
| +++ b/Source/bindings/v8/ScriptDebugServer.cpp
|
| @@ -39,8 +39,10 @@
|
| #include "ScriptObject.h"
|
| #include "V8Binding.h"
|
| #include "V8JavaScriptCallFrame.h"
|
| +#include "V8PerContextDebugData.h"
|
| #include "V8RecursionScope.h"
|
| #include <wtf/StdLibExtras.h>
|
| +#include <wtf/StringExtras.h>
|
| #include <wtf/Vector.h>
|
|
|
| namespace WebCore {
|
| @@ -85,6 +87,7 @@ v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN
|
| class ScriptDebugServer::ScriptPreprocessor {
|
| WTF_MAKE_NONCOPYABLE(ScriptPreprocessor);
|
| public:
|
| +
|
| explicit ScriptPreprocessor(const String& preprocessorScript)
|
| {
|
| v8::HandleScope scope;
|
| @@ -92,7 +95,9 @@ public:
|
| m_utilityContext.set(v8::Context::New());
|
| if (m_utilityContext.isEmpty())
|
| return;
|
| -
|
| +
|
| + V8PerContextDebugData::setDebugDataForSystemUtility(m_utilityContext.get());
|
| +
|
| v8::Context::Scope contextScope(m_utilityContext.get());
|
|
|
| v8::TryCatch tryCatch;
|
| @@ -137,7 +142,13 @@ public:
|
|
|
| if (resultValue->IsString()) {
|
| v8::String::Utf8Value utf8Value(resultValue);
|
| - return String::fromUTF8(*utf8Value, utf8Value.length());
|
| +
|
| + String preprocessed = String::fromUTF8(*utf8Value, utf8Value.length());
|
| + // Zero bytes crash the page if we are preprocessing injectedScripts
|
| + if (preprocessed.length() == 0)
|
| + return sourceCode;
|
| +
|
| + return preprocessed;
|
| }
|
|
|
| return sourceCode;
|
| @@ -458,9 +469,15 @@ void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
|
| if (!m_scriptPreprocessor)
|
| return;
|
|
|
| + // Only preprocess web scripts
|
| + if (V8PerContextDebugData::compilationOriginCategory(eventContext) != CompilationOriginWeb)
|
| + return;
|
| +
|
| OwnPtr<ScriptPreprocessor> preprocessor(m_scriptPreprocessor.release());
|
| +
|
| v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
|
| v8::Context::Scope contextScope(debugContext);
|
| +
|
| v8::Handle<v8::Function> getScriptSourceFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptSource")));
|
| v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
|
| v8::Handle<v8::Value> script = getScriptSourceFunction->Call(m_debuggerScript.get(), 1, argv);
|
| @@ -469,8 +486,13 @@ void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
|
| v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() };
|
| v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_debuggerScript.get(), 1, argv1);
|
|
|
| + v8::String::Utf8Value scriptNameUtf8Value(scriptName);
|
| + String scriptNameString = String::fromUTF8(*scriptNameUtf8Value, scriptNameUtf8Value.length());
|
| + if (scriptNameString.contains("data:text/html,chromewebdata"))
|
| + return;
|
| +
|
| v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource")));
|
| - String patchedScript = preprocessor->preprocessSourceCode(toWebCoreStringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(scriptName));
|
| + String patchedScript = preprocessor->preprocessSourceCode(toWebCoreStringWithUndefinedOrNullCheck(script), scriptNameString);
|
|
|
| v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8String(patchedScript, debugContext->GetIsolate()) };
|
| setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2);
|
|
|