Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[DevTools] Blackbox sources with inline source maps
Browse files Browse the repository at this point in the history
BUG=341082
[email protected],[email protected], oilpan-reviews

Review URL: https://codereview.chromium.org/1579283002

Cr-Commit-Position: refs/heads/master@{#370182}
  • Loading branch information
alexkozy authored and Commit bot committed Jan 19, 2016
1 parent e29e658 commit 8f131d2
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Stack trace:
testFunction:10:21
Stack trace:
testFunction:10:21
Stack trace:
boo:5:12
foo:2:12
testFunction:10:21
Stack trace:
testFunction:10:21

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script type="text/javascript" src="resources/framework-with-inline-sourcemap.js"></script>
<script>
function boo()
{
return 239;
}

function testFunction()
{
debugger;
foo(boo);
}

function test()
{
var actions = [ "stepInto", "stepInto", "stepOut" ];

InspectorTest.eventHandler["Debugger.paused"] = printStackTraceAndMakeNextStep;
InspectorTest.sendCommand("Debugger.enable", {}, setSkipStackFrames);

function setSkipStackFrames(response)
{
failIfError(response);
InspectorTest.sendCommand("Debugger.skipStackFrames", { script: "foo\\.js$"}, callTestFunction);
}

function callTestFunction(response)
{
failIfError(response);
InspectorTest.sendCommand("Runtime.evaluate", { "expression": "setTimeout(testFunction, 0)"});
}

function printStackTraceAndMakeNextStep(response)
{
failIfError(response);
var callFrames = response.params.callFrames;
InspectorTest.log("Stack trace:")
for (var callFrame of callFrames) {
var location = callFrame.functionLocation.lineNumber + ":" + callFrame.functionLocation.columnNumber;
InspectorTest.log(callFrame.functionName + ":" + location);
}

var action = actions.shift();
if (!action)
InspectorTest.completeTest();
else
InspectorTest.sendCommand("Debugger." + action);
}

function failIfError(response)
{
if (response.error) {
InspectorTest.log(JSON.stringify(response));
InspectorTest.completeTest();
}
}
}
</script>
</head>
<body onload="runTest()">
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "core/inspector/v8/V8Debugger.h"
#include "core/inspector/v8/V8JavaScriptCallFrame.h"
#include "platform/JSONValues.h"
#include "platform/SharedBuffer.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/Platform.h"
#include "wtf/Optional.h"
#include "wtf/text/StringBuilder.h"
#include "wtf/text/WTFString.h"
Expand Down Expand Up @@ -121,6 +124,19 @@ static PassRefPtrWillBeRawPtr<ScriptCallStack> toScriptCallStack(v8::Local<v8::C
return jsCallFrame ? toScriptCallStack(jsCallFrame.get()) : nullptr;
}

static PassOwnPtr<SourceMap> parseSourceMapFromDataUrl(const String& url)
{
KURL sourceMapURL(KURL(), url);
if (sourceMapURL.isEmpty() || !sourceMapURL.isValid())
return nullptr;
WebString mimetype;
WebString charset;
RefPtr<SharedBuffer> data = PassRefPtr<SharedBuffer>(Platform::current()->parseDataURL(sourceMapURL, mimetype, charset));
if (!data)
return nullptr;
return SourceMap::parse(String(data->data(), data->size()));
}

PassOwnPtr<V8DebuggerAgent> V8DebuggerAgent::create(InjectedScriptManager* injectedScriptManager, V8Debugger* debugger, int contextGroupId)
{
return adoptPtr(new V8DebuggerAgentImpl(injectedScriptManager, static_cast<V8DebuggerImpl*>(debugger), contextGroupId));
Expand Down Expand Up @@ -217,6 +233,7 @@ void V8DebuggerAgentImpl::disable(ErrorString*)
m_pausedScriptState = nullptr;
m_currentCallStack.Reset();
m_scripts.clear();
m_sourceMaps.clear();
m_breakpointIdToDebuggerBreakpointIds.clear();
internalSetAsyncCallStackDepth(0);
m_promiseTracker->setEnabled(false, false);
Expand Down Expand Up @@ -519,9 +536,17 @@ bool V8DebuggerAgentImpl::isCallFrameWithUnknownScriptOrBlackboxed(PassRefPtr<Ja
return true;
bool isBlackboxed = false;
String scriptURL = it->value.sourceURL();
if (m_cachedSkipStackRegExp && !scriptURL.isEmpty()) {
String sourceMappedScriptURL;
auto itSourceMap = m_sourceMaps.find(String::number(frame->sourceID()));
if (itSourceMap != m_sourceMaps.end()) {
const SourceMap::Entry* entry = itSourceMap->value->findEntry(frame->line(), frame->column());
if (entry)
sourceMappedScriptURL = entry->sourceURL;
}
if (m_cachedSkipStackRegExp && (!scriptURL.isEmpty() || !sourceMappedScriptURL.isEmpty())) {
if (!it->value.getBlackboxedState(m_cachedSkipStackGeneration, &isBlackboxed)) {
isBlackboxed = m_cachedSkipStackRegExp->match(scriptURL) != -1;
isBlackboxed = !scriptURL.isEmpty() && m_cachedSkipStackRegExp->match(scriptURL) != -1;
isBlackboxed = isBlackboxed || (!sourceMappedScriptURL.isEmpty() && m_cachedSkipStackRegExp->match(sourceMappedScriptURL) != -1);
it->value.setBlackboxedState(m_cachedSkipStackGeneration, isBlackboxed);
}
}
Expand Down Expand Up @@ -1480,6 +1505,9 @@ void V8DebuggerAgentImpl::didParseSource(const V8DebuggerParsedScript& parsedScr
bool hasSourceURL = script.hasSourceURL();
String scriptURL = script.sourceURL();
String sourceMapURL = sourceMapURLForScript(script, parsedScript.success);
OwnPtr<SourceMap> sourceMap = parseSourceMapFromDataUrl(sourceMapURL);
if (sourceMap)
m_sourceMaps.set(parsedScript.scriptId, sourceMap.release());

const String* sourceMapURLParam = sourceMapURL.isNull() ? nullptr : &sourceMapURL;
const bool* isContentScriptParam = isContentScript ? &isContentScript : nullptr;
Expand Down Expand Up @@ -1662,6 +1690,7 @@ void V8DebuggerAgentImpl::reset()
{
m_scheduledDebuggerStep = NoStep;
m_scripts.clear();
m_sourceMaps.clear();
m_breakpointIdToDebuggerBreakpointIds.clear();
resetAsyncCallTracker();
m_promiseTracker->clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "core/inspector/InspectorBaseAgent.h"
#include "core/inspector/PromiseTracker.h"
#include "core/inspector/v8/ScriptBreakpoint.h"
#include "core/inspector/v8/SourceMap.h"
#include "core/inspector/v8/V8DebuggerAgent.h"
#include "core/inspector/v8/V8DebuggerImpl.h"
#include "platform/heap/Handle.h"
Expand Down Expand Up @@ -246,6 +247,7 @@ class CORE_EXPORT V8DebuggerAgentImpl
bool m_pendingTraceAsyncOperationCompleted;
bool m_startingStepIntoAsync;
V8GlobalValueMap<String, v8::Script, v8::kNotWeak> m_compiledScripts;
HashMap<String, OwnPtr<SourceMap>> m_sourceMaps;
};

} // namespace blink
Expand Down

0 comments on commit 8f131d2

Please sign in to comment.