| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 virtual void throwSecurityError(const String& sanitizedMessage, const String
& unsanitizedMessage = String()); | 79 virtual void throwSecurityError(const String& sanitizedMessage, const String
& unsanitizedMessage = String()); |
| 80 | 80 |
| 81 bool hadException() const { return !m_exception.isEmpty() || m_code; } | 81 bool hadException() const { return !m_exception.isEmpty() || m_code; } |
| 82 void clearException(); | 82 void clearException(); |
| 83 | 83 |
| 84 ExceptionCode code() const { return m_code; } | 84 ExceptionCode code() const { return m_code; } |
| 85 const String& message() const { return m_message; } | 85 const String& message() const { return m_message; } |
| 86 | 86 |
| 87 bool throwIfNeeded() | 87 bool throwIfNeeded() |
| 88 { | 88 { |
| 89 if (m_exception.isEmpty()) { | 89 if (!hadException()) |
| 90 if (!m_code) | 90 return false; |
| 91 return false; | 91 throwException(); |
| 92 throwDOMException(m_code, String()); // FIXME: Do we ever hit this?
If so, where and why? | |
| 93 } | |
| 94 | |
| 95 V8ThrowException::throwError(m_exception.newLocal(m_isolate), m_isolate)
; | |
| 96 return true; | 92 return true; |
| 97 } | 93 } |
| 98 | 94 |
| 99 Context context() const { return m_context; } | 95 Context context() const { return m_context; } |
| 100 const char* propertyName() const { return m_propertyName; } | 96 const char* propertyName() const { return m_propertyName; } |
| 101 const char* interfaceName() const { return m_interfaceName; } | 97 const char* interfaceName() const { return m_interfaceName; } |
| 102 | 98 |
| 103 void rethrowV8Exception(v8::Handle<v8::Value> value) | 99 void rethrowV8Exception(v8::Handle<v8::Value> value) |
| 104 { | 100 { |
| 105 setException(value); | 101 setException(value); |
| 106 } | 102 } |
| 107 | 103 |
| 108 protected: | 104 protected: |
| 109 ExceptionCode m_code; | 105 ExceptionCode m_code; |
| 110 Context m_context; | 106 Context m_context; |
| 111 String m_message; | 107 String m_message; |
| 112 const char* m_propertyName; | 108 const char* m_propertyName; |
| 113 const char* m_interfaceName; | 109 const char* m_interfaceName; |
| 114 | 110 |
| 115 private: | 111 private: |
| 116 void setException(v8::Handle<v8::Value>); | 112 void setException(v8::Handle<v8::Value>); |
| 113 void throwException(); |
| 117 | 114 |
| 118 String addExceptionContext(const String&) const; | 115 String addExceptionContext(const String&) const; |
| 119 | 116 |
| 120 ScopedPersistent<v8::Value> m_exception; | 117 ScopedPersistent<v8::Value> m_exception; |
| 121 v8::Handle<v8::Object> m_creationContext; | 118 v8::Handle<v8::Object> m_creationContext; |
| 122 v8::Isolate* m_isolate; | 119 v8::Isolate* m_isolate; |
| 123 }; | 120 }; |
| 124 | 121 |
| 125 // Used if exceptions can/should not be directly thrown. | 122 // Used if exceptions can/should not be directly thrown. |
| 126 class NonThrowableExceptionState FINAL : public ExceptionState { | 123 class NonThrowableExceptionState FINAL : public ExceptionState { |
| 127 public: | 124 public: |
| 128 NonThrowableExceptionState(): ExceptionState(ExceptionState::UnknownContext,
0, 0, v8::Handle<v8::Object>(), v8::Isolate::GetCurrent()) { } | 125 NonThrowableExceptionState(): ExceptionState(ExceptionState::UnknownContext,
0, 0, v8::Handle<v8::Object>(), v8::Isolate::GetCurrent()) { } |
| 129 virtual void throwDOMException(const ExceptionCode&, const String& message)
OVERRIDE; | 126 virtual void throwDOMException(const ExceptionCode&, const String& message)
OVERRIDE; |
| 130 virtual void throwTypeError(const String& message = String()) OVERRIDE; | 127 virtual void throwTypeError(const String& message = String()) OVERRIDE; |
| 131 virtual void throwSecurityError(const String& sanitizedMessage, const String
& unsanitizedMessage = String()) OVERRIDE; | 128 virtual void throwSecurityError(const String& sanitizedMessage, const String
& unsanitizedMessage = String()) OVERRIDE; |
| 132 }; | 129 }; |
| 133 | 130 |
| 134 // Used if any exceptions thrown are ignorable. | 131 // Used if any exceptions thrown are ignorable. |
| 135 class TrackExceptionState FINAL : public ExceptionState { | 132 class TrackExceptionState FINAL : public ExceptionState { |
| 136 public: | 133 public: |
| 137 TrackExceptionState(): ExceptionState(ExceptionState::UnknownContext, 0, 0,
v8::Handle<v8::Object>(), v8::Isolate::GetCurrent()) { } | 134 TrackExceptionState(): ExceptionState(ExceptionState::UnknownContext, 0, 0,
v8::Handle<v8::Object>(), v8::Isolate::GetCurrent()) { } |
| 138 virtual void throwDOMException(const ExceptionCode&, const String& message)
OVERRIDE; | 135 virtual void throwDOMException(const ExceptionCode&, const String& message)
OVERRIDE; |
| 139 virtual void throwTypeError(const String& message = String()) OVERRIDE; | 136 virtual void throwTypeError(const String& message = String()) OVERRIDE; |
| 140 virtual void throwSecurityError(const String& sanitizedMessage, const String
& unsanitizedMessage = String()) OVERRIDE; | 137 virtual void throwSecurityError(const String& sanitizedMessage, const String
& unsanitizedMessage = String()) OVERRIDE; |
| 141 }; | 138 }; |
| 142 | 139 |
| 143 } // namespace WebCore | 140 } // namespace WebCore |
| 144 | 141 |
| 145 #endif // ExceptionState_h | 142 #endif // ExceptionState_h |
| OLD | NEW |