| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 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 13 matching lines...) Expand all Loading... |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 #include "config.h" | 30 #include "config.h" |
| 31 | 31 |
| 32 #include "v8_nodefilter.h" | 32 #include "v8_nodefilter.h" |
| 33 #include "v8_proxy.h" | 33 #include "v8_proxy.h" |
| 34 #include "ExceptionContext.h" |
| 34 #include "NodeFilter.h" | 35 #include "NodeFilter.h" |
| 35 #include "Node.h" | 36 #include "Node.h" |
| 36 | 37 |
| 37 namespace WebCore { | 38 namespace WebCore { |
| 38 | 39 |
| 39 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter) { | 40 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter) { |
| 40 m_filter = v8::Persistent<v8::Value>::New(filter); | 41 m_filter = v8::Persistent<v8::Value>::New(filter); |
| 41 #ifndef NDEBUG | 42 #ifndef NDEBUG |
| 42 V8Proxy::RegisterGlobalHandle(NODE_FILTER, this, m_filter); | 43 V8Proxy::RegisterGlobalHandle(NODE_FILTER, this, m_filter); |
| 43 #endif | 44 #endif |
| 44 } | 45 } |
| 45 | 46 |
| 46 V8NodeFilterCondition::~V8NodeFilterCondition() { | 47 V8NodeFilterCondition::~V8NodeFilterCondition() { |
| 47 #ifndef NDEBUG | 48 #ifndef NDEBUG |
| 48 V8Proxy::UnregisterGlobalHandle(this, m_filter); | 49 V8Proxy::UnregisterGlobalHandle(this, m_filter); |
| 49 #endif | 50 #endif |
| 50 m_filter.Dispose(); | 51 m_filter.Dispose(); |
| 51 m_filter.Clear(); | 52 m_filter.Clear(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 short V8NodeFilterCondition::acceptNode(Node* node) const { | 55 short V8NodeFilterCondition::acceptNode(ExceptionContext* exception_context, |
| 56 Node* node) const { |
| 55 ASSERT(v8::Context::InContext()); | 57 ASSERT(v8::Context::InContext()); |
| 56 | 58 |
| 57 if (!m_filter->IsFunction()) return NodeFilter::FILTER_ACCEPT; | 59 if (!m_filter->IsFunction()) return NodeFilter::FILTER_ACCEPT; |
| 58 | 60 |
| 59 v8::TryCatch exception_catcher; | 61 ExceptionCatcher exception_catcher(exception_context); |
| 60 | 62 |
| 61 v8::Handle<v8::Object> this_obj = v8::Context::GetCurrent()->Global(); | 63 v8::Handle<v8::Object> this_obj = v8::Context::GetCurrent()->Global(); |
| 62 v8::Handle<v8::Function> callback = v8::Handle<v8::Function>::Cast(m_filter); | 64 v8::Handle<v8::Function> callback = |
| 65 v8::Handle<v8::Function>::Cast(m_filter); |
| 63 v8::Handle<v8::Value>* args = new v8::Handle<v8::Value>[1]; | 66 v8::Handle<v8::Value>* args = new v8::Handle<v8::Value>[1]; |
| 64 args[0] = V8Proxy::ToV8Object(V8ClassIndex::NODE, node); | 67 args[0] = V8Proxy::ToV8Object(V8ClassIndex::NODE, node); |
| 65 | 68 |
| 66 V8Proxy* proxy = V8Proxy::retrieve(); | 69 V8Proxy* proxy = V8Proxy::retrieve(); |
| 67 ASSERT(proxy); | 70 ASSERT(proxy); |
| 68 | 71 |
| 69 v8::Handle<v8::Value> result = | 72 v8::Handle<v8::Value> result = |
| 70 proxy->CallFunction(callback, this_obj, 1, args); | 73 proxy->CallFunction(callback, this_obj, 1, args); |
| 71 delete[] args; | 74 delete[] args; |
| 72 | 75 |
| 73 // TODO(fqian): this code can be removed when issue 1042294 is fixed. | 76 if (exception_context->hadException()) { |
| 74 // See also 1068243. | |
| 75 if (exception_catcher.HasCaught()) { | |
| 76 return NodeFilter::FILTER_REJECT; | 77 return NodeFilter::FILTER_REJECT; |
| 77 } | 78 } |
| 78 | 79 |
| 79 ASSERT(!result.IsEmpty()); | 80 ASSERT(!result.IsEmpty()); |
| 80 | 81 |
| 81 return result->Int32Value(); | 82 return result->Int32Value(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 } // namespace WebCore | 85 } // namespace WebCore |
| OLD | NEW |