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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/SourceLocation.cpp

Issue 1997293002: Introduce SourceLocation to be used for console messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/SourceLocation.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/SourceLocation.cpp b/third_party/WebKit/Source/bindings/core/v8/SourceLocation.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..048e5ca1ca9b7d30491f49e04527d680a8f353da
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/SourceLocation.cpp
@@ -0,0 +1,87 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "bindings/core/v8/SourceLocation.h"
+
+#include "bindings/core/v8/V8PerIsolateData.h"
+#include "core/dom/Document.h"
+#include "core/dom/ExecutionContext.h"
+#include "core/dom/ScriptableDocumentParser.h"
+#include "core/html/HTMLFrameOwnerElement.h"
+#include "core/inspector/InspectorInstrumentation.h"
+#include "core/inspector/ThreadDebugger.h"
+#include "platform/ScriptForbiddenScope.h"
+#include "platform/TracedValue.h"
+#include "platform/v8_inspector/public/V8Debugger.h"
+
+namespace blink {
+
+namespace {
+
+PassOwnPtr<V8StackTrace> captureStackTrace()
+{
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ V8PerIsolateData* data = V8PerIsolateData::from(isolate);
+ if (!data->threadDebugger() || !isolate->InContext())
+ return nullptr;
+ size_t stackSize = 1;
+ if (InspectorInstrumentation::hasFrontends()) {
+ if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContext(isolate)))
+ stackSize = V8StackTrace::maxCallStackSizeToCapture;
+ }
+ ScriptForbiddenScope::AllowUserAgentScript allowScripting;
+ return data->threadDebugger()->debugger()->captureStackTrace(stackSize);
+}
+
+}
+
+// static
+PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned lineNumber, unsigned columnNumber)
+{
+ OwnPtr<V8StackTrace> stackTrace = captureStackTrace();
+ if (stackTrace && !stackTrace->isEmpty())
+ return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->topLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0);
+ return SourceLocation::create(url, lineNumber, columnNumber, std::move(stackTrace));
+}
+
+// static
+PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionContext)
+{
+ OwnPtr<V8StackTrace> stackTrace = captureStackTrace();
+ if (stackTrace && !stackTrace->isEmpty())
+ return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->topLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0);
+
+ Document* document = executionContext && executionContext->isDocument() ? toDocument(executionContext) : nullptr;
+ if (document) {
+ unsigned lineNumber = 0;
+ if (document->scriptableDocumentParser() && !document->isInDocumentWrite()) {
+ if (document->scriptableDocumentParser()->isParsingAtLineNumber())
+ lineNumber = document->scriptableDocumentParser()->lineNumber().oneBasedInt();
+ }
+ return SourceLocation::create(document->url().getString(), lineNumber, 0, std::move(stackTrace));
+ }
+
+ return SourceLocation::create(executionContext ? executionContext->url().getString() : "", 0, 0, std::move(stackTrace));
+}
+
+// static
+PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned lineNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int scriptId)
+{
+ return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(stackTrace), scriptId));
+}
+
+SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int scriptId)
+ : m_url(url)
+ , m_lineNumber(lineNumber)
+ , m_columnNumber(columnNumber)
+ , m_stackTrace(std::move(stackTrace))
+ , m_scriptId(scriptId)
+{
+}
+
+SourceLocation::~SourceLocation()
+{
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/SourceLocation.h ('k') | third_party/WebKit/Source/bindings/core/v8/v8.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698