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(WEB_AUDIO)
24
25#include "JSAudioBufferCallback.h"
26
27#include "JSAudioBuffer.h"
28#include "JSDOMConvertInterface.h"
29#include "JSDOMConvertNullable.h"
30#include "JSDOMExceptionHandling.h"
31#include "JSDOMGlobalObject.h"
32#include "ScriptExecutionContext.h"
33
34
35namespace WebCore {
36using namespace JSC;
37
38JSAudioBufferCallback::JSAudioBufferCallback(JSObject* callback, JSDOMGlobalObject* globalObject)
39 : AudioBufferCallback(globalObject->scriptExecutionContext())
40 , m_data(new JSCallbackDataStrong(callback, globalObject, this))
41{
42}
43
44JSAudioBufferCallback::~JSAudioBufferCallback()
45{
46 ScriptExecutionContext* context = scriptExecutionContext();
47 // When the context is destroyed, all tasks with a reference to a callback
48 // should be deleted. So if the context is 0, we are on the context thread.
49 if (!context || context->isContextThread())
50 delete m_data;
51 else
52 context->postTask(DeleteCallbackDataTask(m_data));
53#ifndef NDEBUG
54 m_data = nullptr;
55#endif
56}
57
58CallbackResult<typename IDLVoid::ImplementationType> JSAudioBufferCallback::handleEvent(typename IDLNullable<IDLInterface<AudioBuffer>>::ParameterType audioBuffer)
59{
60 if (!canInvokeCallback())
61 return CallbackResultType::UnableToExecute;
62
63 Ref<JSAudioBufferCallback> protectedThis(*this);
64
65 auto& globalObject = *m_data->globalObject();
66 auto& vm = globalObject.vm();
67
68 JSLockHolder lock(vm);
69 auto& state = *globalObject.globalExec();
70 JSValue thisValue = jsUndefined();
71 MarkedArgumentBuffer args;
72 args.append(toJS<IDLNullable<IDLInterface<AudioBuffer>>>(state, globalObject, audioBuffer));
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
85JSC::JSValue toJS(AudioBufferCallback& impl)
86{
87 if (!static_cast<JSAudioBufferCallback&>(impl).callbackData())
88 return jsNull();
89
90 return static_cast<JSAudioBufferCallback&>(impl).callbackData()->callback();
91}
92
93} // namespace WebCore
94
95#endif // ENABLE(WEB_AUDIO)
96