OLD | NEW |
| (Empty) |
1 // Copyright 2008, Google Inc. | |
2 // 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 // Javascript exception abstraction | |
31 | |
32 #ifndef ExceptionContext_h | |
33 #define ExceptionContext_h | |
34 | |
35 #include <wtf/Noncopyable.h> | |
36 #include "ScriptController.h" | |
37 | |
38 #if USE(JSC) | |
39 namespace JSC { | |
40 class ExecState; | |
41 } | |
42 #endif | |
43 | |
44 | |
45 namespace WebCore { | |
46 | |
47 class Node; | |
48 #if USE(V8) | |
49 class ExceptionCatcher; | |
50 #endif | |
51 | |
52 // 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 | |
54 // by the ExceptionCatcher. | |
55 class ExceptionContext : Noncopyable { | |
56 public: | |
57 ExceptionContext(Node*); | |
58 #if USE(V8) | |
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() {} | |
65 | |
66 bool hadException(); | |
67 JSException exception() const; | |
68 | |
69 // Returns a non-exception code object. | |
70 static JSException noException(); | |
71 | |
72 private: | |
73 #if USE(V8) | |
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 }; | |
83 | |
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 | |
101 | |
102 #endif // !defined(ExceptionContext_h) | |
OLD | NEW |