JSTestCallbackFunctionWithTypedefs.cpp [plain text]
#include "config.h"
#include "JSTestCallbackFunctionWithTypedefs.h"
#include "JSDOMConvert.h"
#include "ScriptExecutionContext.h"
#include <runtime/JSArray.h>
#include <runtime/JSLock.h>
using namespace JSC;
namespace WebCore {
JSTestCallbackFunctionWithTypedefs::JSTestCallbackFunctionWithTypedefs(JSObject* callback, JSDOMGlobalObject* globalObject)
: TestCallbackFunctionWithTypedefs()
, ActiveDOMCallback(globalObject->scriptExecutionContext())
, m_data(new JSCallbackDataStrong(callback, globalObject, this))
{
}
JSTestCallbackFunctionWithTypedefs::~JSTestCallbackFunctionWithTypedefs()
{
ScriptExecutionContext* context = scriptExecutionContext();
if (!context || context->isContextThread())
delete m_data;
else
context->postTask(DeleteCallbackDataTask(m_data));
#ifndef NDEBUG
m_data = nullptr;
#endif
}
bool JSTestCallbackFunctionWithTypedefs::handleEvent(Vector<int32_t> sequenceArg, int32_t longArg)
{
if (!canInvokeCallback())
return true;
Ref<JSTestCallbackFunctionWithTypedefs> protectedThis(*this);
JSLockHolder lock(m_data->globalObject()->vm());
ExecState* state = m_data->globalObject()->globalExec();
MarkedArgumentBuffer args;
args.append(toJS<IDLSequence<IDLNullable<IDLLong>>>(*state, *m_data->globalObject(), sequenceArg));
args.append(toJS<IDLLong>(longArg));
NakedPtr<JSC::Exception> returnedException;
m_data->invokeCallback(args, JSCallbackData::CallbackType::Function, Identifier(), returnedException);
if (returnedException)
reportException(state, returnedException);
return !returnedException;
}
JSC::JSValue toJS(TestCallbackFunctionWithTypedefs& impl)
{
if (!static_cast<JSTestCallbackFunctionWithTypedefs&>(impl).callbackData())
return jsNull();
return static_cast<JSTestCallbackFunctionWithTypedefs&>(impl).callbackData()->callback();
}
}