1/*
2 This file is part of the WebKit open source project.
3 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "JSVoidCallback.h"
23
24#include "JSDOMExceptionHandling.h"
25#include "ScriptExecutionContext.h"
26
27
28namespace WebCore {
29using namespace JSC;
30
31JSVoidCallback::JSVoidCallback(JSObject* callback, JSDOMGlobalObject* globalObject)
32 : VoidCallback(globalObject->scriptExecutionContext())
33 , m_data(new JSCallbackDataStrong(callback, globalObject, this))
34{
35}
36
37JSVoidCallback::~JSVoidCallback()
38{
39 ScriptExecutionContext* context = scriptExecutionContext();
40 // When the context is destroyed, all tasks with a reference to a callback
41 // should be deleted. So if the context is 0, we are on the context thread.
42 if (!context || context->isContextThread())
43 delete m_data;
44 else
45 context->postTask(DeleteCallbackDataTask(m_data));
46#ifndef NDEBUG
47 m_data = nullptr;
48#endif
49}
50
51CallbackResult<typename IDLVoid::ImplementationType> JSVoidCallback::handleEvent()
52{
53 if (!canInvokeCallback())
54 return CallbackResultType::UnableToExecute;
55
56 Ref<JSVoidCallback> protectedThis(*this);
57
58 auto& globalObject = *m_data->globalObject();
59 auto& vm = globalObject.vm();
60
61 JSLockHolder lock(vm);
62 auto& state = *globalObject.globalExec();
63 JSValue thisValue = jsUndefined();
64 MarkedArgumentBuffer args;
65 ASSERT(!args.hasOverflowed());
66
67 NakedPtr<JSC::Exception> returnedException;
68 m_data->invokeCallback(thisValue, args, JSCallbackData::CallbackType::Function, Identifier(), returnedException);
69 if (returnedException) {
70 reportException(&state, returnedException);
71 return CallbackResultType::ExceptionThrown;
72 }
73
74 return { };
75}
76
77JSC::JSValue toJS(VoidCallback& impl)
78{
79 if (!static_cast<JSVoidCallback&>(impl).callbackData())
80 return jsNull();
81
82 return static_cast<JSVoidCallback&>(impl).callbackData()->callback();
83}
84
85} // namespace WebCore
86