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 "JSGeolocation.h"
26
27#include "JSDOMBinding.h"
28#include "JSDOMConvertCallbacks.h"
29#include "JSDOMConvertDictionary.h"
30#include "JSDOMConvertNullable.h"
31#include "JSDOMConvertNumbers.h"
32#include "JSDOMExceptionHandling.h"
33#include "JSDOMGlobalObject.h"
34#include "JSDOMOperation.h"
35#include "JSDOMWrapperCache.h"
36#include "JSPositionCallback.h"
37#include "JSPositionErrorCallback.h"
38#include "JSPositionOptions.h"
39#include "ScriptExecutionContext.h"
40#include <JavaScriptCore/HeapSnapshotBuilder.h>
41#include <JavaScriptCore/JSCInlines.h>
42#include <wtf/GetPtr.h>
43#include <wtf/PointerPreparations.h>
44#include <wtf/URL.h>
45
46
47namespace WebCore {
48using namespace JSC;
49
50// Functions
51
52JSC::EncodedJSValue JSC_HOST_CALL jsGeolocationPrototypeFunctionGetCurrentPosition(JSC::ExecState*);
53JSC::EncodedJSValue JSC_HOST_CALL jsGeolocationPrototypeFunctionWatchPosition(JSC::ExecState*);
54JSC::EncodedJSValue JSC_HOST_CALL jsGeolocationPrototypeFunctionClearWatch(JSC::ExecState*);
55
56class JSGeolocationPrototype : public JSC::JSNonFinalObject {
57public:
58 using Base = JSC::JSNonFinalObject;
59 static JSGeolocationPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
60 {
61 JSGeolocationPrototype* ptr = new (NotNull, JSC::allocateCell<JSGeolocationPrototype>(vm.heap)) JSGeolocationPrototype(vm, globalObject, structure);
62 ptr->finishCreation(vm);
63 return ptr;
64 }
65
66 DECLARE_INFO;
67 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
68 {
69 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
70 }
71
72private:
73 JSGeolocationPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
74 : JSC::JSNonFinalObject(vm, structure)
75 {
76 }
77
78 void finishCreation(JSC::VM&);
79};
80
81/* Hash table for prototype */
82
83static const HashTableValue JSGeolocationPrototypeTableValues[] =
84{
85 { "getCurrentPosition", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsGeolocationPrototypeFunctionGetCurrentPosition), (intptr_t) (1) } },
86 { "watchPosition", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsGeolocationPrototypeFunctionWatchPosition), (intptr_t) (1) } },
87 { "clearWatch", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsGeolocationPrototypeFunctionClearWatch), (intptr_t) (1) } },
88};
89
90const ClassInfo JSGeolocationPrototype::s_info = { "GeolocationPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSGeolocationPrototype) };
91
92void JSGeolocationPrototype::finishCreation(VM& vm)
93{
94 Base::finishCreation(vm);
95 reifyStaticProperties(vm, JSGeolocation::info(), JSGeolocationPrototypeTableValues, *this);
96}
97
98const ClassInfo JSGeolocation::s_info = { "Geolocation", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSGeolocation) };
99
100JSGeolocation::JSGeolocation(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Geolocation>&& impl)
101 : JSDOMWrapper<Geolocation>(structure, globalObject, WTFMove(impl))
102{
103}
104
105void JSGeolocation::finishCreation(VM& vm)
106{
107 Base::finishCreation(vm);
108 ASSERT(inherits(vm, info()));
109
110}
111
112JSObject* JSGeolocation::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
113{
114 return JSGeolocationPrototype::create(vm, &globalObject, JSGeolocationPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
115}
116
117JSObject* JSGeolocation::prototype(VM& vm, JSDOMGlobalObject& globalObject)
118{
119 return getDOMPrototype<JSGeolocation>(vm, globalObject);
120}
121
122void JSGeolocation::destroy(JSC::JSCell* cell)
123{
124 JSGeolocation* thisObject = static_cast<JSGeolocation*>(cell);
125 thisObject->JSGeolocation::~JSGeolocation();
126}
127
128template<> inline JSGeolocation* IDLOperation<JSGeolocation>::cast(ExecState& state)
129{
130 return jsDynamicCast<JSGeolocation*>(state.vm(), state.thisValue());
131}
132
133static inline JSC::EncodedJSValue jsGeolocationPrototypeFunctionGetCurrentPositionBody(JSC::ExecState* state, typename IDLOperation<JSGeolocation>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
134{
135 UNUSED_PARAM(state);
136 UNUSED_PARAM(throwScope);
137 auto& impl = castedThis->wrapped();
138 if (UNLIKELY(state->argumentCount() < 1))
139 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
140 auto successCallback = convert<IDLCallbackFunction<JSPositionCallback>>(*state, state->uncheckedArgument(0), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 0, "successCallback", "Geolocation", "getCurrentPosition"); });
141 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
142 auto errorCallback = convert<IDLNullable<IDLCallbackFunction<JSPositionErrorCallback>>>(*state, state->argument(1), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 1, "errorCallback", "Geolocation", "getCurrentPosition"); });
143 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
144 auto options = convert<IDLDictionary<PositionOptions>>(*state, state->argument(2));
145 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
146 impl.getCurrentPosition(successCallback.releaseNonNull(), WTFMove(errorCallback), WTFMove(options));
147 return JSValue::encode(jsUndefined());
148}
149
150EncodedJSValue JSC_HOST_CALL jsGeolocationPrototypeFunctionGetCurrentPosition(ExecState* state)
151{
152 return IDLOperation<JSGeolocation>::call<jsGeolocationPrototypeFunctionGetCurrentPositionBody>(*state, "getCurrentPosition");
153}
154
155static inline JSC::EncodedJSValue jsGeolocationPrototypeFunctionWatchPositionBody(JSC::ExecState* state, typename IDLOperation<JSGeolocation>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
156{
157 UNUSED_PARAM(state);
158 UNUSED_PARAM(throwScope);
159 auto& impl = castedThis->wrapped();
160 if (UNLIKELY(state->argumentCount() < 1))
161 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
162 auto successCallback = convert<IDLCallbackFunction<JSPositionCallback>>(*state, state->uncheckedArgument(0), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 0, "successCallback", "Geolocation", "watchPosition"); });
163 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
164 auto errorCallback = convert<IDLNullable<IDLCallbackFunction<JSPositionErrorCallback>>>(*state, state->argument(1), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 1, "errorCallback", "Geolocation", "watchPosition"); });
165 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
166 auto options = convert<IDLDictionary<PositionOptions>>(*state, state->argument(2));
167 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
168 return JSValue::encode(toJS<IDLLong>(impl.watchPosition(successCallback.releaseNonNull(), WTFMove(errorCallback), WTFMove(options))));
169}
170
171EncodedJSValue JSC_HOST_CALL jsGeolocationPrototypeFunctionWatchPosition(ExecState* state)
172{
173 return IDLOperation<JSGeolocation>::call<jsGeolocationPrototypeFunctionWatchPositionBody>(*state, "watchPosition");
174}
175
176static inline JSC::EncodedJSValue jsGeolocationPrototypeFunctionClearWatchBody(JSC::ExecState* state, typename IDLOperation<JSGeolocation>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
177{
178 UNUSED_PARAM(state);
179 UNUSED_PARAM(throwScope);
180 auto& impl = castedThis->wrapped();
181 if (UNLIKELY(state->argumentCount() < 1))
182 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
183 auto watchId = convert<IDLLong>(*state, state->uncheckedArgument(0));
184 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
185 impl.clearWatch(WTFMove(watchId));
186 return JSValue::encode(jsUndefined());
187}
188
189EncodedJSValue JSC_HOST_CALL jsGeolocationPrototypeFunctionClearWatch(ExecState* state)
190{
191 return IDLOperation<JSGeolocation>::call<jsGeolocationPrototypeFunctionClearWatchBody>(*state, "clearWatch");
192}
193
194void JSGeolocation::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
195{
196 auto* thisObject = jsCast<JSGeolocation*>(cell);
197 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
198 if (thisObject->scriptExecutionContext())
199 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
200 Base::heapSnapshot(cell, builder);
201}
202
203bool JSGeolocationOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
204{
205 auto* jsGeolocation = jsCast<JSGeolocation*>(handle.slot()->asCell());
206 Frame* root = WTF::getPtr(jsGeolocation->wrapped().frame());
207 if (!root)
208 return false;
209 if (UNLIKELY(reason))
210 *reason = "Reachable from Frame";
211 return visitor.containsOpaqueRoot(root);
212}
213
214void JSGeolocationOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
215{
216 auto* jsGeolocation = static_cast<JSGeolocation*>(handle.slot()->asCell());
217 auto& world = *static_cast<DOMWrapperWorld*>(context);
218 uncacheWrapper(world, &jsGeolocation->wrapped(), jsGeolocation);
219}
220
221#if ENABLE(BINDING_INTEGRITY)
222#if PLATFORM(WIN)
223#pragma warning(disable: 4483)
224extern "C" { extern void (*const __identifier("??_7Geolocation@WebCore@@6B@")[])(); }
225#else
226extern "C" { extern void* _ZTVN7WebCore11GeolocationE[]; }
227#endif
228#endif
229
230JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<Geolocation>&& impl)
231{
232
233#if ENABLE(BINDING_INTEGRITY)
234 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
235#if PLATFORM(WIN)
236 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7Geolocation@WebCore@@6B@"));
237#else
238 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore11GeolocationE[2]);
239#endif
240
241 // If this fails Geolocation does not have a vtable, so you need to add the
242 // ImplementationLacksVTable attribute to the interface definition
243 static_assert(std::is_polymorphic<Geolocation>::value, "Geolocation is not polymorphic");
244
245 // If you hit this assertion you either have a use after free bug, or
246 // Geolocation has subclasses. If Geolocation has subclasses that get passed
247 // to toJS() we currently require Geolocation you to opt out of binding hardening
248 // by adding the SkipVTableValidation attribute to the interface IDL definition
249 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
250#endif
251 return createWrapper<Geolocation>(globalObject, WTFMove(impl));
252}
253
254JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, Geolocation& impl)
255{
256 return wrap(state, globalObject, impl);
257}
258
259Geolocation* JSGeolocation::toWrapped(JSC::VM& vm, JSC::JSValue value)
260{
261 if (auto* wrapper = jsDynamicCast<JSGeolocation*>(vm, value))
262 return &wrapper->wrapped();
263 return nullptr;
264}
265
266}
267
268#endif // ENABLE(GEOLOCATION)
269