V8CustomXPathNSResolver.cpp [plain text]
#include "config.h"
#include "V8CustomXPathNSResolver.h"
#include "ScriptCallStack.h"
#include "ScriptExecutionContext.h"
#include "V8Binding.h"
#include "V8Proxy.h"
#include "V8Utilities.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
PassRefPtr<V8CustomXPathNSResolver> V8CustomXPathNSResolver::create(v8::Handle<v8::Object> resolver)
{
return adoptRef(new V8CustomXPathNSResolver(resolver));
}
V8CustomXPathNSResolver::V8CustomXPathNSResolver(v8::Handle<v8::Object> resolver)
: m_resolver(resolver)
{
}
V8CustomXPathNSResolver::~V8CustomXPathNSResolver()
{
}
String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
{
v8::Handle<v8::Function> lookupNamespaceURIFunc;
v8::Handle<v8::String> lookupNamespaceURIName = v8::String::New("lookupNamespaceURI");
if (m_resolver->Has(lookupNamespaceURIName)) {
v8::Handle<v8::Value> lookupNamespaceURI = m_resolver->Get(lookupNamespaceURIName);
if (lookupNamespaceURI->IsFunction())
lookupNamespaceURIFunc = v8::Handle<v8::Function>::Cast(lookupNamespaceURI);
}
if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) {
if (ScriptExecutionContext* context = getScriptExecutionContext())
context->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.");
return String();
}
v8::TryCatch try_catch;
try_catch.SetVerbose(true);
const int argc = 1;
v8::Handle<v8::Value> argv[argc] = { v8String(prefix) };
v8::Handle<v8::Function> function = lookupNamespaceURIFunc.IsEmpty() ? v8::Handle<v8::Function>::Cast(m_resolver) : lookupNamespaceURIFunc;
v8::Handle<v8::Value> retval = V8Proxy::instrumentedCallFunction(0 , function, m_resolver, argc, argv);
if (try_catch.HasCaught())
return String();
return toWebCoreStringWithNullCheck(retval);
}
}