JSCustomXPathNSResolver.cpp [plain text]
#include "config.h"
#include "JSCustomXPathNSResolver.h"
#include "CommonVM.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMWindowCustom.h"
#include "JSMainThreadExecState.h"
#include "Page.h"
#include "PageConsoleClient.h"
#include <runtime/JSLock.h>
#include <wtf/Ref.h>
namespace WebCore {
using namespace JSC;
ExceptionOr<Ref<JSCustomXPathNSResolver>> JSCustomXPathNSResolver::create(ExecState& state, JSValue value)
{
if (value.isUndefinedOrNull())
return Exception { TypeError };
auto* resolverObject = value.getObject();
if (!resolverObject)
return Exception { TYPE_MISMATCH_ERR };
return adoptRef(*new JSCustomXPathNSResolver(state.vm(), resolverObject, asJSDOMWindow(state.vmEntryGlobalObject())));
}
JSCustomXPathNSResolver::JSCustomXPathNSResolver(VM& vm, JSObject* customResolver, JSDOMWindow* globalObject)
: m_customResolver(vm, customResolver)
, m_globalObject(vm, globalObject)
{
}
JSCustomXPathNSResolver::~JSCustomXPathNSResolver()
{
}
String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
{
ASSERT(m_customResolver);
JSLockHolder lock(commonVM());
ExecState* exec = m_globalObject->globalExec();
JSValue function = m_customResolver->get(exec, Identifier::fromString(exec, "lookupNamespaceURI"));
CallData callData;
CallType callType = getCallData(function, callData);
if (callType == CallType::None) {
callType = m_customResolver->methodTable()->getCallData(m_customResolver.get(), callData);
if (callType == CallType::None) {
if (PageConsoleClient* console = m_globalObject->wrapped().console())
console->addMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("XPathNSResolver does not have a lookupNamespaceURI method."));
return String();
}
function = m_customResolver.get();
}
Ref<JSCustomXPathNSResolver> protectedThis(*this);
MarkedArgumentBuffer args;
args.append(jsStringWithCache(exec, prefix));
NakedPtr<JSC::Exception> exception;
JSValue retval = JSMainThreadExecState::call(exec, function, callType, callData, m_customResolver.get(), args, exception);
String result;
if (exception)
reportException(exec, exception);
else {
if (!retval.isUndefinedOrNull())
result = retval.toWTFString(exec);
}
return result;
}
}