| 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 "JSDeviceMotionEvent.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 "JSDOMGlobalObject.h" |
| 37 | #include "JSDOMOperation.h" |
| 38 | #include "JSDOMWrapperCache.h" |
| 39 | #include "ScriptExecutionContext.h" |
| 40 | #include "Settings.h" |
| 41 | #include <JavaScriptCore/HeapSnapshotBuilder.h> |
| 42 | #include <JavaScriptCore/JSCInlines.h> |
| 43 | #include <JavaScriptCore/ObjectConstructor.h> |
| 44 | #include <wtf/GetPtr.h> |
| 45 | #include <wtf/PointerPreparations.h> |
| 46 | #include <wtf/URL.h> |
| 47 | |
| 48 | #if ENABLE(DEVICE_ORIENTATION) |
| 49 | #include "JSDOMOperationReturningPromise.h" |
| 50 | #endif |
| 51 | |
| 52 | |
| 53 | namespace WebCore { |
| 54 | using namespace JSC; |
| 55 | |
| 56 | #if ENABLE(DEVICE_ORIENTATION) |
| 57 | |
| 58 | template<> DeviceMotionEvent::Acceleration convertDictionary<DeviceMotionEvent::Acceleration>(ExecState& state, JSValue value) |
| 59 | { |
| 60 | VM& vm = state.vm(); |
| 61 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 62 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 63 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 64 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 65 | throwTypeError(&state, throwScope); |
| 66 | return { }; |
| 67 | } |
| 68 | DeviceMotionEvent::Acceleration result; |
| 69 | JSValue xValue; |
| 70 | if (isNullOrUndefined) |
| 71 | xValue = jsUndefined(); |
| 72 | else { |
| 73 | xValue = object->get(&state, Identifier::fromString(&state, "x" )); |
| 74 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 75 | } |
| 76 | if (!xValue.isUndefined()) { |
| 77 | result.x = convert<IDLNullable<IDLDouble>>(state, xValue); |
| 78 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 79 | } |
| 80 | JSValue yValue; |
| 81 | if (isNullOrUndefined) |
| 82 | yValue = jsUndefined(); |
| 83 | else { |
| 84 | yValue = object->get(&state, Identifier::fromString(&state, "y" )); |
| 85 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 86 | } |
| 87 | if (!yValue.isUndefined()) { |
| 88 | result.y = convert<IDLNullable<IDLDouble>>(state, yValue); |
| 89 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 90 | } |
| 91 | JSValue zValue; |
| 92 | if (isNullOrUndefined) |
| 93 | zValue = jsUndefined(); |
| 94 | else { |
| 95 | zValue = object->get(&state, Identifier::fromString(&state, "z" )); |
| 96 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 97 | } |
| 98 | if (!zValue.isUndefined()) { |
| 99 | result.z = convert<IDLNullable<IDLDouble>>(state, zValue); |
| 100 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 101 | } |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const DeviceMotionEvent::Acceleration& dictionary) |
| 106 | { |
| 107 | auto& vm = state.vm(); |
| 108 | |
| 109 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 110 | |
| 111 | if (!IDLNullable<IDLDouble>::isNullValue(dictionary.x)) { |
| 112 | auto xValue = toJS<IDLNullable<IDLDouble>>(IDLNullable<IDLDouble>::extractValueFromNullable(dictionary.x)); |
| 113 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "x" ), xValue); |
| 114 | } |
| 115 | if (!IDLNullable<IDLDouble>::isNullValue(dictionary.y)) { |
| 116 | auto yValue = toJS<IDLNullable<IDLDouble>>(IDLNullable<IDLDouble>::extractValueFromNullable(dictionary.y)); |
| 117 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "y" ), yValue); |
| 118 | } |
| 119 | if (!IDLNullable<IDLDouble>::isNullValue(dictionary.z)) { |
| 120 | auto zValue = toJS<IDLNullable<IDLDouble>>(IDLNullable<IDLDouble>::extractValueFromNullable(dictionary.z)); |
| 121 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "z" ), zValue); |
| 122 | } |
| 123 | return result; |
| 124 | } |
| 125 | |
| 126 | #endif |
| 127 | |
| 128 | #if ENABLE(DEVICE_ORIENTATION) |
| 129 | |
| 130 | template<> DeviceMotionEvent::RotationRate convertDictionary<DeviceMotionEvent::RotationRate>(ExecState& state, JSValue value) |
| 131 | { |
| 132 | VM& vm = state.vm(); |
| 133 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 134 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 135 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 136 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 137 | throwTypeError(&state, throwScope); |
| 138 | return { }; |
| 139 | } |
| 140 | DeviceMotionEvent::RotationRate result; |
| 141 | JSValue alphaValue; |
| 142 | if (isNullOrUndefined) |
| 143 | alphaValue = jsUndefined(); |
| 144 | else { |
| 145 | alphaValue = object->get(&state, Identifier::fromString(&state, "alpha" )); |
| 146 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 147 | } |
| 148 | if (!alphaValue.isUndefined()) { |
| 149 | result.alpha = convert<IDLNullable<IDLDouble>>(state, alphaValue); |
| 150 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 151 | } |
| 152 | JSValue betaValue; |
| 153 | if (isNullOrUndefined) |
| 154 | betaValue = jsUndefined(); |
| 155 | else { |
| 156 | betaValue = object->get(&state, Identifier::fromString(&state, "beta" )); |
| 157 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 158 | } |
| 159 | if (!betaValue.isUndefined()) { |
| 160 | result.beta = convert<IDLNullable<IDLDouble>>(state, betaValue); |
| 161 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 162 | } |
| 163 | JSValue gammaValue; |
| 164 | if (isNullOrUndefined) |
| 165 | gammaValue = jsUndefined(); |
| 166 | else { |
| 167 | gammaValue = object->get(&state, Identifier::fromString(&state, "gamma" )); |
| 168 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 169 | } |
| 170 | if (!gammaValue.isUndefined()) { |
| 171 | result.gamma = convert<IDLNullable<IDLDouble>>(state, gammaValue); |
| 172 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 173 | } |
| 174 | return result; |
| 175 | } |
| 176 | |
| 177 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const DeviceMotionEvent::RotationRate& dictionary) |
| 178 | { |
| 179 | auto& vm = state.vm(); |
| 180 | |
| 181 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 182 | |
| 183 | if (!IDLNullable<IDLDouble>::isNullValue(dictionary.alpha)) { |
| 184 | auto alphaValue = toJS<IDLNullable<IDLDouble>>(IDLNullable<IDLDouble>::extractValueFromNullable(dictionary.alpha)); |
| 185 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "alpha" ), alphaValue); |
| 186 | } |
| 187 | if (!IDLNullable<IDLDouble>::isNullValue(dictionary.beta)) { |
| 188 | auto betaValue = toJS<IDLNullable<IDLDouble>>(IDLNullable<IDLDouble>::extractValueFromNullable(dictionary.beta)); |
| 189 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "beta" ), betaValue); |
| 190 | } |
| 191 | if (!IDLNullable<IDLDouble>::isNullValue(dictionary.gamma)) { |
| 192 | auto gammaValue = toJS<IDLNullable<IDLDouble>>(IDLNullable<IDLDouble>::extractValueFromNullable(dictionary.gamma)); |
| 193 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "gamma" ), gammaValue); |
| 194 | } |
| 195 | return result; |
| 196 | } |
| 197 | |
| 198 | #endif |
| 199 | |
| 200 | // Functions |
| 201 | |
| 202 | JSC::EncodedJSValue JSC_HOST_CALL jsDeviceMotionEventPrototypeFunctionInitDeviceMotionEvent(JSC::ExecState*); |
| 203 | #if ENABLE(DEVICE_ORIENTATION) |
| 204 | JSC::EncodedJSValue JSC_HOST_CALL jsDeviceMotionEventConstructorFunctionRequestPermission(JSC::ExecState*); |
| 205 | #endif |
| 206 | |
| 207 | // Attributes |
| 208 | |
| 209 | JSC::EncodedJSValue jsDeviceMotionEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 210 | bool setJSDeviceMotionEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
| 211 | JSC::EncodedJSValue jsDeviceMotionEventAcceleration(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 212 | JSC::EncodedJSValue jsDeviceMotionEventAccelerationIncludingGravity(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 213 | JSC::EncodedJSValue jsDeviceMotionEventRotationRate(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 214 | JSC::EncodedJSValue jsDeviceMotionEventInterval(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
| 215 | |
| 216 | class JSDeviceMotionEventPrototype : public JSC::JSNonFinalObject { |
| 217 | public: |
| 218 | using Base = JSC::JSNonFinalObject; |
| 219 | static JSDeviceMotionEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure) |
| 220 | { |
| 221 | JSDeviceMotionEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSDeviceMotionEventPrototype>(vm.heap)) JSDeviceMotionEventPrototype(vm, globalObject, structure); |
| 222 | ptr->finishCreation(vm); |
| 223 | return ptr; |
| 224 | } |
| 225 | |
| 226 | DECLARE_INFO; |
| 227 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
| 228 | { |
| 229 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 230 | } |
| 231 | |
| 232 | private: |
| 233 | JSDeviceMotionEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure) |
| 234 | : JSC::JSNonFinalObject(vm, structure) |
| 235 | { |
| 236 | } |
| 237 | |
| 238 | void finishCreation(JSC::VM&); |
| 239 | }; |
| 240 | |
| 241 | using JSDeviceMotionEventConstructor = JSDOMConstructorNotConstructable<JSDeviceMotionEvent>; |
| 242 | |
| 243 | /* Hash table for constructor */ |
| 244 | |
| 245 | static const HashTableValue JSDeviceMotionEventConstructorTableValues[] = |
| 246 | { |
| 247 | #if ENABLE(DEVICE_ORIENTATION) |
| 248 | { "requestPermission" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDeviceMotionEventConstructorFunctionRequestPermission), (intptr_t) (0) } }, |
| 249 | #else |
| 250 | { 0, 0, NoIntrinsic, { 0, 0 } }, |
| 251 | #endif |
| 252 | }; |
| 253 | |
| 254 | template<> JSValue JSDeviceMotionEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
| 255 | { |
| 256 | return JSEvent::getConstructor(vm, &globalObject); |
| 257 | } |
| 258 | |
| 259 | template<> void JSDeviceMotionEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject) |
| 260 | { |
| 261 | putDirect(vm, vm.propertyNames->prototype, JSDeviceMotionEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 262 | putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("DeviceMotionEvent"_s )), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 263 | putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); |
| 264 | reifyStaticProperties(vm, JSDeviceMotionEvent::info(), JSDeviceMotionEventConstructorTableValues, *this); |
| 265 | #if ENABLE(DEVICE_ORIENTATION) |
| 266 | if (!downcast<Document>(jsCast<JSDOMGlobalObject*>(&globalObject)->scriptExecutionContext())->settings().deviceOrientationPermissionAPIEnabled()) { |
| 267 | auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("requestPermission" ), strlen("requestPermission" )); |
| 268 | VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable); |
| 269 | JSObject::deleteProperty(this, globalObject.globalExec(), propertyName); |
| 270 | } |
| 271 | #endif |
| 272 | } |
| 273 | |
| 274 | template<> const ClassInfo JSDeviceMotionEventConstructor::s_info = { "DeviceMotionEvent" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDeviceMotionEventConstructor) }; |
| 275 | |
| 276 | /* Hash table for prototype */ |
| 277 | |
| 278 | static const HashTableValue JSDeviceMotionEventPrototypeTableValues[] = |
| 279 | { |
| 280 | { "constructor" , static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceMotionEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDeviceMotionEventConstructor) } }, |
| 281 | { "acceleration" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceMotionEventAcceleration), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 282 | { "accelerationIncludingGravity" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceMotionEventAccelerationIncludingGravity), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 283 | { "rotationRate" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceMotionEventRotationRate), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 284 | { "interval" , static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDeviceMotionEventInterval), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }, |
| 285 | { "initDeviceMotionEvent" , static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDeviceMotionEventPrototypeFunctionInitDeviceMotionEvent), (intptr_t) (0) } }, |
| 286 | }; |
| 287 | |
| 288 | const ClassInfo JSDeviceMotionEventPrototype::s_info = { "DeviceMotionEventPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDeviceMotionEventPrototype) }; |
| 289 | |
| 290 | void JSDeviceMotionEventPrototype::finishCreation(VM& vm) |
| 291 | { |
| 292 | Base::finishCreation(vm); |
| 293 | reifyStaticProperties(vm, JSDeviceMotionEvent::info(), JSDeviceMotionEventPrototypeTableValues, *this); |
| 294 | } |
| 295 | |
| 296 | const ClassInfo JSDeviceMotionEvent::s_info = { "DeviceMotionEvent" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDeviceMotionEvent) }; |
| 297 | |
| 298 | JSDeviceMotionEvent::JSDeviceMotionEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DeviceMotionEvent>&& impl) |
| 299 | : JSEvent(structure, globalObject, WTFMove(impl)) |
| 300 | { |
| 301 | } |
| 302 | |
| 303 | void JSDeviceMotionEvent::finishCreation(VM& vm) |
| 304 | { |
| 305 | Base::finishCreation(vm); |
| 306 | ASSERT(inherits(vm, info())); |
| 307 | |
| 308 | } |
| 309 | |
| 310 | JSObject* JSDeviceMotionEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 311 | { |
| 312 | return JSDeviceMotionEventPrototype::create(vm, &globalObject, JSDeviceMotionEventPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject))); |
| 313 | } |
| 314 | |
| 315 | JSObject* JSDeviceMotionEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
| 316 | { |
| 317 | return getDOMPrototype<JSDeviceMotionEvent>(vm, globalObject); |
| 318 | } |
| 319 | |
| 320 | JSValue JSDeviceMotionEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
| 321 | { |
| 322 | return getDOMConstructor<JSDeviceMotionEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
| 323 | } |
| 324 | |
| 325 | template<> inline JSDeviceMotionEvent* IDLAttribute<JSDeviceMotionEvent>::cast(ExecState& state, EncodedJSValue thisValue) |
| 326 | { |
| 327 | return jsDynamicCast<JSDeviceMotionEvent*>(state.vm(), JSValue::decode(thisValue)); |
| 328 | } |
| 329 | |
| 330 | template<> inline JSDeviceMotionEvent* IDLOperation<JSDeviceMotionEvent>::cast(ExecState& state) |
| 331 | { |
| 332 | return jsDynamicCast<JSDeviceMotionEvent*>(state.vm(), state.thisValue()); |
| 333 | } |
| 334 | |
| 335 | EncodedJSValue jsDeviceMotionEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 336 | { |
| 337 | VM& vm = state->vm(); |
| 338 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 339 | auto* prototype = jsDynamicCast<JSDeviceMotionEventPrototype*>(vm, JSValue::decode(thisValue)); |
| 340 | if (UNLIKELY(!prototype)) |
| 341 | return throwVMTypeError(state, throwScope); |
| 342 | return JSValue::encode(JSDeviceMotionEvent::getConstructor(state->vm(), prototype->globalObject())); |
| 343 | } |
| 344 | |
| 345 | bool setJSDeviceMotionEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue) |
| 346 | { |
| 347 | VM& vm = state->vm(); |
| 348 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 349 | auto* prototype = jsDynamicCast<JSDeviceMotionEventPrototype*>(vm, JSValue::decode(thisValue)); |
| 350 | if (UNLIKELY(!prototype)) { |
| 351 | throwVMTypeError(state, throwScope); |
| 352 | return false; |
| 353 | } |
| 354 | // Shadowing a built-in constructor |
| 355 | return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue)); |
| 356 | } |
| 357 | |
| 358 | static inline JSValue jsDeviceMotionEventAccelerationGetter(ExecState& state, JSDeviceMotionEvent& thisObject, ThrowScope& throwScope) |
| 359 | { |
| 360 | UNUSED_PARAM(throwScope); |
| 361 | UNUSED_PARAM(state); |
| 362 | auto& impl = thisObject.wrapped(); |
| 363 | JSValue result = toJS<IDLNullable<IDLDictionary<DeviceMotionEvent::Acceleration>>>(state, *thisObject.globalObject(), throwScope, impl.acceleration()); |
| 364 | return result; |
| 365 | } |
| 366 | |
| 367 | EncodedJSValue jsDeviceMotionEventAcceleration(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 368 | { |
| 369 | return IDLAttribute<JSDeviceMotionEvent>::get<jsDeviceMotionEventAccelerationGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "acceleration" ); |
| 370 | } |
| 371 | |
| 372 | static inline JSValue jsDeviceMotionEventAccelerationIncludingGravityGetter(ExecState& state, JSDeviceMotionEvent& thisObject, ThrowScope& throwScope) |
| 373 | { |
| 374 | UNUSED_PARAM(throwScope); |
| 375 | UNUSED_PARAM(state); |
| 376 | auto& impl = thisObject.wrapped(); |
| 377 | JSValue result = toJS<IDLNullable<IDLDictionary<DeviceMotionEvent::Acceleration>>>(state, *thisObject.globalObject(), throwScope, impl.accelerationIncludingGravity()); |
| 378 | return result; |
| 379 | } |
| 380 | |
| 381 | EncodedJSValue jsDeviceMotionEventAccelerationIncludingGravity(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 382 | { |
| 383 | return IDLAttribute<JSDeviceMotionEvent>::get<jsDeviceMotionEventAccelerationIncludingGravityGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "accelerationIncludingGravity" ); |
| 384 | } |
| 385 | |
| 386 | static inline JSValue jsDeviceMotionEventRotationRateGetter(ExecState& state, JSDeviceMotionEvent& thisObject, ThrowScope& throwScope) |
| 387 | { |
| 388 | UNUSED_PARAM(throwScope); |
| 389 | UNUSED_PARAM(state); |
| 390 | auto& impl = thisObject.wrapped(); |
| 391 | JSValue result = toJS<IDLNullable<IDLDictionary<DeviceMotionEvent::RotationRate>>>(state, *thisObject.globalObject(), throwScope, impl.rotationRate()); |
| 392 | return result; |
| 393 | } |
| 394 | |
| 395 | EncodedJSValue jsDeviceMotionEventRotationRate(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 396 | { |
| 397 | return IDLAttribute<JSDeviceMotionEvent>::get<jsDeviceMotionEventRotationRateGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "rotationRate" ); |
| 398 | } |
| 399 | |
| 400 | static inline JSValue jsDeviceMotionEventIntervalGetter(ExecState& state, JSDeviceMotionEvent& thisObject, ThrowScope& throwScope) |
| 401 | { |
| 402 | UNUSED_PARAM(throwScope); |
| 403 | UNUSED_PARAM(state); |
| 404 | auto& impl = thisObject.wrapped(); |
| 405 | JSValue result = toJS<IDLNullable<IDLUnrestrictedDouble>>(state, throwScope, impl.interval()); |
| 406 | return result; |
| 407 | } |
| 408 | |
| 409 | EncodedJSValue jsDeviceMotionEventInterval(ExecState* state, EncodedJSValue thisValue, PropertyName) |
| 410 | { |
| 411 | return IDLAttribute<JSDeviceMotionEvent>::get<jsDeviceMotionEventIntervalGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "interval" ); |
| 412 | } |
| 413 | |
| 414 | static inline JSC::EncodedJSValue jsDeviceMotionEventPrototypeFunctionInitDeviceMotionEventBody(JSC::ExecState* state, typename IDLOperation<JSDeviceMotionEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope) |
| 415 | { |
| 416 | UNUSED_PARAM(state); |
| 417 | UNUSED_PARAM(throwScope); |
| 418 | auto& impl = castedThis->wrapped(); |
| 419 | auto type = state->argument(0).isUndefined() ? emptyString() : convert<IDLDOMString>(*state, state->uncheckedArgument(0)); |
| 420 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 421 | auto bubbles = convert<IDLBoolean>(*state, state->argument(1)); |
| 422 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 423 | auto cancelable = convert<IDLBoolean>(*state, state->argument(2)); |
| 424 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 425 | auto acceleration = state->argument(3).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLDictionary<DeviceMotionEvent::Acceleration>>>(*state, state->uncheckedArgument(3)); |
| 426 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 427 | auto accelerationIncludingGravity = state->argument(4).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLDictionary<DeviceMotionEvent::Acceleration>>>(*state, state->uncheckedArgument(4)); |
| 428 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 429 | auto rotationRate = state->argument(5).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLDictionary<DeviceMotionEvent::RotationRate>>>(*state, state->uncheckedArgument(5)); |
| 430 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 431 | auto interval = state->argument(6).isUndefined() ? WTF::nullopt : convert<IDLNullable<IDLUnrestrictedDouble>>(*state, state->uncheckedArgument(6)); |
| 432 | RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); |
| 433 | impl.initDeviceMotionEvent(WTFMove(type), WTFMove(bubbles), WTFMove(cancelable), WTFMove(acceleration), WTFMove(accelerationIncludingGravity), WTFMove(rotationRate), WTFMove(interval)); |
| 434 | return JSValue::encode(jsUndefined()); |
| 435 | } |
| 436 | |
| 437 | EncodedJSValue JSC_HOST_CALL jsDeviceMotionEventPrototypeFunctionInitDeviceMotionEvent(ExecState* state) |
| 438 | { |
| 439 | return IDLOperation<JSDeviceMotionEvent>::call<jsDeviceMotionEventPrototypeFunctionInitDeviceMotionEventBody>(*state, "initDeviceMotionEvent" ); |
| 440 | } |
| 441 | |
| 442 | #if ENABLE(DEVICE_ORIENTATION) |
| 443 | static inline JSC::EncodedJSValue jsDeviceMotionEventConstructorFunctionRequestPermissionBody(JSC::ExecState* state, Ref<DeferredPromise>&& promise, JSC::ThrowScope& throwScope) |
| 444 | { |
| 445 | UNUSED_PARAM(state); |
| 446 | UNUSED_PARAM(throwScope); |
| 447 | auto* context = jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())->scriptExecutionContext(); |
| 448 | if (UNLIKELY(!context)) |
| 449 | return JSValue::encode(jsUndefined()); |
| 450 | ASSERT(context->isDocument()); |
| 451 | auto& document = downcast<Document>(*context); |
| 452 | DeviceMotionEvent::requestPermission(document, WTFMove(promise)); |
| 453 | return JSValue::encode(jsUndefined()); |
| 454 | } |
| 455 | |
| 456 | EncodedJSValue JSC_HOST_CALL jsDeviceMotionEventConstructorFunctionRequestPermission(ExecState* state) |
| 457 | { |
| 458 | return IDLOperationReturningPromise<JSDeviceMotionEvent>::callStatic<jsDeviceMotionEventConstructorFunctionRequestPermissionBody, PromiseExecutionScope::WindowOnly>(*state, "requestPermission" ); |
| 459 | } |
| 460 | |
| 461 | #endif |
| 462 | |
| 463 | void JSDeviceMotionEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) |
| 464 | { |
| 465 | auto* thisObject = jsCast<JSDeviceMotionEvent*>(cell); |
| 466 | builder.setWrappedObjectForCell(cell, &thisObject->wrapped()); |
| 467 | if (thisObject->scriptExecutionContext()) |
| 468 | builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string()); |
| 469 | Base::heapSnapshot(cell, builder); |
| 470 | } |
| 471 | |
| 472 | |
| 473 | } |
| 474 | |
| 475 | #endif // ENABLE(DEVICE_ORIENTATION) |
| 476 | |