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

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

Issue 2715073002: Devirtualize ExceptionState's helper throwing methods.
Patch Set: . Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ExceptionState.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bool ExceptionState::shouldThrow() const {
41 return true;
42 }
43
40 void ExceptionState::throwDOMException(ExceptionCode ec, const char* message) { 44 void ExceptionState::throwDOMException(ExceptionCode ec, const char* message) {
41 throwDOMException(ec, String(message)); 45 throwDOMException(ec, String(message));
42 } 46 }
43 47
44 void ExceptionState::throwRangeError(const char* message) { 48 void ExceptionState::throwRangeError(const char* message) {
45 throwRangeError(String(message)); 49 throwRangeError(String(message));
46 } 50 }
47 51
48 void ExceptionState::throwSecurityError(const char* sanitizedMessage, 52 void ExceptionState::throwSecurityError(const char* sanitizedMessage,
49 const char* unsanitizedMessage) { 53 const char* unsanitizedMessage) {
50 throwSecurityError(String(sanitizedMessage), String(unsanitizedMessage)); 54 throwSecurityError(String(sanitizedMessage), String(unsanitizedMessage));
51 } 55 }
52 56
53 void ExceptionState::throwTypeError(const char* message) { 57 void ExceptionState::throwTypeError(const char* message) {
54 throwTypeError(String(message)); 58 throwTypeError(String(message));
55 } 59 }
56 60
57 void ExceptionState::throwDOMException(ExceptionCode ec, 61 void ExceptionState::throwDOMException(ExceptionCode ec,
58 const String& message) { 62 const String& message) {
59 // SecurityError is thrown via ::throwSecurityError, and _careful_ 63 // SecurityError is thrown via ::throwSecurityError, and _careful_
60 // consideration must be given to the data exposed to JavaScript via the 64 // consideration must be given to the data exposed to JavaScript via the
61 // 'sanitizedMessage'. 65 // 'sanitizedMessage'.
62 DCHECK(ec != SecurityError); 66 DCHECK(ec != SecurityError);
63 67
68 if (!shouldThrow())
69 return;
70
64 const String& processedMessage = addExceptionContext(message); 71 const String& processedMessage = addExceptionContext(message);
65 setException(ec, processedMessage, V8ThrowException::createDOMException( 72 setException(ec, processedMessage, V8ThrowException::createDOMException(
66 m_isolate, ec, processedMessage)); 73 m_isolate, ec, processedMessage));
67 } 74 }
68 75
69 void ExceptionState::throwRangeError(const String& message) { 76 void ExceptionState::throwRangeError(const String& message) {
77 if (!shouldThrow())
78 return;
79
70 setException(V8RangeError, message, 80 setException(V8RangeError, message,
71 V8ThrowException::createRangeError( 81 V8ThrowException::createRangeError(
72 m_isolate, addExceptionContext(message))); 82 m_isolate, addExceptionContext(message)));
73 } 83 }
74 84
75 void ExceptionState::throwSecurityError(const String& sanitizedMessage, 85 void ExceptionState::throwSecurityError(const String& sanitizedMessage,
76 const String& unsanitizedMessage) { 86 const String& unsanitizedMessage) {
87 if (!shouldThrow())
88 return;
89
77 const String& finalSanitized = addExceptionContext(sanitizedMessage); 90 const String& finalSanitized = addExceptionContext(sanitizedMessage);
78 const String& finalUnsanitized = addExceptionContext(unsanitizedMessage); 91 const String& finalUnsanitized = addExceptionContext(unsanitizedMessage);
79 setException(SecurityError, finalSanitized, 92 setException(SecurityError, finalSanitized,
80 V8ThrowException::createDOMException( 93 V8ThrowException::createDOMException(
81 m_isolate, SecurityError, finalSanitized, finalUnsanitized)); 94 m_isolate, SecurityError, finalSanitized, finalUnsanitized));
82 } 95 }
83 96
84 void ExceptionState::throwTypeError(const String& message) { 97 void ExceptionState::throwTypeError(const String& message) {
98 if (!shouldThrow())
99 return;
100
85 setException(V8TypeError, message, 101 setException(V8TypeError, message,
86 V8ThrowException::createTypeError(m_isolate, 102 V8ThrowException::createTypeError(m_isolate,
87 addExceptionContext(message))); 103 addExceptionContext(message)));
88 } 104 }
89 105
90 void ExceptionState::rethrowV8Exception(v8::Local<v8::Value> value) { 106 void ExceptionState::rethrowV8Exception(v8::Local<v8::Value> value) {
107 if (!shouldThrow())
108 return;
109
91 setException(kRethrownException, String(), value); 110 setException(kRethrownException, String(), value);
92 } 111 }
93 112
94 void ExceptionState::clearException() { 113 void ExceptionState::clearException() {
95 m_code = 0; 114 m_code = 0;
96 m_message = String(); 115 m_message = String();
97 m_exception.clear(); 116 m_exception.clear();
98 } 117 }
99 118
100 ScriptPromise ExceptionState::reject(ScriptState* scriptState) { 119 ScriptPromise ExceptionState::reject(ScriptState* scriptState) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 : ExceptionState(nullptr, ExceptionState::UnknownContext, nullptr, nullptr), 184 : ExceptionState(nullptr, ExceptionState::UnknownContext, nullptr, nullptr),
166 m_file(""), 185 m_file(""),
167 m_line(0) {} 186 m_line(0) {}
168 187
169 NonThrowableExceptionState::NonThrowableExceptionState(const char* file, 188 NonThrowableExceptionState::NonThrowableExceptionState(const char* file,
170 int line) 189 int line)
171 : ExceptionState(nullptr, ExceptionState::UnknownContext, nullptr, nullptr), 190 : ExceptionState(nullptr, ExceptionState::UnknownContext, nullptr, nullptr),
172 m_file(file), 191 m_file(file),
173 m_line(line) {} 192 m_line(line) {}
174 193
175 void NonThrowableExceptionState::throwDOMException(ExceptionCode ec, 194 bool NonThrowableExceptionState::shouldThrow() const {
176 const String& message) { 195 DCHECK_AT(false, m_file, m_line) << "An exception should not be thrown.";
177 DCHECK_AT(false, m_file, m_line) << "DOMExeption should not be thrown."; 196 return false;
178 } 197 }
179 198
180 void NonThrowableExceptionState::throwRangeError(const String& message) { 199 bool DummyExceptionStateForTesting::shouldThrow() const {
181 DCHECK_AT(false, m_file, m_line) << "RangeError should not be thrown."; 200 // This class ignores all exceptions.
182 } 201 return false;
183
184 void NonThrowableExceptionState::throwSecurityError(
185 const String& sanitizedMessage,
186 const String&) {
187 DCHECK_AT(false, m_file, m_line) << "SecurityError should not be thrown.";
188 }
189
190 void NonThrowableExceptionState::throwTypeError(const String& message) {
191 DCHECK_AT(false, m_file, m_line) << "TypeError should not be thrown.";
192 }
193
194 void NonThrowableExceptionState::rethrowV8Exception(v8::Local<v8::Value>) {
195 DCHECK_AT(false, m_file, m_line) << "An exception should not be rethrown.";
196 }
197
198 void DummyExceptionStateForTesting::throwDOMException(ExceptionCode ec,
199 const String& message) {
200 setException(ec, message, v8::Local<v8::Value>());
201 }
202
203 void DummyExceptionStateForTesting::throwRangeError(const String& message) {
204 setException(V8RangeError, message, v8::Local<v8::Value>());
205 }
206
207 void DummyExceptionStateForTesting::throwSecurityError(
208 const String& sanitizedMessage,
209 const String&) {
210 setException(SecurityError, sanitizedMessage, v8::Local<v8::Value>());
211 }
212
213 void DummyExceptionStateForTesting::throwTypeError(const String& message) {
214 setException(V8TypeError, message, v8::Local<v8::Value>());
215 }
216
217 void DummyExceptionStateForTesting::rethrowV8Exception(v8::Local<v8::Value>) {
218 setException(kRethrownException, String(), v8::Local<v8::Value>());
219 } 202 }
220 203
221 } // namespace blink 204 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ExceptionState.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698