Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / v8 / V8NodeFilterCondition.cpp
index 77ec3a1..49ef6d0 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "V8Node.h"
 #include "bindings/v8/ScriptController.h"
-#include "bindings/v8/ScriptState.h"
 #include "bindings/v8/V8HiddenValue.h"
 #include "core/dom/Node.h"
 #include "core/dom/NodeFilter.h"
 namespace WebCore {
 
 V8NodeFilterCondition::V8NodeFilterCondition(v8::Handle<v8::Value> filter, v8::Handle<v8::Object> owner, v8::Isolate* isolate)
-    : m_filter(isolate, filter)
+    : m_scriptState(ScriptState::current(isolate))
 {
-    V8HiddenValue::setHiddenValue(isolate, owner, V8HiddenValue::condition(isolate), filter);
-    m_filter.setWeak(this, &setWeakCallback);
+    // ..acceptNode(..) will only dispatch m_filter if m_filter->IsObject().
+    // We'll make sure m_filter is either usable by acceptNode or empty.
+    // (See the fast/dom/node-filter-gc test for a case where 'empty' happens.)
+    if (!filter.IsEmpty() && filter->IsObject()) {
+        V8HiddenValue::setHiddenValue(isolate, owner, V8HiddenValue::condition(isolate), filter);
+        m_filter.set(isolate, filter);
+        m_filter.setWeak(this, &setWeakCallback);
+    }
 }
 
 V8NodeFilterCondition::~V8NodeFilterCondition()
 {
 }
 
-short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const
+short V8NodeFilterCondition::acceptNode(Node* node, ExceptionState& exceptionState) const
 {
-    v8::Isolate* isolate = state->isolate();
-    ASSERT(isolate->InContext());
+    v8::Isolate* isolate = m_scriptState->isolate();
+    ASSERT(!m_scriptState->context().IsEmpty());
     v8::HandleScope handleScope(isolate);
     v8::Handle<v8::Value> filter = m_filter.newLocal(isolate);
-    ASSERT(!filter.IsEmpty());
-    if (!filter->IsObject())
+
+    ASSERT(filter.IsEmpty() || filter->IsObject());
+    if (filter.IsEmpty())
         return NodeFilter::FILTER_ACCEPT;
 
     v8::TryCatch exceptionCatcher;
@@ -70,20 +76,20 @@ short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const
     else {
         v8::Local<v8::Value> value = filter->ToObject()->Get(v8AtomicString(isolate, "acceptNode"));
         if (value.IsEmpty() || !value->IsFunction()) {
-            throwTypeError("NodeFilter object does not have an acceptNode function", state->isolate());
+            throwTypeError("NodeFilter object does not have an acceptNode function", isolate);
             return NodeFilter::FILTER_REJECT;
         }
         callback = v8::Handle<v8::Function>::Cast(value);
     }
 
     OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Value>[1]);
-    info[0] = toV8(node, v8::Handle<v8::Object>(), state->isolate());
+    info[0] = toV8(node, v8::Handle<v8::Object>(), isolate);
 
-    v8::Handle<v8::Object> object = isolate->GetCurrentContext()->Global();
-    v8::Handle<v8::Value> result = ScriptController::callFunction(state->executionContext(), callback, object, 1, info.get(), isolate);
+    v8::Handle<v8::Object> object = m_scriptState->context()->Global();
+    v8::Handle<v8::Value> result = ScriptController::callFunction(m_scriptState->executionContext(), callback, object, 1, info.get(), isolate);
 
     if (exceptionCatcher.HasCaught()) {
-        state->setException(exceptionCatcher.Exception());
+        exceptionState.rethrowV8Exception(exceptionCatcher.Exception());
         return NodeFilter::FILTER_REJECT;
     }