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

Side by Side Diff: third_party/WebKit/Source/core/events/ErrorEvent.h

Issue 2006893004: Store SourceLocation in ErrorEvent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2010603002
Patch Set: rebased Created 4 years, 6 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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef ErrorEvent_h 31 #ifndef ErrorEvent_h
32 #define ErrorEvent_h 32 #define ErrorEvent_h
33 33
34 #include "bindings/core/v8/DOMWrapperWorld.h" 34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/SourceLocation.h"
35 #include "core/events/ErrorEventInit.h" 36 #include "core/events/ErrorEventInit.h"
36 #include "core/events/Event.h" 37 #include "core/events/Event.h"
37 #include "wtf/RefPtr.h" 38 #include "wtf/RefPtr.h"
38 #include "wtf/text/WTFString.h" 39 #include "wtf/text/WTFString.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 class ErrorEvent final : public Event { 43 class ErrorEvent final : public Event {
43 DEFINE_WRAPPERTYPEINFO(); 44 DEFINE_WRAPPERTYPEINFO();
44 public: 45 public:
45 static ErrorEvent* create() 46 static ErrorEvent* create()
46 { 47 {
47 return new ErrorEvent; 48 return new ErrorEvent;
48 } 49 }
49 static ErrorEvent* create(const String& message, const String& fileName, uns igned lineNumber, unsigned columnNumber, DOMWrapperWorld* world) 50 static ErrorEvent* create(const String& message, PassOwnPtr<SourceLocation> location, DOMWrapperWorld* world)
50 { 51 {
51 return new ErrorEvent(message, fileName, lineNumber, columnNumber, world ); 52 return new ErrorEvent(message, std::move(location), world);
52 } 53 }
53 static ErrorEvent* create(const AtomicString& type, const ErrorEventInit& in itializer) 54 static ErrorEvent* create(const AtomicString& type, const ErrorEventInit& in itializer)
54 { 55 {
55 return new ErrorEvent(type, initializer); 56 return new ErrorEvent(type, initializer);
56 } 57 }
57 static ErrorEvent* createSanitizedError(DOMWrapperWorld* world) 58 static ErrorEvent* createSanitizedError(DOMWrapperWorld* world)
58 { 59 {
59 return new ErrorEvent("Script error.", String(), 0, 0, world); 60 return new ErrorEvent("Script error.", SourceLocation::create(String(), 0, 0, nullptr), world);
60 } 61 }
61 ~ErrorEvent() override; 62 ~ErrorEvent() override;
62 63
63 // As 'message' is exposed to JavaScript, never return unsanitizedMessage. 64 // As 'message' is exposed to JavaScript, never return unsanitizedMessage.
64 const String& message() const { return m_sanitizedMessage; } 65 const String& message() const { return m_sanitizedMessage; }
65 const String& filename() const { return m_fileName; } 66 const String& filename() const { return m_location->url(); }
66 unsigned lineno() const { return m_lineNumber; } 67 unsigned lineno() const { return m_location->lineNumber(); }
67 unsigned colno() const { return m_columnNumber; } 68 unsigned colno() const { return m_location->columnNumber(); }
68 ScriptValue error(ScriptState*) const; 69 ScriptValue error(ScriptState*) const;
69 70
70 // 'messageForConsole' is not exposed to JavaScript, and prefers 'm_unsaniti zedMessage'. 71 // 'messageForConsole' is not exposed to JavaScript, and prefers 'm_unsaniti zedMessage'.
71 const String& messageForConsole() const { return !m_unsanitizedMessage.isEmp ty() ? m_unsanitizedMessage : m_sanitizedMessage; } 72 const String& messageForConsole() const { return !m_unsanitizedMessage.isEmp ty() ? m_unsanitizedMessage : m_sanitizedMessage; }
73 SourceLocation* location() const { return m_location.get(); }
72 74
73 const AtomicString& interfaceName() const override; 75 const AtomicString& interfaceName() const override;
74 76
75 DOMWrapperWorld* world() const { return m_world.get(); } 77 DOMWrapperWorld* world() const { return m_world.get(); }
76 78
77 void setUnsanitizedMessage(const String&); 79 void setUnsanitizedMessage(const String&);
78 80
79 DECLARE_VIRTUAL_TRACE(); 81 DECLARE_VIRTUAL_TRACE();
80 82
81 private: 83 private:
82 ErrorEvent(); 84 ErrorEvent();
83 ErrorEvent(const String& message, const String& fileName, unsigned lineNumbe r, unsigned columnNumber, DOMWrapperWorld*); 85 ErrorEvent(const String& message, PassOwnPtr<SourceLocation>, DOMWrapperWorl d*);
84 ErrorEvent(const AtomicString&, const ErrorEventInit&); 86 ErrorEvent(const AtomicString&, const ErrorEventInit&);
85 87
86 String m_unsanitizedMessage; 88 String m_unsanitizedMessage;
87 String m_sanitizedMessage; 89 String m_sanitizedMessage;
88 String m_fileName; 90 OwnPtr<SourceLocation> m_location;
89 unsigned m_lineNumber;
90 unsigned m_columnNumber;
91 ScriptValue m_error; 91 ScriptValue m_error;
92 92
93 RefPtr<DOMWrapperWorld> m_world; 93 RefPtr<DOMWrapperWorld> m_world;
94 }; 94 };
95 95
96 } // namespace blink 96 } // namespace blink
97 97
98 #endif // ErrorEvent_h 98 #endif // ErrorEvent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698