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

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

Issue 2004423007: SourceLocation: Fix use-after-move. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reflect review comments. 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
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/SourceLocation.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index f7e4197f4b94008753555589c481ea87de5ecacc..032e2b2cb8b275d70b6bb58932fd12315903f878 100644
--- a/third_party/WebKit/Source/bindings/core/v8/SourceLocation.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/SourceLocation.cpp
@@ -42,7 +42,7 @@ PassOwnPtr<SourceLocation> SourceLocation::capture(const String& url, unsigned l
{
std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace();
if (stackTrace && !stackTrace->isEmpty())
- return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->topLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0);
+ return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTrace), 0);
return SourceLocation::create(url, lineNumber, columnNumber, std::move(stackTrace));
}
@@ -51,7 +51,7 @@ PassOwnPtr<SourceLocation> SourceLocation::capture(ExecutionContext* executionCo
{
std::unique_ptr<V8StackTrace> stackTrace = captureStackTrace();
if (stackTrace && !stackTrace->isEmpty())
- return SourceLocation::create(stackTrace->topSourceURL(), stackTrace->topLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0);
+ return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTrace), 0);
Document* document = executionContext && executionContext->isDocument() ? toDocument(executionContext) : nullptr;
if (document) {
@@ -89,12 +89,12 @@ PassOwnPtr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate, v8:
++columnNumber;
if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty())
- return adoptPtr(new SourceLocation(stackTrace->topSourceURL(), stackTrace->topLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0));
+ return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTrace), 0);
String url = toCoreStringWithUndefinedOrNullCheck(message->GetScriptOrigin().ResourceName());
if (url.isNull())
url = executionContext->url();
- return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(stackTrace), scriptId));
+ return SourceLocation::create(url, lineNumber, columnNumber, std::move(stackTrace), scriptId);
}
// static
@@ -103,6 +103,16 @@ PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li
return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(stackTrace), scriptId));
}
+// static
+PassOwnPtr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace(std::unique_ptr<V8StackTrace> stackTrace, int scriptId)
+{
+ // Retrieve the data before passing the ownership to SourceLocation.
+ const String& url = stackTrace->topSourceURL();
+ unsigned lineNumber = stackTrace->topLineNumber();
+ unsigned columnNumber = stackTrace->topColumnNumber();
+ return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move(stackTrace), scriptId));
+}
+
SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId)
: m_url(url)
, m_lineNumber(lineNumber)
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/SourceLocation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698