progressevent.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict'
  2. const { webidl } = require('../fetch/webidl')
  3. const kState = Symbol('ProgressEvent state')
  4. /**
  5. * @see https://xhr.spec.whatwg.org/#progressevent
  6. */
  7. class ProgressEvent extends Event {
  8. constructor (type, eventInitDict = {}) {
  9. type = webidl.converters.DOMString(type)
  10. eventInitDict = webidl.converters.ProgressEventInit(eventInitDict ?? {})
  11. super(type, eventInitDict)
  12. this[kState] = {
  13. lengthComputable: eventInitDict.lengthComputable,
  14. loaded: eventInitDict.loaded,
  15. total: eventInitDict.total
  16. }
  17. }
  18. get lengthComputable () {
  19. webidl.brandCheck(this, ProgressEvent)
  20. return this[kState].lengthComputable
  21. }
  22. get loaded () {
  23. webidl.brandCheck(this, ProgressEvent)
  24. return this[kState].loaded
  25. }
  26. get total () {
  27. webidl.brandCheck(this, ProgressEvent)
  28. return this[kState].total
  29. }
  30. }
  31. webidl.converters.ProgressEventInit = webidl.dictionaryConverter([
  32. {
  33. key: 'lengthComputable',
  34. converter: webidl.converters.boolean,
  35. defaultValue: false
  36. },
  37. {
  38. key: 'loaded',
  39. converter: webidl.converters['unsigned long long'],
  40. defaultValue: 0
  41. },
  42. {
  43. key: 'total',
  44. converter: webidl.converters['unsigned long long'],
  45. defaultValue: 0
  46. },
  47. {
  48. key: 'bubbles',
  49. converter: webidl.converters.boolean,
  50. defaultValue: false
  51. },
  52. {
  53. key: 'cancelable',
  54. converter: webidl.converters.boolean,
  55. defaultValue: false
  56. },
  57. {
  58. key: 'composed',
  59. converter: webidl.converters.boolean,
  60. defaultValue: false
  61. }
  62. ])
  63. module.exports = {
  64. ProgressEvent
  65. }