Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef ExceptionState_h | |
| 32 #define ExceptionState_h | |
| 33 | |
| 34 #include "bindings/v8/V8ThrowException.h" | |
| 35 #include "wtf/Noncopyable.h" | |
| 36 #include <v8.h> | |
| 37 | |
| 38 namespace WebCore { | |
| 39 | |
| 40 typedef int ExceptionCode; | |
| 41 | |
| 42 class ExceptionState { | |
| 43 WTF_MAKE_NONCOPYABLE(ExceptionState); | |
| 44 public: | |
| 45 explicit ExceptionState(v8::Isolate* isolate) | |
| 46 : m_code(0) | |
| 47 , m_exceptionThrown(false) | |
| 48 , m_isolate(isolate) { } | |
| 49 | |
| 50 virtual void throwDOMException(const ExceptionCode& ec, const char* message = 0) | |
|
haraken
2013/07/01 23:55:05
You might want to put the method in a cpp file, si
arv (Not doing code reviews)
2013/07/09 23:41:04
Done.
| |
| 51 { | |
| 52 if (m_exceptionThrown) | |
| 53 return; | |
| 54 V8ThrowException::setDOMException(ec, message, m_isolate); | |
| 55 m_exceptionThrown = true; | |
| 56 } | |
| 57 | |
| 58 // FIXME: Add more and consolidate | |
| 59 // void throwDOMException(const ExceptionCode&, const String& message) | |
| 60 // void throwDOMException(const ExceptionCode&, const String& message, const String& descriptionForInspector) | |
| 61 // void throwTypeError() | |
| 62 // void throwTypeError(const String& message) | |
| 63 // void throwTypeError(const String& message, const String& descriptionForIn spector) | |
| 64 | |
| 65 bool hadException() const { return m_exceptionThrown || m_code; } | |
| 66 | |
| 67 bool throwIfNeeded() | |
| 68 { | |
| 69 if (m_code) { | |
|
arv (Not doing code reviews)
2013/07/01 22:29:31
The idea is that all the uses would do throwDOMExc
| |
| 70 throwDOMException(m_code); | |
| 71 return true; | |
| 72 } | |
| 73 return m_exceptionThrown; | |
| 74 } | |
| 75 | |
| 76 // FIXME: Remove the rest of the public methods/operators once the transitio n is done. | |
| 77 typedef void* ExceptionState::*UnspecifiedBoolType; | |
| 78 operator UnspecifiedBoolType*() const | |
| 79 { | |
| 80 return m_code ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0; | |
| 81 } | |
| 82 | |
| 83 operator ExceptionCode& () { return m_code; } | |
| 84 | |
| 85 ExceptionState& operator=(const ExceptionCode& ec) | |
| 86 { | |
| 87 throwDOMException(ec); | |
| 88 return *this; | |
| 89 } | |
| 90 | |
| 91 protected: | |
| 92 ExceptionCode m_code; | |
|
arv (Not doing code reviews)
2013/07/01 22:29:31
During the transition we need both m_code and m_ex
| |
| 93 | |
| 94 private: | |
| 95 bool m_exceptionThrown; | |
| 96 v8::Isolate* m_isolate; | |
| 97 }; | |
| 98 | |
| 99 } // namespace WebCore | |
| 100 | |
| 101 #endif // ExceptionState_h | |
| OLD | NEW |