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