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