OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "bindings/core/v8/SourceLocation.h" |
| 6 |
| 7 #include "bindings/core/v8/V8PerIsolateData.h" |
| 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/dom/ScriptableDocumentParser.h" |
| 11 #include "core/html/HTMLFrameOwnerElement.h" |
| 12 #include "core/inspector/InspectorInstrumentation.h" |
| 13 #include "core/inspector/ThreadDebugger.h" |
| 14 #include "platform/ScriptForbiddenScope.h" |
| 15 #include "platform/TracedValue.h" |
| 16 #include "platform/v8_inspector/public/V8Debugger.h" |
| 17 |
| 18 namespace blink { |
| 19 |
| 20 namespace { |
| 21 |
| 22 PassOwnPtr<V8StackTrace> captureStackTrace() |
| 23 { |
| 24 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 25 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 26 if (!data->threadDebugger() || !isolate->InContext()) |
| 27 return nullptr; |
| 28 size_t stackSize = 1; |
| 29 if (InspectorInstrumentation::hasFrontends()) { |
| 30 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex
t(isolate))) |
| 31 stackSize = V8StackTrace::maxCallStackSizeToCapture; |
| 32 } |
| 33 ScriptForbiddenScope::AllowUserAgentScript allowScripting; |
| 34 return data->threadDebugger()->debugger()->captureStackTrace(stackSize); |
| 35 } |
| 36 |
| 37 } |
| 38 |
| 39 // static |
| 40 PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l
ineNumber, unsigned columnNumber) |
| 41 { |
| 42 OwnPtr<V8StackTrace> stackTrace = captureStackTrace(); |
| 43 if (stackTrace && !stackTrace->isEmpty()) |
| 44 return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->to
pLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0); |
| 45 return SourceLocation::create(url, lineNumber, columnNumber, std::move(stack
Trace)); |
| 46 } |
| 47 |
| 48 // static |
| 49 PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo
ntext) |
| 50 { |
| 51 OwnPtr<V8StackTrace> stackTrace = captureStackTrace(); |
| 52 if (stackTrace && !stackTrace->isEmpty()) |
| 53 return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->to
pLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0); |
| 54 |
| 55 Document* document = executionContext && executionContext->isDocument() ? to
Document(executionContext) : nullptr; |
| 56 if (document) { |
| 57 unsigned lineNumber = 0; |
| 58 if (document->scriptableDocumentParser() && !document->isInDocumentWrite
()) { |
| 59 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) |
| 60 lineNumber = document->scriptableDocumentParser()->lineNumber().
oneBasedInt(); |
| 61 } |
| 62 return SourceLocation::create(document->url().getString(), lineNumber, 0
, std::move(stackTrace)); |
| 63 } |
| 64 |
| 65 return SourceLocation::create(executionContext ? executionContext->url().get
String() : "", 0, 0, std::move(stackTrace)); |
| 66 } |
| 67 |
| 68 // static |
| 69 PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li
neNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int script
Id) |
| 70 { |
| 71 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(
stackTrace), scriptId)); |
| 72 } |
| 73 |
| 74 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned
columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int scriptId) |
| 75 : m_url(url) |
| 76 , m_lineNumber(lineNumber) |
| 77 , m_columnNumber(columnNumber) |
| 78 , m_stackTrace(std::move(stackTrace)) |
| 79 , m_scriptId(scriptId) |
| 80 { |
| 81 } |
| 82 |
| 83 SourceLocation::~SourceLocation() |
| 84 { |
| 85 } |
| 86 |
| 87 } // namespace blink |
OLD | NEW |