DeviceMotionEventInit.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const DeviceMotionEventAccelerationInit = require("./DeviceMotionEventAccelerationInit.js");
  5. const DeviceMotionEventRotationRateInit = require("./DeviceMotionEventRotationRateInit.js");
  6. const EventInit = require("./EventInit.js");
  7. exports._convertInherit = (globalObject, obj, ret, { context = "The provided value" } = {}) => {
  8. EventInit._convertInherit(globalObject, obj, ret, { context });
  9. {
  10. const key = "acceleration";
  11. let value = obj === undefined || obj === null ? undefined : obj[key];
  12. if (value !== undefined) {
  13. value = DeviceMotionEventAccelerationInit.convert(globalObject, value, {
  14. context: context + " has member 'acceleration' that"
  15. });
  16. ret[key] = value;
  17. }
  18. }
  19. {
  20. const key = "accelerationIncludingGravity";
  21. let value = obj === undefined || obj === null ? undefined : obj[key];
  22. if (value !== undefined) {
  23. value = DeviceMotionEventAccelerationInit.convert(globalObject, value, {
  24. context: context + " has member 'accelerationIncludingGravity' that"
  25. });
  26. ret[key] = value;
  27. }
  28. }
  29. {
  30. const key = "interval";
  31. let value = obj === undefined || obj === null ? undefined : obj[key];
  32. if (value !== undefined) {
  33. value = conversions["double"](value, { context: context + " has member 'interval' that", globals: globalObject });
  34. ret[key] = value;
  35. } else {
  36. ret[key] = 0;
  37. }
  38. }
  39. {
  40. const key = "rotationRate";
  41. let value = obj === undefined || obj === null ? undefined : obj[key];
  42. if (value !== undefined) {
  43. value = DeviceMotionEventRotationRateInit.convert(globalObject, value, {
  44. context: context + " has member 'rotationRate' that"
  45. });
  46. ret[key] = value;
  47. }
  48. }
  49. };
  50. exports.convert = (globalObject, obj, { context = "The provided value" } = {}) => {
  51. if (obj !== undefined && typeof obj !== "object" && typeof obj !== "function") {
  52. throw new globalObject.TypeError(`${context} is not an object.`);
  53. }
  54. const ret = Object.create(null);
  55. exports._convertInherit(globalObject, obj, ret, { context });
  56. return ret;
  57. };