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