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

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

Issue 2272613003: binding: Retires ExceptionState::throwIfNeeded(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Synced. Created 4 years, 3 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 19 matching lines...) Expand all
30 30
31 #include "bindings/core/v8/ExceptionState.h" 31 #include "bindings/core/v8/ExceptionState.h"
32 32
33 #include "bindings/core/v8/ExceptionMessages.h" 33 #include "bindings/core/v8/ExceptionMessages.h"
34 #include "bindings/core/v8/ScriptPromiseResolver.h" 34 #include "bindings/core/v8/ScriptPromiseResolver.h"
35 #include "bindings/core/v8/V8ThrowException.h" 35 #include "bindings/core/v8/V8ThrowException.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 37
38 namespace blink { 38 namespace blink {
39 39
40 void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& me ssage)
41 {
42 // SecurityError is thrown via ::throwSecurityError, and _careful_ considera tion must be given to the data exposed to JavaScript via the 'sanitizedMessage'.
43 DCHECK(ec != SecurityError);
44
45 const String& processedMessage = addExceptionContext(message);
46 setException(ec, processedMessage, V8ThrowException::createDOMException(m_is olate, ec, processedMessage));
47 }
48
49 void ExceptionState::throwRangeError(const String& message)
50 {
51 setException(V8RangeError, message, V8ThrowException::createRangeError(m_iso late, addExceptionContext(message)));
52 }
53
54 void ExceptionState::throwSecurityError(const String& sanitizedMessage, const St ring& unsanitizedMessage)
55 {
56 const String& finalSanitized = addExceptionContext(sanitizedMessage);
57 const String& finalUnsanitized = addExceptionContext(unsanitizedMessage);
58 setException(SecurityError, finalSanitized, V8ThrowException::createDOMExcep tion(m_isolate, SecurityError, finalSanitized, finalUnsanitized));
59 }
60
61 void ExceptionState::throwTypeError(const String& message)
62 {
63 setException(V8TypeError, message, V8ThrowException::createTypeError(m_isola te, addExceptionContext(message)));
64 }
65
66 void ExceptionState::rethrowV8Exception(v8::Local<v8::Value> value)
67 {
68 setException(kRethrownException, String(), value);
69 }
70
40 void ExceptionState::clearException() 71 void ExceptionState::clearException()
41 { 72 {
42 m_code = 0; 73 m_code = 0;
74 m_message = String();
43 m_exception.clear(); 75 m_exception.clear();
44 } 76 }
45 77
46 ScriptPromise ExceptionState::reject(ScriptState* scriptState) 78 ScriptPromise ExceptionState::reject(ScriptState* scriptState)
47 { 79 {
48 ScriptPromise promise = ScriptPromise::reject(scriptState, m_exception.newLo cal(scriptState->isolate())); 80 ScriptPromise promise = ScriptPromise::reject(scriptState, getException());
49 clearException(); 81 clearException();
50 return promise; 82 return promise;
51 } 83 }
52 84
53 void ExceptionState::reject(ScriptPromiseResolver* resolver) 85 void ExceptionState::reject(ScriptPromiseResolver* resolver)
54 { 86 {
55 resolver->reject(m_exception.newLocal(resolver->getScriptState()->isolate()) ); 87 resolver->reject(getException());
56 clearException(); 88 clearException();
57 } 89 }
58 90
59 void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& me ssage) 91 void ExceptionState::setException(ExceptionCode ec, const String& message, v8::L ocal<v8::Value> exception)
60 { 92 {
61 ASSERT(ec); 93 CHECK(ec);
62 ASSERT(m_isolate);
63
64 // SecurityError is thrown via ::throwSecurityError, and _careful_ considera tion must be given to the data exposed to JavaScript via the 'sanitizedMessage'.
65 ASSERT(ec != SecurityError);
66 94
67 m_code = ec; 95 m_code = ec;
68 String processedMessage = addExceptionContext(message); 96 m_message = message;
69 m_message = processedMessage;
70 setException(V8ThrowException::createDOMException(m_isolate, ec, processedMe ssage));
71 }
72
73 void ExceptionState::throwSecurityError(const String& sanitizedMessage, const St ring& unsanitizedMessage)
74 {
75 ASSERT(m_isolate);
76 m_code = SecurityError;
77 String finalSanitized = addExceptionContext(sanitizedMessage);
78 m_message = finalSanitized;
79 String finalUnsanitized = addExceptionContext(unsanitizedMessage);
80
81 setException(V8ThrowException::createDOMException(m_isolate, SecurityError, finalSanitized, finalUnsanitized));
82 }
83
84 void ExceptionState::setException(v8::Local<v8::Value> exception)
85 {
86 // FIXME: Assert that exception is not empty?
87 if (exception.IsEmpty()) { 97 if (exception.IsEmpty()) {
88 clearException(); 98 m_exception.clear();
89 return; 99 } else {
100 DCHECK(m_isolate);
101 m_exception.set(m_isolate, exception);
90 } 102 }
91
92 m_exception.set(m_isolate, exception);
93 }
94
95 void ExceptionState::throwException()
96 {
97 ASSERT(!m_exception.isEmpty());
98 V8ThrowException::throwException(m_isolate, m_exception.newLocal(m_isolate)) ;
99 }
100
101 void ExceptionState::throwTypeError(const String& message)
102 {
103 ASSERT(m_isolate);
104 m_code = V8TypeError;
105 m_message = message;
106 setException(V8ThrowException::createTypeError(m_isolate, addExceptionContex t(message)));
107 }
108
109 void ExceptionState::throwRangeError(const String& message)
110 {
111 ASSERT(m_isolate);
112 m_code = V8RangeError;
113 m_message = message;
114 setException(V8ThrowException::createRangeError(m_isolate, addExceptionConte xt(message)));
115 }
116
117 void NonThrowableExceptionState::throwDOMException(const ExceptionCode& ec, cons t String& message)
118 {
119 ASSERT_NOT_REACHED();
120 m_code = ec;
121 m_message = message;
122 }
123
124 void NonThrowableExceptionState::throwTypeError(const String& message)
125 {
126 ASSERT_NOT_REACHED();
127 m_code = V8TypeError;
128 m_message = message;
129 }
130
131 void NonThrowableExceptionState::throwSecurityError(const String& sanitizedMessa ge, const String&)
132 {
133 ASSERT_NOT_REACHED();
134 m_code = SecurityError;
135 m_message = sanitizedMessage;
136 }
137
138 void NonThrowableExceptionState::throwRangeError(const String& message)
139 {
140 ASSERT_NOT_REACHED();
141 m_code = V8RangeError;
142 m_message = message;
143 }
144
145 void TrackExceptionState::throwDOMException(const ExceptionCode& ec, const Strin g& message)
146 {
147 m_code = ec;
148 m_message = message;
149 }
150
151 void TrackExceptionState::throwTypeError(const String& message)
152 {
153 m_code = V8TypeError;
154 m_message = message;
155 }
156
157 void TrackExceptionState::throwSecurityError(const String& sanitizedMessage, con st String&)
158 {
159 m_code = SecurityError;
160 m_message = sanitizedMessage;
161 }
162
163 void TrackExceptionState::throwRangeError(const String& message)
164 {
165 m_code = V8RangeError;
166 m_message = message;
167 } 103 }
168 104
169 String ExceptionState::addExceptionContext(const String& message) const 105 String ExceptionState::addExceptionContext(const String& message) const
170 { 106 {
171 if (message.isEmpty()) 107 if (message.isEmpty())
172 return message; 108 return message;
173 109
174 String processedMessage = message; 110 String processedMessage = message;
175 if (propertyName() && interfaceName() && m_context != UnknownContext) { 111 if (propertyName() && interfaceName() && m_context != UnknownContext) {
176 if (m_context == DeletionContext) 112 if (m_context == DeletionContext)
(...skipping 12 matching lines...) Expand all
189 else if (m_context == IndexedDeletionContext) 125 else if (m_context == IndexedDeletionContext)
190 processedMessage = ExceptionMessages::failedToDeleteIndexed(interfac eName(), message); 126 processedMessage = ExceptionMessages::failedToDeleteIndexed(interfac eName(), message);
191 else if (m_context == IndexedGetterContext) 127 else if (m_context == IndexedGetterContext)
192 processedMessage = ExceptionMessages::failedToGetIndexed(interfaceNa me(), message); 128 processedMessage = ExceptionMessages::failedToGetIndexed(interfaceNa me(), message);
193 else if (m_context == IndexedSetterContext) 129 else if (m_context == IndexedSetterContext)
194 processedMessage = ExceptionMessages::failedToSetIndexed(interfaceNa me(), message); 130 processedMessage = ExceptionMessages::failedToSetIndexed(interfaceNa me(), message);
195 } 131 }
196 return processedMessage; 132 return processedMessage;
197 } 133 }
198 134
135 void NonThrowableExceptionState::throwDOMException(const ExceptionCode& ec, cons t String& message)
136 {
137 NOTREACHED();
138 }
139
140 void NonThrowableExceptionState::throwRangeError(const String& message)
141 {
142 NOTREACHED();
143 }
144
145 void NonThrowableExceptionState::throwSecurityError(const String& sanitizedMessa ge, const String&)
146 {
147 NOTREACHED();
148 }
149
150 void NonThrowableExceptionState::throwTypeError(const String& message)
151 {
152 NOTREACHED();
153 }
154
155 void NonThrowableExceptionState::rethrowV8Exception(v8::Local<v8::Value>)
156 {
157 NOTREACHED();
158 }
159
160 void TrackExceptionState::throwDOMException(const ExceptionCode& ec, const Strin g& message)
161 {
162 setException(ec, message, v8::Local<v8::Value>());
163 }
164
165 void TrackExceptionState::throwRangeError(const String& message)
166 {
167 setException(V8RangeError, message, v8::Local<v8::Value>());
168 }
169
170 void TrackExceptionState::throwSecurityError(const String& sanitizedMessage, con st String&)
171 {
172 setException(SecurityError, sanitizedMessage, v8::Local<v8::Value>());
173 }
174
175 void TrackExceptionState::throwTypeError(const String& message)
176 {
177 setException(V8TypeError, message, v8::Local<v8::Value>());
178 }
179
180 void TrackExceptionState::rethrowV8Exception(v8::Local<v8::Value>)
181 {
182 setException(kRethrownException, String(), v8::Local<v8::Value>());
183 }
184
199 } // namespace blink 185 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698