OLD | NEW |
1 // Copyright 2008, Google Inc. | 1 // Copyright 2008, Google Inc. |
2 // All rights reserved. | 2 // 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 14 matching lines...) Expand all Loading... |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // Javascript exception abstraction | 30 // Javascript exception abstraction |
31 | 31 |
32 #ifndef ExceptionContext_h | 32 #ifndef ExceptionContext_h |
33 #define ExceptionContext_h | 33 #define ExceptionContext_h |
34 | 34 |
| 35 #include "ExceptionContextData.h" |
35 #include <wtf/Noncopyable.h> | 36 #include <wtf/Noncopyable.h> |
36 #include "ScriptController.h" | |
37 | |
38 #if USE(JSC) | |
39 namespace JSC { | |
40 class ExecState; | |
41 } | |
42 #endif | |
43 | |
44 | 37 |
45 namespace WebCore { | 38 namespace WebCore { |
46 | 39 |
47 class Node; | 40 class Node; |
48 #if USE(V8) | |
49 class ExceptionCatcher; | |
50 #endif | |
51 | 41 |
52 // Provides context of an exception. This class is an abstraction of JSC's | 42 // Provides context of an exception. This class is an abstraction of JSC's |
53 // ExecState. In V8, its purpose is to carry along the exceptions captured | 43 // ExecState. In V8, it carries an explicitly set exception. |
54 // by the ExceptionCatcher. | |
55 class ExceptionContext : Noncopyable { | 44 class ExceptionContext : Noncopyable { |
56 public: | 45 public: |
57 ExceptionContext(Node*); | 46 ExceptionContext(Node* node); |
58 #if USE(V8) | 47 ExceptionContext(ExceptionContextData data) : m_data(data) {} |
59 ExceptionContext(); | |
60 #elif USE(JSC) | |
61 ExceptionContext(JSC::ExecState* exec) : m_exec(exec) {} | |
62 JSC::ExecState* exec() const { return m_exec; } | |
63 #endif | |
64 ~ExceptionContext() {} | 48 ~ExceptionContext() {} |
65 | 49 |
66 bool hadException(); | 50 bool hadException(); |
67 JSException exception() const; | 51 ExceptionContextData data() const { return m_data; } |
68 | 52 void setData(ExceptionContextData data) { m_data = data; } |
69 // Returns a non-exception code object. | |
70 static JSException noException(); | |
71 | 53 |
72 private: | 54 private: |
73 #if USE(V8) | 55 ExceptionContextData m_data; |
74 friend class ExceptionCatcher; | |
75 void setException(JSException exception) { m_exception = exception; } | |
76 void setExceptionCatcher(ExceptionCatcher*); | |
77 JSException m_exception; | |
78 ExceptionCatcher* m_exceptionCatcher; | |
79 #elif USE(JSC) | |
80 JSC::ExecState* m_exec; | |
81 #endif | |
82 }; | 56 }; |
83 | 57 |
84 #if USE(V8) | |
85 // A wrapper around v8::TryCatch helper in order to facilitate updating | |
86 // ExceptionContext with the latest exceptions that may have occurred. | |
87 class ExceptionCatcher { | |
88 public: | |
89 ExceptionCatcher(ExceptionContext*); | |
90 ~ExceptionCatcher(); | |
91 void updateContext(); | |
92 void detachContext(); | |
93 | |
94 private: | |
95 ExceptionContext* m_context; | |
96 v8::TryCatch m_catcher; | |
97 }; | |
98 #endif | |
99 | |
100 } // namespace WebCore | 58 } // namespace WebCore |
101 | 59 |
102 #endif // !defined(ExceptionContext_h) | 60 #endif // ExceptionContext_h |
OLD | NEW |