| OLD | NEW |
| 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 Loading... |
| 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 |
| 40 void ExceptionState::clearException() | 66 void ExceptionState::clearException() |
| 41 { | 67 { |
| 42 m_code = 0; | 68 m_code = 0; |
| 69 m_message = String(); |
| 43 m_exception.clear(); | 70 m_exception.clear(); |
| 44 } | 71 } |
| 45 | 72 |
| 46 ScriptPromise ExceptionState::reject(ScriptState* scriptState) | 73 ScriptPromise ExceptionState::reject(ScriptState* scriptState) |
| 47 { | 74 { |
| 48 ScriptPromise promise = ScriptPromise::reject(scriptState, m_exception.newLo
cal(scriptState->isolate())); | 75 ScriptPromise promise = ScriptPromise::reject(scriptState, getException()); |
| 49 clearException(); | 76 clearException(); |
| 50 return promise; | 77 return promise; |
| 51 } | 78 } |
| 52 | 79 |
| 53 void ExceptionState::reject(ScriptPromiseResolver* resolver) | 80 void ExceptionState::reject(ScriptPromiseResolver* resolver) |
| 54 { | 81 { |
| 55 resolver->reject(m_exception.newLocal(resolver->getScriptState()->isolate())
); | 82 resolver->reject(getException()); |
| 56 clearException(); | 83 clearException(); |
| 57 } | 84 } |
| 58 | 85 |
| 59 void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& me
ssage) | 86 void ExceptionState::setException(ExceptionCode ec, const String& message, v8::L
ocal<v8::Value> exception) |
| 60 { | 87 { |
| 61 ASSERT(ec); | 88 CHECK(ec); |
| 62 ASSERT(m_isolate); | 89 CHECK(!exception.IsEmpty()); |
| 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 | 90 |
| 67 m_code = ec; | 91 m_code = ec; |
| 68 String processedMessage = addExceptionContext(message); | 92 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()) { | |
| 88 clearException(); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 m_exception.set(m_isolate, exception); | 93 m_exception.set(m_isolate, exception); |
| 93 } | 94 } |
| 94 | 95 |
| 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 } | |
| 168 | |
| 169 String ExceptionState::addExceptionContext(const String& message) const | 96 String ExceptionState::addExceptionContext(const String& message) const |
| 170 { | 97 { |
| 171 if (message.isEmpty()) | 98 if (message.isEmpty()) |
| 172 return message; | 99 return message; |
| 173 | 100 |
| 174 String processedMessage = message; | 101 String processedMessage = message; |
| 175 if (propertyName() && interfaceName() && m_context != UnknownContext) { | 102 if (propertyName() && interfaceName() && m_context != UnknownContext) { |
| 176 if (m_context == DeletionContext) | 103 if (m_context == DeletionContext) |
| 177 processedMessage = ExceptionMessages::failedToDelete(propertyName(),
interfaceName(), message); | 104 processedMessage = ExceptionMessages::failedToDelete(propertyName(),
interfaceName(), message); |
| 178 else if (m_context == ExecutionContext) | 105 else if (m_context == ExecutionContext) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 189 else if (m_context == IndexedDeletionContext) | 116 else if (m_context == IndexedDeletionContext) |
| 190 processedMessage = ExceptionMessages::failedToDeleteIndexed(interfac
eName(), message); | 117 processedMessage = ExceptionMessages::failedToDeleteIndexed(interfac
eName(), message); |
| 191 else if (m_context == IndexedGetterContext) | 118 else if (m_context == IndexedGetterContext) |
| 192 processedMessage = ExceptionMessages::failedToGetIndexed(interfaceNa
me(), message); | 119 processedMessage = ExceptionMessages::failedToGetIndexed(interfaceNa
me(), message); |
| 193 else if (m_context == IndexedSetterContext) | 120 else if (m_context == IndexedSetterContext) |
| 194 processedMessage = ExceptionMessages::failedToSetIndexed(interfaceNa
me(), message); | 121 processedMessage = ExceptionMessages::failedToSetIndexed(interfaceNa
me(), message); |
| 195 } | 122 } |
| 196 return processedMessage; | 123 return processedMessage; |
| 197 } | 124 } |
| 198 | 125 |
| 126 void NonThrowableExceptionState::throwDOMException(const ExceptionCode& ec, cons
t String& message) |
| 127 { |
| 128 NOTREACHED(); |
| 129 } |
| 130 |
| 131 void NonThrowableExceptionState::throwRangeError(const String& message) |
| 132 { |
| 133 NOTREACHED(); |
| 134 } |
| 135 |
| 136 void NonThrowableExceptionState::throwSecurityError(const String& sanitizedMessa
ge, const String&) |
| 137 { |
| 138 NOTREACHED(); |
| 139 } |
| 140 |
| 141 void NonThrowableExceptionState::throwTypeError(const String& message) |
| 142 { |
| 143 NOTREACHED(); |
| 144 } |
| 145 |
| 146 void TrackExceptionState::throwDOMException(const ExceptionCode& ec, const Strin
g& message) |
| 147 { |
| 148 setException(ec, message, v8::Null(isolate())); |
| 149 } |
| 150 |
| 151 void TrackExceptionState::throwRangeError(const String& message) |
| 152 { |
| 153 setException(V8RangeError, message, v8::Null(isolate())); |
| 154 } |
| 155 |
| 156 void TrackExceptionState::throwSecurityError(const String& sanitizedMessage, con
st String&) |
| 157 { |
| 158 setException(SecurityError, sanitizedMessage, v8::Null(isolate())); |
| 159 } |
| 160 |
| 161 void TrackExceptionState::throwTypeError(const String& message) |
| 162 { |
| 163 setException(V8TypeError, message, v8::Null(isolate())); |
| 164 } |
| 165 |
| 199 } // namespace blink | 166 } // namespace blink |
| OLD | NEW |