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(GEOLOCATION) |
24 | |
25 | #include "JSPositionCallback.h" |
26 | |
27 | #include "JSDOMConvertInterface.h" |
28 | #include "JSDOMConvertNullable.h" |
29 | #include "JSDOMExceptionHandling.h" |
30 | #include "JSDOMGlobalObject.h" |
31 | #include "JSGeoposition.h" |
32 | #include "ScriptExecutionContext.h" |
33 | |
34 | |
35 | namespace WebCore { |
36 | using namespace JSC; |
37 | |
38 | JSPositionCallback::JSPositionCallback(JSObject* callback, JSDOMGlobalObject* globalObject) |
39 | : PositionCallback(globalObject->scriptExecutionContext()) |
40 | , m_data(new JSCallbackDataStrong(callback, globalObject, this)) |
41 | { |
42 | } |
43 | |
44 | JSPositionCallback::~JSPositionCallback() |
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 | |
58 | CallbackResult<typename IDLVoid::ImplementationType> JSPositionCallback::handleEvent(typename IDLNullable<IDLInterface<Geoposition>>::ParameterType position) |
59 | { |
60 | if (!canInvokeCallback()) |
61 | return CallbackResultType::UnableToExecute; |
62 | |
63 | Ref<JSPositionCallback> 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<Geoposition>>>(state, globalObject, position)); |
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 | |
85 | JSC::JSValue toJS(PositionCallback& impl) |
86 | { |
87 | if (!static_cast<JSPositionCallback&>(impl).callbackData()) |
88 | return jsNull(); |
89 | |
90 | return static_cast<JSPositionCallback&>(impl).callbackData()->callback(); |
91 | } |
92 | |
93 | } // namespace WebCore |
94 | |
95 | #endif // ENABLE(GEOLOCATION) |
96 | |