OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 #include "config.h" |
| 31 #include "ExceptionContext.h" |
| 32 |
| 33 #include "Node.h" |
| 34 |
| 35 namespace WebCore { |
| 36 |
| 37 ExceptionContext::ExceptionContext() |
| 38 : m_exceptionCatcher(0) |
| 39 , m_exception() |
| 40 { |
| 41 } |
| 42 |
| 43 ExceptionContext::~ExceptionContext() |
| 44 { |
| 45 } |
| 46 |
| 47 void ExceptionContext::setExceptionCatcher(ExceptionCatcher* exceptionCatcher) |
| 48 { |
| 49 if (m_exceptionCatcher && exceptionCatcher) |
| 50 m_exceptionCatcher->detachContext(); |
| 51 |
| 52 m_exceptionCatcher = exceptionCatcher; |
| 53 } |
| 54 |
| 55 bool ExceptionContext::hadException() |
| 56 { |
| 57 if (m_exceptionCatcher) |
| 58 m_exceptionCatcher->updateContext(); |
| 59 |
| 60 return !m_exception.IsEmpty(); |
| 61 } |
| 62 |
| 63 ExceptionContext* ExceptionContext::createFromNode(Node*) |
| 64 { |
| 65 // Unlike JSC, which stores exceptions in ExecState that is accessible from |
| 66 // ScriptController that is retrievable from Node*, V8 uses static chain of |
| 67 // handlers (encapsulated as v8::TryCatch and here as ExceptionCatcher) |
| 68 // to track exceptions, so it has no need for Node*. |
| 69 return new ExceptionContext(); |
| 70 } |
| 71 |
| 72 JSException ExceptionContext::NoException() |
| 73 { |
| 74 return v8::Local<v8::Value>(); |
| 75 } |
| 76 |
| 77 ExceptionCatcher::ExceptionCatcher(ExceptionContext* exceptionContext) |
| 78 : m_catcher() |
| 79 , m_context(exceptionContext) |
| 80 { |
| 81 exceptionContext->setExceptionCatcher(this); |
| 82 } |
| 83 |
| 84 void ExceptionCatcher::detachContext() |
| 85 { |
| 86 m_context = 0; |
| 87 } |
| 88 |
| 89 void ExceptionCatcher::updateContext() |
| 90 { |
| 91 ASSERT(m_context); |
| 92 |
| 93 if (m_catcher.HasCaught()) |
| 94 m_context->setException(m_catcher.Exception()); |
| 95 else |
| 96 m_context->setException(ExceptionContext::NoException()); |
| 97 } |
| 98 |
| 99 ExceptionCatcher::~ExceptionCatcher() |
| 100 { |
| 101 if (!m_context) |
| 102 return; |
| 103 |
| 104 updateContext(); |
| 105 m_context->setExceptionCatcher(0); |
| 106 } |
| 107 |
| 108 } // namespace WebCore |
OLD | NEW |