JSTestCallbackFunctionWithThisObject.cpp [plain text]
#include "config.h"
#include "JSTestCallbackFunctionWithThisObject.h"
#include "JSDOMConvertInterface.h"
#include "JSDOMConvertSequences.h"
#include "JSDOMExceptionHandling.h"
#include "JSDOMGlobalObject.h"
#include "JSTestNode.h"
#include "ScriptExecutionContext.h"
#include <runtime/JSArray.h>
namespace WebCore {
using namespace JSC;
JSTestCallbackFunctionWithThisObject::JSTestCallbackFunctionWithThisObject(JSObject* callback, JSDOMGlobalObject* globalObject)
: TestCallbackFunctionWithThisObject(globalObject->scriptExecutionContext())
, m_data(new JSCallbackDataStrong(callback, globalObject, this))
{
}
JSTestCallbackFunctionWithThisObject::~JSTestCallbackFunctionWithThisObject()
{
ScriptExecutionContext* context = scriptExecutionContext();
if (!context || context->isContextThread())
delete m_data;
else
context->postTask(DeleteCallbackDataTask(m_data));
#ifndef NDEBUG
m_data = nullptr;
#endif
}
CallbackResult<typename IDLVoid::ImplementationType> JSTestCallbackFunctionWithThisObject::handleEvent(typename IDLInterface<TestNode>::ParameterType thisObject, typename IDLSequence<IDLInterface<TestNode>>::ParameterType parameter)
{
if (!canInvokeCallback())
return CallbackResultType::UnableToExecute;
Ref<JSTestCallbackFunctionWithThisObject> protectedThis(*this);
auto& globalObject = *m_data->globalObject();
auto& vm = globalObject.vm();
JSLockHolder lock(vm);
auto& state = *globalObject.globalExec();
JSValue thisValue = toJS<IDLInterface<TestNode>>(state, globalObject, thisObject);
MarkedArgumentBuffer args;
args.append(toJS<IDLSequence<IDLInterface<TestNode>>>(state, globalObject, parameter));
ASSERT(!args.hasOverflowed());
NakedPtr<JSC::Exception> returnedException;
m_data->invokeCallback(thisValue, args, JSCallbackData::CallbackType::Function, Identifier(), returnedException);
if (returnedException) {
reportException(&state, returnedException);
return CallbackResultType::ExceptionThrown;
}
return { };
}
JSC::JSValue toJS(TestCallbackFunctionWithThisObject& impl)
{
if (!static_cast<JSTestCallbackFunctionWithThisObject&>(impl).callbackData())
return jsNull();
return static_cast<JSTestCallbackFunctionWithThisObject&>(impl).callbackData()->callback();
}
}