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