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