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 "JSMutationCallback.h"
23
24#include "JSDOMConvertInterface.h"
25#include "JSDOMConvertSequences.h"
26#include "JSDOMExceptionHandling.h"
27#include "JSDOMGlobalObject.h"
28#include "JSMutationObserver.h"
29#include "JSMutationRecord.h"
30#include "ScriptExecutionContext.h"
31#include <JavaScriptCore/JSArray.h>
32
33
34namespace WebCore {
35using namespace JSC;
36
37JSMutationCallback::JSMutationCallback(JSObject* callback, JSDOMGlobalObject* globalObject)
38 : MutationCallback(globalObject->scriptExecutionContext())
39 , m_data(new JSCallbackDataWeak(callback, globalObject, this))
40{
41}
42
43JSMutationCallback::~JSMutationCallback()
44{
45 ScriptExecutionContext* context = scriptExecutionContext();
46 // When the context is destroyed, all tasks with a reference to a callback
47 // should be deleted. So if the context is 0, we are on the context thread.
48 if (!context || context->isContextThread())
49 delete m_data;
50 else
51 context->postTask(DeleteCallbackDataTask(m_data));
52#ifndef NDEBUG
53 m_data = nullptr;
54#endif
55}
56
57CallbackResult<typename IDLVoid::ImplementationType> JSMutationCallback::handleEvent(typename IDLInterface<MutationObserver>::ParameterType thisObject, typename IDLSequence<IDLInterface<MutationRecord>>::ParameterType mutations, typename IDLInterface<MutationObserver>::ParameterType observer)
58{
59 if (!canInvokeCallback())
60 return CallbackResultType::UnableToExecute;
61
62 Ref<JSMutationCallback> protectedThis(*this);
63
64 auto& globalObject = *m_data->globalObject();
65 auto& vm = globalObject.vm();
66
67 JSLockHolder lock(vm);
68 auto& state = *globalObject.globalExec();
69 JSValue thisValue = toJS<IDLInterface<MutationObserver>>(state, globalObject, thisObject);
70 MarkedArgumentBuffer args;
71 args.append(toJS<IDLSequence<IDLInterface<MutationRecord>>>(state, globalObject, mutations));
72 args.append(toJS<IDLInterface<MutationObserver>>(state, globalObject, observer));
73 ASSERT(!args.hasOverflowed());
74
75 NakedPtr<JSC::Exception> returnedException;
76 m_data->invokeCallback(thisValue, args, JSCallbackData::CallbackType::Function, Identifier(), returnedException);
77 if (returnedException) {
78 reportException(&state, returnedException);
79 return CallbackResultType::ExceptionThrown;
80 }
81
82 return { };
83}
84
85void JSMutationCallback::visitJSFunction(JSC::SlotVisitor& visitor)
86{
87 m_data->visitJSFunction(visitor);
88}
89
90JSC::JSValue toJS(MutationCallback& impl)
91{
92 if (!static_cast<JSMutationCallback&>(impl).callbackData())
93 return jsNull();
94
95 return static_cast<JSMutationCallback&>(impl).callbackData()->callback();
96}
97
98} // namespace WebCore
99