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