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(DEVICE_ORIENTATION)
24
25#include "JSDeviceOrientationEvent.h"
26
27#include "Document.h"
28#include "JSDOMAttribute.h"
29#include "JSDOMBinding.h"
30#include "JSDOMConstructorNotConstructable.h"
31#include "JSDOMConvertBoolean.h"
32#include "JSDOMConvertNullable.h"
33#include "JSDOMConvertNumbers.h"
34#include "JSDOMConvertStrings.h"
35#include "JSDOMExceptionHandling.h"
36#include "JSDOMOperation.h"
37#include "JSDOMWrapperCache.h"
38#include "ScriptExecutionContext.h"
39#include "Settings.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#if ENABLE(DEVICE_ORIENTATION)
47#include "JSDOMOperationReturningPromise.h"
48#endif
49
50
51namespace WebCore {
52using namespace JSC;
53
54// Functions
55
56JSC::EncodedJSValue JSC_HOST_CALL jsDeviceOrientationEventPrototypeFunctionInitDeviceOrientationEvent(JSC::ExecState*);
57#if ENABLE(DEVICE_ORIENTATION)
58JSC::EncodedJSValue JSC_HOST_CALL jsDeviceOrientationEventConstructorFunctionRequestPermission(JSC::ExecState*);
59#endif
60
61// Attributes
62
63JSC::EncodedJSValue jsDeviceOrientationEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
64bool setJSDeviceOrientationEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
65JSC::EncodedJSValue jsDeviceOrientationEventAlpha(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
66JSC::EncodedJSValue jsDeviceOrientationEventBeta(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
67JSC::EncodedJSValue jsDeviceOrientationEventGamma(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
68JSC::EncodedJSValue jsDeviceOrientationEventAbsolute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
69
70class JSDeviceOrientationEventPrototype : public JSC::JSNonFinalObject {
71public:
72 using Base = JSC::JSNonFinalObject;
73 static JSDeviceOrientationEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
74 {
75 JSDeviceOrientationEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSDeviceOrientationEventPrototype>(vm.heap)) JSDeviceOrientationEventPrototype(vm, globalObject, structure);
76 ptr->finishCreation(vm);
77 return ptr;
78 }
79
80 DECLARE_INFO;
81 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
82 {
83 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
84 }
85
86private:
87 JSDeviceOrientationEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
88 : JSC::JSNonFinalObject(vm, structure)
89 {
90 }
91
92 void finishCreation(JSC::VM&);
93};
94
95using JSDeviceOrientationEventConstructor = JSDOMConstructorNotConstructable<JSDeviceOrientationEvent>;
96
97/* Hash table for constructor */
98
99static const HashTableValue JSDeviceOrientationEventConstructorTableValues[] =
100{
101#if ENABLE(DEVICE_ORIENTATION)
102 { "requestPermission", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDeviceOrientationEventConstructorFunctionRequestPermission), (intptr_t) (0) } },
103#else
104 { 0, 0, NoIntrinsic, { 0, 0 } },
105#endif
106};
107
108template<> JSValue JSDeviceOrientationEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
109{
110 return JSEvent::getConstructor(vm, &globalObject);
111}
112
113template<> void JSDeviceOrientationEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
114{
115 putDirect(vm, vm.propertyNames->prototype, JSDeviceOrientationEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
116 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("DeviceOrientationEvent"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
117 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
118 reifyStaticProperties(vm, JSDeviceOrientationEvent::info(), JSDeviceOrientationEventConstructorTableValues, *this);
119#if ENABLE(DEVICE_ORIENTATION)
120 if (!downcast<Document>(jsCast<JSDOMGlobalObject*>(&globalObject)->scriptExecutionContext())->settings().deviceOrientationPermissionAPIEnabled()) {
121 auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("requestPermission"), strlen("requestPermission"));
122 VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
123 JSObject::deleteProperty(this, globalObject.globalExec(), propertyName);
124 }
125#endif
126}
127
128template<> const ClassInfo JSDeviceOrientationEventConstructor::s_info = { "DeviceOrientationEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDeviceOrientationEventConstructor) };
129
130/* Hash table for prototype */
131
132static const HashTableValue JSDeviceOrientationEventPrototypeTableValues[] =
133{
134 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceOrientationEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDeviceOrientationEventConstructor) } },
135 { "alpha", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceOrientationEventAlpha), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
136 { "beta", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceOrientationEventBeta), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
137 { "gamma", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceOrientationEventGamma), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
138 { "absolute", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceOrientationEventAbsolute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
139 { "initDeviceOrientationEvent", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDeviceOrientationEventPrototypeFunctionInitDeviceOrientationEvent), (intptr_t) (0) } },
140};
141
142const ClassInfo JSDeviceOrientationEventPrototype::s_info = { "DeviceOrientationEventPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDeviceOrientationEventPrototype) };
143
144void JSDeviceOrientationEventPrototype::finishCreation(VM& vm)
145{
146 Base::finishCreation(vm);
147 reifyStaticProperties(vm, JSDeviceOrientationEvent::info(), JSDeviceOrientationEventPrototypeTableValues, *this);
148}
149
150const ClassInfo JSDeviceOrientationEvent::s_info = { "DeviceOrientationEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDeviceOrientationEvent) };
151
152JSDeviceOrientationEvent::JSDeviceOrientationEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DeviceOrientationEvent>&& impl)
153 : JSEvent(structure, globalObject, WTFMove(impl))
154{
155}
156
157void JSDeviceOrientationEvent::finishCreation(VM& vm)
158{
159 Base::finishCreation(vm);
160 ASSERT(inherits(vm, info()));
161
162}
163
164JSObject* JSDeviceOrientationEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
165{
166 return JSDeviceOrientationEventPrototype::create(vm, &globalObject, JSDeviceOrientationEventPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject)));
167}
168
169JSObject* JSDeviceOrientationEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject)
170{
171 return getDOMPrototype<JSDeviceOrientationEvent>(vm, globalObject);
172}
173
174JSValue JSDeviceOrientationEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject)
175{
176 return getDOMConstructor<JSDeviceOrientationEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
177}
178
179template<> inline JSDeviceOrientationEvent* IDLAttribute<JSDeviceOrientationEvent>::cast(ExecState& state, EncodedJSValue thisValue)
180{
181 return jsDynamicCast<JSDeviceOrientationEvent*>(state.vm(), JSValue::decode(thisValue));
182}
183
184template<> inline JSDeviceOrientationEvent* IDLOperation<JSDeviceOrientationEvent>::cast(ExecState& state)
185{
186 return jsDynamicCast<JSDeviceOrientationEvent*>(state.vm(), state.thisValue());
187}
188
189EncodedJSValue jsDeviceOrientationEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
190{
191 VM& vm = state->vm();
192 auto throwScope = DECLARE_THROW_SCOPE(vm);
193 auto* prototype = jsDynamicCast<JSDeviceOrientationEventPrototype*>(vm, JSValue::decode(thisValue));
194 if (UNLIKELY(!prototype))
195 return throwVMTypeError(state, throwScope);
196 return JSValue::encode(JSDeviceOrientationEvent::getConstructor(state->vm(), prototype->globalObject()));
197}
198
199bool setJSDeviceOrientationEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
200{
201 VM& vm = state->vm();
202 auto throwScope = DECLARE_THROW_SCOPE(vm);
203 auto* prototype = jsDynamicCast<JSDeviceOrientationEventPrototype*>(vm, JSValue::decode(thisValue));
204 if (UNLIKELY(!prototype)) {
205 throwVMTypeError(state, throwScope);
206 return false;
207 }
208 // Shadowing a built-in constructor
209 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
210}
211
212static inline JSValue jsDeviceOrientationEventAlphaGetter(ExecState& state, JSDeviceOrientationEvent& thisObject, ThrowScope& throwScope)
213{
214 UNUSED_PARAM(throwScope);
215 UNUSED_PARAM(state);
216 auto& impl = thisObject.wrapped();
217 JSValue result = toJS<IDLNullable<IDLUnrestrictedDouble>>(state, throwScope, impl.alpha());
218 return result;
219}
220
221EncodedJSValue jsDeviceOrientationEventAlpha(ExecState* state, EncodedJSValue thisValue, PropertyName)
222{
223 return IDLAttribute<JSDeviceOrientationEvent>::get<jsDeviceOrientationEventAlphaGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "alpha");
224}
225
226static inline JSValue jsDeviceOrientationEventBetaGetter(ExecState& state, JSDeviceOrientationEvent& thisObject, ThrowScope& throwScope)
227{
228 UNUSED_PARAM(throwScope);
229 UNUSED_PARAM(state);
230 auto& impl = thisObject.wrapped();
231 JSValue result = toJS<IDLNullable<IDLUnrestrictedDouble>>(state, throwScope, impl.beta());
232 return result;
233}
234
235EncodedJSValue jsDeviceOrientationEventBeta(ExecState* state, EncodedJSValue thisValue, PropertyName)
236{
237 return IDLAttribute<JSDeviceOrientationEvent>::get<jsDeviceOrientationEventBetaGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "beta");
238}
239
240static inline JSValue jsDeviceOrientationEventGammaGetter(ExecState& state, JSDeviceOrientationEvent& thisObject, ThrowScope& throwScope)
241{
242 UNUSED_PARAM(throwScope);
243 UNUSED_PARAM(state);
244 auto& impl = thisObject.wrapped();
245 JSValue result = toJS<IDLNullable<IDLUnrestrictedDouble>>(state, throwScope, impl.gamma());
246 return result;
247}
248
249EncodedJSValue jsDeviceOrientationEventGamma(ExecState* state, EncodedJSValue thisValue, PropertyName)
250{
251 return IDLAttribute<JSDeviceOrientationEvent>::get<jsDeviceOrientationEventGammaGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "gamma");
252}
253
254static inline JSValue jsDeviceOrientationEventAbsoluteGetter(ExecState& state, JSDeviceOrientationEvent& thisObject, ThrowScope& throwScope)
255{
256 UNUSED_PARAM(throwScope);
257 UNUSED_PARAM(state);
258 auto& impl = thisObject.wrapped();
259 JSValue result = toJS<IDLNullable<IDLBoolean>>(state, throwScope, impl.absolute());
260 return result;
261}
262
263EncodedJSValue jsDeviceOrientationEventAbsolute(ExecState* state, EncodedJSValue thisValue, PropertyName)
264{
265 return IDLAttribute<JSDeviceOrientationEvent>::get<jsDeviceOrientationEventAbsoluteGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "absolute");
266}
267
268static inline JSC::EncodedJSValue jsDeviceOrientationEventPrototypeFunctionInitDeviceOrientationEventBody(JSC::ExecState* state, typename IDLOperation<JSDeviceOrientationEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
269{
270 UNUSED_PARAM(state);
271 UNUSED_PARAM(throwScope);
272 auto& impl = castedThis->wrapped();
273 auto type = state->argument(0).isUndefined() ? emptyString() : convert<IDLDOMString>(*state, state->uncheckedArgument(0));
274 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
275 auto bubbles = convert<IDLBoolean>(*state, state->argument(1));
276 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
277 auto cancelable = convert<IDLBoolean>(*state, state->argument(2));
278 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
279 auto alpha = state->argument(3).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLUnrestrictedDouble>>(*state, state->uncheckedArgument(3));
280 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
281 auto beta = state->argument(4).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLUnrestrictedDouble>>(*state, state->uncheckedArgument(4));
282 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
283 auto gamma = state->argument(5).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLUnrestrictedDouble>>(*state, state->uncheckedArgument(5));
284 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
285 auto absolute = state->argument(6).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLBoolean>>(*state, state->uncheckedArgument(6));
286 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
287 impl.initDeviceOrientationEvent(WTFMove(type), WTFMove(bubbles), WTFMove(cancelable), WTFMove(alpha), WTFMove(beta), WTFMove(gamma), WTFMove(absolute));
288 return JSValue::encode(jsUndefined());
289}
290
291EncodedJSValue JSC_HOST_CALL jsDeviceOrientationEventPrototypeFunctionInitDeviceOrientationEvent(ExecState* state)
292{
293 return IDLOperation<JSDeviceOrientationEvent>::call<jsDeviceOrientationEventPrototypeFunctionInitDeviceOrientationEventBody>(*state, "initDeviceOrientationEvent");
294}
295
296#if ENABLE(DEVICE_ORIENTATION)
297static inline JSC::EncodedJSValue jsDeviceOrientationEventConstructorFunctionRequestPermissionBody(JSC::ExecState* state, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope)
298{
299 UNUSED_PARAM(state);
300 UNUSED_PARAM(throwScope);
301 auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext();
302 if (UNLIKELY(!context))
303 return JSValue::encode(jsUndefined());
304 ASSERT(context->isDocument());
305 auto& document = downcast<Document>(*context);
306 DeviceOrientationEvent::requestPermission(document, WTFMove(promise));
307 return JSValue::encode(jsUndefined());
308}
309
310EncodedJSValue JSC_HOST_CALL jsDeviceOrientationEventConstructorFunctionRequestPermission(ExecState* state)
311{
312 return IDLOperationReturningPromise<JSDeviceOrientationEvent>::callStatic<jsDeviceOrientationEventConstructorFunctionRequestPermissionBody, PromiseExecutionScope::WindowOnly>(*state, "requestPermission");
313}
314
315#endif
316
317void JSDeviceOrientationEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
318{
319 auto* thisObject = jsCast<JSDeviceOrientationEvent*>(cell);
320 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
321 if (thisObject->scriptExecutionContext())
322 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
323 Base::heapSnapshot(cell, builder);
324}
325
326
327}
328
329#endif // ENABLE(DEVICE_ORIENTATION)
330