2009-11-10 Vitaly Repeshko <vitalyr@chromium.org>
[WebKit-https.git] / WebCore / bindings / v8 / custom / V8CustomXPathNSResolver.cpp
index 334192495b285f6818dff6ed3ad611fa8770c2e3..e45cba0285c48a513960742fb0d285cbb02356c0 100644 (file)
 
 namespace WebCore {
 
-PassRefPtr<V8CustomXPathNSResolver> V8CustomXPathNSResolver::create(v8::Handle<v8::Object> resolver)
+PassRefPtr<V8CustomXPathNSResolver> V8CustomXPathNSResolver::create(V8Proxy* proxy, v8::Handle<v8::Object> resolver)
 {
-    return adoptRef(new V8CustomXPathNSResolver(resolver));
+    return adoptRef(new V8CustomXPathNSResolver(proxy, resolver));
 }
 
-V8CustomXPathNSResolver::V8CustomXPathNSResolver(v8::Handle<v8::Object> resolver)
-    : m_resolver(resolver)
+V8CustomXPathNSResolver::V8CustomXPathNSResolver(V8Proxy* proxy, v8::Handle<v8::Object> resolver)
+        : m_proxy(proxy)
+        , m_resolver(resolver)
 {
 }
 
@@ -54,6 +55,14 @@ V8CustomXPathNSResolver::~V8CustomXPathNSResolver()
 
 String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
 {
+    V8Proxy* proxy = m_proxy;
+
+    if (!proxy) {
+        proxy = V8Proxy::retrieve();
+        if (!proxy)
+            return String();
+    }
+
     v8::Handle<v8::Function> lookupNamespaceURIFunc;
     v8::Handle<v8::String> lookupNamespaceURIName = v8::String::New("lookupNamespaceURI");
 
@@ -65,7 +74,7 @@ String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
     }
 
     if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) {
-        Frame* frame = V8Proxy::retrieveFrameForEnteredContext();
+        Frame* frame = proxy->frame();
         logInfo(frame, "XPathNSResolver does not have a lookupNamespaceURI method.", String());
         return String();
     }
@@ -78,7 +87,6 @@ String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
     v8::Handle<v8::Value> argv[argc] = { v8String(prefix) };
     v8::Handle<v8::Function> function = lookupNamespaceURIFunc.IsEmpty() ? v8::Handle<v8::Function>::Cast(m_resolver) : lookupNamespaceURIFunc;
 
-    V8Proxy* proxy = V8Proxy::retrieve();
     v8::Handle<v8::Value> retval = proxy->callFunction(function, m_resolver, argc, argv);
 
     // Eat exceptions from namespace resolver and return an empty string. This will most likely cause NAMESPACE_ERR.