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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& me
ssage) | 46 void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& me
ssage) |
47 { | 47 { |
48 ASSERT(ec); | 48 ASSERT(ec); |
49 ASSERT(m_isolate); | 49 ASSERT(m_isolate); |
50 | 50 |
51 // SecurityError is thrown via ::throwSecurityError, and _careful_ considera
tion must be given to the data exposed to JavaScript via the 'sanitizedMessage'. | 51 // SecurityError is thrown via ::throwSecurityError, and _careful_ considera
tion must be given to the data exposed to JavaScript via the 'sanitizedMessage'. |
52 ASSERT(ec != SecurityError); | 52 ASSERT(ec != SecurityError); |
53 | 53 |
54 String processedMessage = message; | |
55 if (propertyName() && interfaceName() && m_context != UnknownContext) { | |
56 if (m_context == DeletionContext) | |
57 processedMessage = ExceptionMessages::failedToDelete(propertyName(),
interfaceName(), message); | |
58 else if (m_context == ExecutionContext) | |
59 processedMessage = ExceptionMessages::failedToExecute(propertyName()
, interfaceName(), message); | |
60 else if (m_context == GetterContext) | |
61 processedMessage = ExceptionMessages::failedToGet(propertyName(), in
terfaceName(), message); | |
62 else if (m_context == SetterContext) | |
63 processedMessage = ExceptionMessages::failedToSet(propertyName(), in
terfaceName(), message); | |
64 } else if (!propertyName() && interfaceName() && m_context == ConstructionCo
ntext) { | |
65 processedMessage = ExceptionMessages::failedToConstruct(interfaceName(),
message); | |
66 } | |
67 | |
68 m_code = ec; | 54 m_code = ec; |
| 55 String processedMessage = addExceptionContext(message); |
69 setException(V8ThrowException::createDOMException(ec, processedMessage, m_cr
eationContext, m_isolate)); | 56 setException(V8ThrowException::createDOMException(ec, processedMessage, m_cr
eationContext, m_isolate)); |
70 } | 57 } |
71 | 58 |
72 void ExceptionState::throwSecurityError(const String& sanitizedMessage, const St
ring& unsanitizedMessage) | 59 void ExceptionState::throwSecurityError(const String& sanitizedMessage, const St
ring& unsanitizedMessage) |
73 { | 60 { |
74 ASSERT(m_isolate); | 61 ASSERT(m_isolate); |
75 m_code = SecurityError; | 62 m_code = SecurityError; |
76 setException(V8ThrowException::createDOMException(SecurityError, sanitizedMe
ssage, unsanitizedMessage, m_creationContext, m_isolate)); | 63 String finalSanitized = addExceptionContext(sanitizedMessage); |
| 64 String finalUnsanitized = addExceptionContext(unsanitizedMessage); |
| 65 setException(V8ThrowException::createDOMException(SecurityError, finalSaniti
zed, finalUnsanitized, m_creationContext, m_isolate)); |
77 } | 66 } |
78 | 67 |
79 void ExceptionState::setException(v8::Handle<v8::Value> exception) | 68 void ExceptionState::setException(v8::Handle<v8::Value> exception) |
80 { | 69 { |
81 // FIXME: Assert that exception is not empty? | 70 // FIXME: Assert that exception is not empty? |
82 if (exception.IsEmpty()) { | 71 if (exception.IsEmpty()) { |
83 clearException(); | 72 clearException(); |
84 return; | 73 return; |
85 } | 74 } |
86 | 75 |
(...skipping 15 matching lines...) Expand all Loading... |
102 void TrackExceptionState::throwTypeError(const String&) | 91 void TrackExceptionState::throwTypeError(const String&) |
103 { | 92 { |
104 m_code = TypeError; | 93 m_code = TypeError; |
105 } | 94 } |
106 | 95 |
107 void TrackExceptionState::throwSecurityError(const String&, const String&) | 96 void TrackExceptionState::throwSecurityError(const String&, const String&) |
108 { | 97 { |
109 m_code = SecurityError; | 98 m_code = SecurityError; |
110 } | 99 } |
111 | 100 |
| 101 String ExceptionState::addExceptionContext(const String& message) const |
| 102 { |
| 103 if (message.isEmpty()) |
| 104 return message; |
| 105 |
| 106 String processedMessage = message; |
| 107 if (propertyName() && interfaceName() && m_context != UnknownContext) { |
| 108 if (m_context == DeletionContext) |
| 109 processedMessage = ExceptionMessages::failedToDelete(propertyName(),
interfaceName(), message); |
| 110 else if (m_context == ExecutionContext) |
| 111 processedMessage = ExceptionMessages::failedToExecute(propertyName()
, interfaceName(), message); |
| 112 else if (m_context == GetterContext) |
| 113 processedMessage = ExceptionMessages::failedToGet(propertyName(), in
terfaceName(), message); |
| 114 else if (m_context == SetterContext) |
| 115 processedMessage = ExceptionMessages::failedToSet(propertyName(), in
terfaceName(), message); |
| 116 } else if (!propertyName() && interfaceName() && m_context == ConstructionCo
ntext) { |
| 117 processedMessage = ExceptionMessages::failedToConstruct(interfaceName(),
message); |
| 118 } |
| 119 return processedMessage; |
| 120 } |
| 121 |
112 } // namespace WebCore | 122 } // namespace WebCore |
OLD | NEW |