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

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

Issue 2010603002: Use SourceLocation when reporting runtime exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2004243002
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/core/v8/SourceLocation.h" 5 #include "bindings/core/v8/SourceLocation.h"
6 6
7 #include "bindings/core/v8/V8PerIsolateData.h" 7 #include "bindings/core/v8/V8PerIsolateData.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/ExecutionContext.h" 9 #include "core/dom/ExecutionContext.h"
10 #include "core/dom/ScriptableDocumentParser.h" 10 #include "core/dom/ScriptableDocumentParser.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 if (document->scriptableDocumentParser()->isParsingAtLineNumber()) 59 if (document->scriptableDocumentParser()->isParsingAtLineNumber())
60 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt(); 60 lineNumber = document->scriptableDocumentParser()->lineNumber(). oneBasedInt();
61 } 61 }
62 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace)); 62 return SourceLocation::create(document->url().getString(), lineNumber, 0 , std::move(stackTrace));
63 } 63 }
64 64
65 return SourceLocation::create(executionContext ? executionContext->url().get String() : "", 0, 0, std::move(stackTrace)); 65 return SourceLocation::create(executionContext ? executionContext->url().get String() : "", 0, 0, std::move(stackTrace));
66 } 66 }
67 67
68 // static 68 // static
69 PassOwnPtr<SourceLocation> SourceLocation::fromMessage(v8::Isolate* isolate, v8: :Local<v8::Message> message, ExecutionContext* executionContext)
70 {
71 v8::Local<v8::StackTrace> stack = message->GetStackTrace();
72
73 OwnPtr<V8StackTrace> stackTrace = nullptr;
74 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
75 if (data && data->threadDebugger())
76 stackTrace = data->threadDebugger()->debugger()->createStackTrace(stack) ;
77
78 int scriptId = message->GetScriptOrigin().ScriptID()->Value();
79 if (!stack.IsEmpty() && stack->GetFrameCount() > 0) {
80 int topScriptId = stack->GetFrame(0)->GetScriptId();
81 if (topScriptId == scriptId)
82 scriptId = 0;
83 }
84
85 unsigned lineNumber = message->GetLineNumber(isolate->GetCurrentContext()).F romMaybe(0);
86 unsigned columnNumber = message->GetStartColumn(isolate->GetCurrentContext() ).FromMaybe(-1) + 1;
haraken 2016/05/24 19:48:34 Use v8Call macros in V8BindingMacros.h.
dgozman 2016/05/24 23:13:22 Done.
87
88 if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty())
89 return adoptPtr(new SourceLocation(stackTrace->topSourceURL(), stackTrac e->topLineNumber(), stackTrace->topColumnNumber(), std::move(stackTrace), 0));
90
91 v8::Local<v8::Value> resourceName = message->GetScriptOrigin().ResourceName( );
92 String url = executionContext->url();
93 bool shouldUseDocumentURL = executionContext->isDocument() && (resourceName. IsEmpty() || !resourceName->IsString());
94 if (!shouldUseDocumentURL) {
95 V8StringResource<> v8ResourceName(resourceName);
haraken 2016/05/24 19:48:34 url = toCoreString(resourceName); will work.
dgozman 2016/05/24 23:13:22 Done. Used toCoreStringWithUndefinedOrNullCheck, s
96 if (v8ResourceName.prepare())
97 url = v8ResourceName;
98 }
99 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId));
100 }
101
102 // static
69 PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li neNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int script Id) 103 PassOwnPtr<SourceLocation> SourceLocation::create(const String& url, unsigned li neNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int script Id)
70 { 104 {
71 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId)); 105 return adoptPtr(new SourceLocation(url, lineNumber, columnNumber, std::move( stackTrace), scriptId));
72 } 106 }
73 107
74 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int scriptId) 108 SourceLocation::SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber, PassOwnPtr<V8StackTrace> stackTrace, int scriptId)
75 : m_url(url) 109 : m_url(url)
76 , m_lineNumber(lineNumber) 110 , m_lineNumber(lineNumber)
77 , m_columnNumber(columnNumber) 111 , m_columnNumber(columnNumber)
78 , m_stackTrace(std::move(stackTrace)) 112 , m_stackTrace(std::move(stackTrace))
(...skipping 19 matching lines...) Expand all
98 value->endDictionary(); 132 value->endDictionary();
99 value->endArray(); 133 value->endArray();
100 } 134 }
101 135
102 PassOwnPtr<SourceLocation> SourceLocation::clone() const 136 PassOwnPtr<SourceLocation> SourceLocation::clone() const
103 { 137 {
104 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId)); 138 return adoptPtr(new SourceLocation(m_url, m_lineNumber, m_columnNumber, m_st ackTrace ? m_stackTrace->clone() : nullptr, m_scriptId));
105 } 139 }
106 140
107 } // namespace blink 141 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698