deepv-code 1.0.182 → 1.0.185

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/bundle/dvcode.js +757 -753
  2. package/package.json +1 -1
  3. package/bundle/assets/help/README.md +0 -113
  4. package/bundle/assets/sounds/README.md +0 -74
  5. package/bundle/node_modules/undici/LICENSE +0 -21
  6. package/bundle/node_modules/undici/README.md +0 -472
  7. package/bundle/node_modules/undici/docs/docs/api/Agent.md +0 -83
  8. package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +0 -99
  9. package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +0 -30
  10. package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +0 -151
  11. package/bundle/node_modules/undici/docs/docs/api/Client.md +0 -281
  12. package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +0 -27
  13. package/bundle/node_modules/undici/docs/docs/api/Connector.md +0 -115
  14. package/bundle/node_modules/undici/docs/docs/api/ContentType.md +0 -57
  15. package/bundle/node_modules/undici/docs/docs/api/Cookies.md +0 -101
  16. package/bundle/node_modules/undici/docs/docs/api/Debug.md +0 -62
  17. package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +0 -204
  18. package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +0 -1200
  19. package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +0 -159
  20. package/bundle/node_modules/undici/docs/docs/api/Errors.md +0 -49
  21. package/bundle/node_modules/undici/docs/docs/api/EventSource.md +0 -45
  22. package/bundle/node_modules/undici/docs/docs/api/Fetch.md +0 -52
  23. package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +0 -262
  24. package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +0 -603
  25. package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +0 -197
  26. package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +0 -43
  27. package/bundle/node_modules/undici/docs/docs/api/MockClient.md +0 -77
  28. package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +0 -12
  29. package/bundle/node_modules/undici/docs/docs/api/MockPool.md +0 -548
  30. package/bundle/node_modules/undici/docs/docs/api/Pool.md +0 -84
  31. package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +0 -35
  32. package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +0 -227
  33. package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +0 -96
  34. package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +0 -45
  35. package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +0 -117
  36. package/bundle/node_modules/undici/docs/docs/api/Util.md +0 -25
  37. package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +0 -85
  38. package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +0 -91
  39. package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +0 -64
  40. package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +0 -190
  41. package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +0 -127
  42. package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +0 -20
  43. package/bundle/node_modules/undici/index-fetch.js +0 -35
  44. package/bundle/node_modules/undici/index.d.ts +0 -3
  45. package/bundle/node_modules/undici/index.js +0 -183
  46. package/bundle/node_modules/undici/lib/api/abort-signal.js +0 -59
  47. package/bundle/node_modules/undici/lib/api/api-connect.js +0 -110
  48. package/bundle/node_modules/undici/lib/api/api-pipeline.js +0 -252
  49. package/bundle/node_modules/undici/lib/api/api-request.js +0 -199
  50. package/bundle/node_modules/undici/lib/api/api-stream.js +0 -209
  51. package/bundle/node_modules/undici/lib/api/api-upgrade.js +0 -110
  52. package/bundle/node_modules/undici/lib/api/index.js +0 -7
  53. package/bundle/node_modules/undici/lib/api/readable.js +0 -558
  54. package/bundle/node_modules/undici/lib/api/util.js +0 -95
  55. package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +0 -234
  56. package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +0 -461
  57. package/bundle/node_modules/undici/lib/core/connect.js +0 -164
  58. package/bundle/node_modules/undici/lib/core/constants.js +0 -143
  59. package/bundle/node_modules/undici/lib/core/diagnostics.js +0 -196
  60. package/bundle/node_modules/undici/lib/core/errors.js +0 -244
  61. package/bundle/node_modules/undici/lib/core/request.js +0 -397
  62. package/bundle/node_modules/undici/lib/core/symbols.js +0 -68
  63. package/bundle/node_modules/undici/lib/core/tree.js +0 -160
  64. package/bundle/node_modules/undici/lib/core/util.js +0 -988
  65. package/bundle/node_modules/undici/lib/dispatcher/agent.js +0 -135
  66. package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +0 -206
  67. package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +0 -1615
  68. package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +0 -798
  69. package/bundle/node_modules/undici/lib/dispatcher/client.js +0 -614
  70. package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +0 -161
  71. package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +0 -48
  72. package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +0 -151
  73. package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +0 -159
  74. package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +0 -122
  75. package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +0 -191
  76. package/bundle/node_modules/undici/lib/dispatcher/pool.js +0 -118
  77. package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +0 -275
  78. package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +0 -35
  79. package/bundle/node_modules/undici/lib/global.js +0 -32
  80. package/bundle/node_modules/undici/lib/handler/cache-handler.js +0 -448
  81. package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +0 -124
  82. package/bundle/node_modules/undici/lib/handler/decorator-handler.js +0 -67
  83. package/bundle/node_modules/undici/lib/handler/redirect-handler.js +0 -227
  84. package/bundle/node_modules/undici/lib/handler/retry-handler.js +0 -342
  85. package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +0 -96
  86. package/bundle/node_modules/undici/lib/handler/wrap-handler.js +0 -95
  87. package/bundle/node_modules/undici/lib/interceptor/cache.js +0 -372
  88. package/bundle/node_modules/undici/lib/interceptor/dns.js +0 -432
  89. package/bundle/node_modules/undici/lib/interceptor/dump.js +0 -111
  90. package/bundle/node_modules/undici/lib/interceptor/redirect.js +0 -21
  91. package/bundle/node_modules/undici/lib/interceptor/response-error.js +0 -95
  92. package/bundle/node_modules/undici/lib/interceptor/retry.js +0 -19
  93. package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  94. package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +0 -97
  95. package/bundle/node_modules/undici/lib/llhttp/constants.js +0 -498
  96. package/bundle/node_modules/undici/lib/llhttp/constants.js.map +0 -1
  97. package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +0 -15
  98. package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +0 -15
  99. package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +0 -2
  100. package/bundle/node_modules/undici/lib/llhttp/utils.js +0 -15
  101. package/bundle/node_modules/undici/lib/llhttp/utils.js.map +0 -1
  102. package/bundle/node_modules/undici/lib/mock/mock-agent.js +0 -224
  103. package/bundle/node_modules/undici/lib/mock/mock-call-history.js +0 -248
  104. package/bundle/node_modules/undici/lib/mock/mock-client.js +0 -64
  105. package/bundle/node_modules/undici/lib/mock/mock-errors.js +0 -19
  106. package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +0 -209
  107. package/bundle/node_modules/undici/lib/mock/mock-pool.js +0 -64
  108. package/bundle/node_modules/undici/lib/mock/mock-symbols.js +0 -31
  109. package/bundle/node_modules/undici/lib/mock/mock-utils.js +0 -433
  110. package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +0 -43
  111. package/bundle/node_modules/undici/lib/util/cache.js +0 -368
  112. package/bundle/node_modules/undici/lib/util/date.js +0 -259
  113. package/bundle/node_modules/undici/lib/util/stats.js +0 -32
  114. package/bundle/node_modules/undici/lib/util/timers.js +0 -423
  115. package/bundle/node_modules/undici/lib/web/cache/cache.js +0 -862
  116. package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +0 -152
  117. package/bundle/node_modules/undici/lib/web/cache/util.js +0 -45
  118. package/bundle/node_modules/undici/lib/web/cookies/constants.js +0 -12
  119. package/bundle/node_modules/undici/lib/web/cookies/index.js +0 -199
  120. package/bundle/node_modules/undici/lib/web/cookies/parse.js +0 -322
  121. package/bundle/node_modules/undici/lib/web/cookies/util.js +0 -282
  122. package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +0 -399
  123. package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +0 -484
  124. package/bundle/node_modules/undici/lib/web/eventsource/util.js +0 -37
  125. package/bundle/node_modules/undici/lib/web/fetch/LICENSE +0 -21
  126. package/bundle/node_modules/undici/lib/web/fetch/body.js +0 -532
  127. package/bundle/node_modules/undici/lib/web/fetch/constants.js +0 -131
  128. package/bundle/node_modules/undici/lib/web/fetch/data-url.js +0 -744
  129. package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +0 -46
  130. package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +0 -501
  131. package/bundle/node_modules/undici/lib/web/fetch/formdata.js +0 -263
  132. package/bundle/node_modules/undici/lib/web/fetch/global.js +0 -40
  133. package/bundle/node_modules/undici/lib/web/fetch/headers.js +0 -719
  134. package/bundle/node_modules/undici/lib/web/fetch/index.js +0 -2258
  135. package/bundle/node_modules/undici/lib/web/fetch/request.js +0 -1099
  136. package/bundle/node_modules/undici/lib/web/fetch/response.js +0 -636
  137. package/bundle/node_modules/undici/lib/web/fetch/util.js +0 -1782
  138. package/bundle/node_modules/undici/lib/web/fetch/webidl.js +0 -740
  139. package/bundle/node_modules/undici/lib/web/websocket/connection.js +0 -325
  140. package/bundle/node_modules/undici/lib/web/websocket/constants.js +0 -126
  141. package/bundle/node_modules/undici/lib/web/websocket/events.js +0 -331
  142. package/bundle/node_modules/undici/lib/web/websocket/frame.js +0 -138
  143. package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +0 -70
  144. package/bundle/node_modules/undici/lib/web/websocket/receiver.js +0 -454
  145. package/bundle/node_modules/undici/lib/web/websocket/sender.js +0 -109
  146. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +0 -83
  147. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +0 -485
  148. package/bundle/node_modules/undici/lib/web/websocket/util.js +0 -338
  149. package/bundle/node_modules/undici/lib/web/websocket/websocket.js +0 -686
  150. package/bundle/node_modules/undici/package.json +0 -149
  151. package/bundle/node_modules/undici/scripts/strip-comments.js +0 -10
  152. package/bundle/node_modules/undici/types/README.md +0 -6
  153. package/bundle/node_modules/undici/types/agent.d.ts +0 -35
  154. package/bundle/node_modules/undici/types/api.d.ts +0 -43
  155. package/bundle/node_modules/undici/types/balanced-pool.d.ts +0 -29
  156. package/bundle/node_modules/undici/types/cache-interceptor.d.ts +0 -172
  157. package/bundle/node_modules/undici/types/cache.d.ts +0 -36
  158. package/bundle/node_modules/undici/types/client-stats.d.ts +0 -15
  159. package/bundle/node_modules/undici/types/client.d.ts +0 -110
  160. package/bundle/node_modules/undici/types/connector.d.ts +0 -34
  161. package/bundle/node_modules/undici/types/content-type.d.ts +0 -21
  162. package/bundle/node_modules/undici/types/cookies.d.ts +0 -30
  163. package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +0 -66
  164. package/bundle/node_modules/undici/types/dispatcher.d.ts +0 -281
  165. package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +0 -21
  166. package/bundle/node_modules/undici/types/errors.d.ts +0 -171
  167. package/bundle/node_modules/undici/types/eventsource.d.ts +0 -61
  168. package/bundle/node_modules/undici/types/fetch.d.ts +0 -210
  169. package/bundle/node_modules/undici/types/formdata.d.ts +0 -108
  170. package/bundle/node_modules/undici/types/global-dispatcher.d.ts +0 -9
  171. package/bundle/node_modules/undici/types/global-origin.d.ts +0 -7
  172. package/bundle/node_modules/undici/types/h2c-client.d.ts +0 -75
  173. package/bundle/node_modules/undici/types/handlers.d.ts +0 -15
  174. package/bundle/node_modules/undici/types/header.d.ts +0 -160
  175. package/bundle/node_modules/undici/types/index.d.ts +0 -75
  176. package/bundle/node_modules/undici/types/interceptors.d.ts +0 -34
  177. package/bundle/node_modules/undici/types/mock-agent.d.ts +0 -68
  178. package/bundle/node_modules/undici/types/mock-call-history.d.ts +0 -111
  179. package/bundle/node_modules/undici/types/mock-client.d.ts +0 -25
  180. package/bundle/node_modules/undici/types/mock-errors.d.ts +0 -12
  181. package/bundle/node_modules/undici/types/mock-interceptor.d.ts +0 -93
  182. package/bundle/node_modules/undici/types/mock-pool.d.ts +0 -25
  183. package/bundle/node_modules/undici/types/patch.d.ts +0 -29
  184. package/bundle/node_modules/undici/types/pool-stats.d.ts +0 -19
  185. package/bundle/node_modules/undici/types/pool.d.ts +0 -41
  186. package/bundle/node_modules/undici/types/proxy-agent.d.ts +0 -29
  187. package/bundle/node_modules/undici/types/readable.d.ts +0 -68
  188. package/bundle/node_modules/undici/types/retry-agent.d.ts +0 -8
  189. package/bundle/node_modules/undici/types/retry-handler.d.ts +0 -116
  190. package/bundle/node_modules/undici/types/util.d.ts +0 -18
  191. package/bundle/node_modules/undici/types/utility.d.ts +0 -7
  192. package/bundle/node_modules/undici/types/webidl.d.ts +0 -266
  193. package/bundle/node_modules/undici/types/websocket.d.ts +0 -184
@@ -1,740 +0,0 @@
1
- 'use strict'
2
-
3
- const { types, inspect } = require('node:util')
4
- const { markAsUncloneable } = require('node:worker_threads')
5
- const { toUSVString } = require('../../core/util')
6
-
7
- const UNDEFINED = 1
8
- const BOOLEAN = 2
9
- const STRING = 3
10
- const SYMBOL = 4
11
- const NUMBER = 5
12
- const BIGINT = 6
13
- const NULL = 7
14
- const OBJECT = 8 // function and object
15
-
16
- const FunctionPrototypeSymbolHasInstance = Function.call.bind(Function.prototype[Symbol.hasInstance])
17
-
18
- /** @type {import('../../../types/webidl').Webidl} */
19
- const webidl = {
20
- converters: {},
21
- util: {},
22
- errors: {},
23
- is: {}
24
- }
25
-
26
- webidl.errors.exception = function (message) {
27
- return new TypeError(`${message.header}: ${message.message}`)
28
- }
29
-
30
- webidl.errors.conversionFailed = function (context) {
31
- const plural = context.types.length === 1 ? '' : ' one of'
32
- const message =
33
- `${context.argument} could not be converted to` +
34
- `${plural}: ${context.types.join(', ')}.`
35
-
36
- return webidl.errors.exception({
37
- header: context.prefix,
38
- message
39
- })
40
- }
41
-
42
- webidl.errors.invalidArgument = function (context) {
43
- return webidl.errors.exception({
44
- header: context.prefix,
45
- message: `"${context.value}" is an invalid ${context.type}.`
46
- })
47
- }
48
-
49
- // https://webidl.spec.whatwg.org/#implements
50
- webidl.brandCheck = function (V, I) {
51
- if (!FunctionPrototypeSymbolHasInstance(I, V)) {
52
- const err = new TypeError('Illegal invocation')
53
- err.code = 'ERR_INVALID_THIS' // node compat.
54
- throw err
55
- }
56
- }
57
-
58
- webidl.brandCheckMultiple = function (List) {
59
- const prototypes = List.map((c) => webidl.util.MakeTypeAssertion(c))
60
-
61
- return (V) => {
62
- if (prototypes.every(typeCheck => !typeCheck(V))) {
63
- const err = new TypeError('Illegal invocation')
64
- err.code = 'ERR_INVALID_THIS' // node compat.
65
- throw err
66
- }
67
- }
68
- }
69
-
70
- webidl.argumentLengthCheck = function ({ length }, min, ctx) {
71
- if (length < min) {
72
- throw webidl.errors.exception({
73
- message: `${min} argument${min !== 1 ? 's' : ''} required, ` +
74
- `but${length ? ' only' : ''} ${length} found.`,
75
- header: ctx
76
- })
77
- }
78
- }
79
-
80
- webidl.illegalConstructor = function () {
81
- throw webidl.errors.exception({
82
- header: 'TypeError',
83
- message: 'Illegal constructor'
84
- })
85
- }
86
-
87
- webidl.util.MakeTypeAssertion = function (I) {
88
- return (O) => FunctionPrototypeSymbolHasInstance(I, O)
89
- }
90
-
91
- // https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values
92
- webidl.util.Type = function (V) {
93
- switch (typeof V) {
94
- case 'undefined': return UNDEFINED
95
- case 'boolean': return BOOLEAN
96
- case 'string': return STRING
97
- case 'symbol': return SYMBOL
98
- case 'number': return NUMBER
99
- case 'bigint': return BIGINT
100
- case 'function':
101
- case 'object': {
102
- if (V === null) {
103
- return NULL
104
- }
105
-
106
- return OBJECT
107
- }
108
- }
109
- }
110
-
111
- webidl.util.Types = {
112
- UNDEFINED,
113
- BOOLEAN,
114
- STRING,
115
- SYMBOL,
116
- NUMBER,
117
- BIGINT,
118
- NULL,
119
- OBJECT
120
- }
121
-
122
- webidl.util.TypeValueToString = function (o) {
123
- switch (webidl.util.Type(o)) {
124
- case UNDEFINED: return 'Undefined'
125
- case BOOLEAN: return 'Boolean'
126
- case STRING: return 'String'
127
- case SYMBOL: return 'Symbol'
128
- case NUMBER: return 'Number'
129
- case BIGINT: return 'BigInt'
130
- case NULL: return 'Null'
131
- case OBJECT: return 'Object'
132
- }
133
- }
134
-
135
- webidl.util.markAsUncloneable = markAsUncloneable || (() => {})
136
-
137
- // https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
138
- webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) {
139
- let upperBound
140
- let lowerBound
141
-
142
- // 1. If bitLength is 64, then:
143
- if (bitLength === 64) {
144
- // 1. Let upperBound be 2^53 − 1.
145
- upperBound = Math.pow(2, 53) - 1
146
-
147
- // 2. If signedness is "unsigned", then let lowerBound be 0.
148
- if (signedness === 'unsigned') {
149
- lowerBound = 0
150
- } else {
151
- // 3. Otherwise let lowerBound be −2^53 + 1.
152
- lowerBound = Math.pow(-2, 53) + 1
153
- }
154
- } else if (signedness === 'unsigned') {
155
- // 2. Otherwise, if signedness is "unsigned", then:
156
-
157
- // 1. Let lowerBound be 0.
158
- lowerBound = 0
159
-
160
- // 2. Let upperBound be 2^bitLength − 1.
161
- upperBound = Math.pow(2, bitLength) - 1
162
- } else {
163
- // 3. Otherwise:
164
-
165
- // 1. Let lowerBound be -2^bitLength − 1.
166
- lowerBound = Math.pow(-2, bitLength) - 1
167
-
168
- // 2. Let upperBound be 2^bitLength − 1 − 1.
169
- upperBound = Math.pow(2, bitLength - 1) - 1
170
- }
171
-
172
- // 4. Let x be ? ToNumber(V).
173
- let x = Number(V)
174
-
175
- // 5. If x is −0, then set x to +0.
176
- if (x === 0) {
177
- x = 0
178
- }
179
-
180
- // 6. If the conversion is to an IDL type associated
181
- // with the [EnforceRange] extended attribute, then:
182
- if (opts?.enforceRange === true) {
183
- // 1. If x is NaN, +∞, or −∞, then throw a TypeError.
184
- if (
185
- Number.isNaN(x) ||
186
- x === Number.POSITIVE_INFINITY ||
187
- x === Number.NEGATIVE_INFINITY
188
- ) {
189
- throw webidl.errors.exception({
190
- header: 'Integer conversion',
191
- message: `Could not convert ${webidl.util.Stringify(V)} to an integer.`
192
- })
193
- }
194
-
195
- // 2. Set x to IntegerPart(x).
196
- x = webidl.util.IntegerPart(x)
197
-
198
- // 3. If x < lowerBound or x > upperBound, then
199
- // throw a TypeError.
200
- if (x < lowerBound || x > upperBound) {
201
- throw webidl.errors.exception({
202
- header: 'Integer conversion',
203
- message: `Value must be between ${lowerBound}-${upperBound}, got ${x}.`
204
- })
205
- }
206
-
207
- // 4. Return x.
208
- return x
209
- }
210
-
211
- // 7. If x is not NaN and the conversion is to an IDL
212
- // type associated with the [Clamp] extended
213
- // attribute, then:
214
- if (!Number.isNaN(x) && opts?.clamp === true) {
215
- // 1. Set x to min(max(x, lowerBound), upperBound).
216
- x = Math.min(Math.max(x, lowerBound), upperBound)
217
-
218
- // 2. Round x to the nearest integer, choosing the
219
- // even integer if it lies halfway between two,
220
- // and choosing +0 rather than −0.
221
- if (Math.floor(x) % 2 === 0) {
222
- x = Math.floor(x)
223
- } else {
224
- x = Math.ceil(x)
225
- }
226
-
227
- // 3. Return x.
228
- return x
229
- }
230
-
231
- // 8. If x is NaN, +0, +∞, or −∞, then return +0.
232
- if (
233
- Number.isNaN(x) ||
234
- (x === 0 && Object.is(0, x)) ||
235
- x === Number.POSITIVE_INFINITY ||
236
- x === Number.NEGATIVE_INFINITY
237
- ) {
238
- return 0
239
- }
240
-
241
- // 9. Set x to IntegerPart(x).
242
- x = webidl.util.IntegerPart(x)
243
-
244
- // 10. Set x to x modulo 2^bitLength.
245
- x = x % Math.pow(2, bitLength)
246
-
247
- // 11. If signedness is "signed" and x ≥ 2^bitLength − 1,
248
- // then return x − 2^bitLength.
249
- if (signedness === 'signed' && x >= Math.pow(2, bitLength) - 1) {
250
- return x - Math.pow(2, bitLength)
251
- }
252
-
253
- // 12. Otherwise, return x.
254
- return x
255
- }
256
-
257
- // https://webidl.spec.whatwg.org/#abstract-opdef-integerpart
258
- webidl.util.IntegerPart = function (n) {
259
- // 1. Let r be floor(abs(n)).
260
- const r = Math.floor(Math.abs(n))
261
-
262
- // 2. If n < 0, then return -1 × r.
263
- if (n < 0) {
264
- return -1 * r
265
- }
266
-
267
- // 3. Otherwise, return r.
268
- return r
269
- }
270
-
271
- webidl.util.Stringify = function (V) {
272
- const type = webidl.util.Type(V)
273
-
274
- switch (type) {
275
- case SYMBOL:
276
- return `Symbol(${V.description})`
277
- case OBJECT:
278
- return inspect(V)
279
- case STRING:
280
- return `"${V}"`
281
- default:
282
- return `${V}`
283
- }
284
- }
285
-
286
- // https://webidl.spec.whatwg.org/#es-sequence
287
- webidl.sequenceConverter = function (converter) {
288
- return (V, prefix, argument, Iterable) => {
289
- // 1. If Type(V) is not Object, throw a TypeError.
290
- if (webidl.util.Type(V) !== OBJECT) {
291
- throw webidl.errors.exception({
292
- header: prefix,
293
- message: `${argument} (${webidl.util.Stringify(V)}) is not iterable.`
294
- })
295
- }
296
-
297
- // 2. Let method be ? GetMethod(V, @@iterator).
298
- /** @type {Generator} */
299
- const method = typeof Iterable === 'function' ? Iterable() : V?.[Symbol.iterator]?.()
300
- const seq = []
301
- let index = 0
302
-
303
- // 3. If method is undefined, throw a TypeError.
304
- if (
305
- method === undefined ||
306
- typeof method.next !== 'function'
307
- ) {
308
- throw webidl.errors.exception({
309
- header: prefix,
310
- message: `${argument} is not iterable.`
311
- })
312
- }
313
-
314
- // https://webidl.spec.whatwg.org/#create-sequence-from-iterable
315
- while (true) {
316
- const { done, value } = method.next()
317
-
318
- if (done) {
319
- break
320
- }
321
-
322
- seq.push(converter(value, prefix, `${argument}[${index++}]`))
323
- }
324
-
325
- return seq
326
- }
327
- }
328
-
329
- // https://webidl.spec.whatwg.org/#es-to-record
330
- webidl.recordConverter = function (keyConverter, valueConverter) {
331
- return (O, prefix, argument) => {
332
- // 1. If Type(O) is not Object, throw a TypeError.
333
- if (webidl.util.Type(O) !== OBJECT) {
334
- throw webidl.errors.exception({
335
- header: prefix,
336
- message: `${argument} ("${webidl.util.TypeValueToString(O)}") is not an Object.`
337
- })
338
- }
339
-
340
- // 2. Let result be a new empty instance of record<K, V>.
341
- const result = {}
342
-
343
- if (!types.isProxy(O)) {
344
- // 1. Let desc be ? O.[[GetOwnProperty]](key).
345
- const keys = [...Object.getOwnPropertyNames(O), ...Object.getOwnPropertySymbols(O)]
346
-
347
- for (const key of keys) {
348
- const keyName = webidl.util.Stringify(key)
349
-
350
- // 1. Let typedKey be key converted to an IDL value of type K.
351
- const typedKey = keyConverter(key, prefix, `Key ${keyName} in ${argument}`)
352
-
353
- // 2. Let value be ? Get(O, key).
354
- // 3. Let typedValue be value converted to an IDL value of type V.
355
- const typedValue = valueConverter(O[key], prefix, `${argument}[${keyName}]`)
356
-
357
- // 4. Set result[typedKey] to typedValue.
358
- result[typedKey] = typedValue
359
- }
360
-
361
- // 5. Return result.
362
- return result
363
- }
364
-
365
- // 3. Let keys be ? O.[[OwnPropertyKeys]]().
366
- const keys = Reflect.ownKeys(O)
367
-
368
- // 4. For each key of keys.
369
- for (const key of keys) {
370
- // 1. Let desc be ? O.[[GetOwnProperty]](key).
371
- const desc = Reflect.getOwnPropertyDescriptor(O, key)
372
-
373
- // 2. If desc is not undefined and desc.[[Enumerable]] is true:
374
- if (desc?.enumerable) {
375
- // 1. Let typedKey be key converted to an IDL value of type K.
376
- const typedKey = keyConverter(key, prefix, argument)
377
-
378
- // 2. Let value be ? Get(O, key).
379
- // 3. Let typedValue be value converted to an IDL value of type V.
380
- const typedValue = valueConverter(O[key], prefix, argument)
381
-
382
- // 4. Set result[typedKey] to typedValue.
383
- result[typedKey] = typedValue
384
- }
385
- }
386
-
387
- // 5. Return result.
388
- return result
389
- }
390
- }
391
-
392
- webidl.interfaceConverter = function (TypeCheck, name) {
393
- return (V, prefix, argument) => {
394
- if (!TypeCheck(V)) {
395
- throw webidl.errors.exception({
396
- header: prefix,
397
- message: `Expected ${argument} ("${webidl.util.Stringify(V)}") to be an instance of ${name}.`
398
- })
399
- }
400
-
401
- return V
402
- }
403
- }
404
-
405
- webidl.dictionaryConverter = function (converters) {
406
- return (dictionary, prefix, argument) => {
407
- const dict = {}
408
-
409
- if (dictionary != null && webidl.util.Type(dictionary) !== OBJECT) {
410
- throw webidl.errors.exception({
411
- header: prefix,
412
- message: `Expected ${dictionary} to be one of: Null, Undefined, Object.`
413
- })
414
- }
415
-
416
- for (const options of converters) {
417
- const { key, defaultValue, required, converter } = options
418
-
419
- if (required === true) {
420
- if (dictionary == null || !Object.hasOwn(dictionary, key)) {
421
- throw webidl.errors.exception({
422
- header: prefix,
423
- message: `Missing required key "${key}".`
424
- })
425
- }
426
- }
427
-
428
- let value = dictionary?.[key]
429
- const hasDefault = defaultValue !== undefined
430
-
431
- // Only use defaultValue if value is undefined and
432
- // a defaultValue options was provided.
433
- if (hasDefault && value === undefined) {
434
- value = defaultValue()
435
- }
436
-
437
- // A key can be optional and have no default value.
438
- // When this happens, do not perform a conversion,
439
- // and do not assign the key a value.
440
- if (required || hasDefault || value !== undefined) {
441
- value = converter(value, prefix, `${argument}.${key}`)
442
-
443
- if (
444
- options.allowedValues &&
445
- !options.allowedValues.includes(value)
446
- ) {
447
- throw webidl.errors.exception({
448
- header: prefix,
449
- message: `${value} is not an accepted type. Expected one of ${options.allowedValues.join(', ')}.`
450
- })
451
- }
452
-
453
- dict[key] = value
454
- }
455
- }
456
-
457
- return dict
458
- }
459
- }
460
-
461
- webidl.nullableConverter = function (converter) {
462
- return (V, prefix, argument) => {
463
- if (V === null) {
464
- return V
465
- }
466
-
467
- return converter(V, prefix, argument)
468
- }
469
- }
470
-
471
- webidl.is.ReadableStream = webidl.util.MakeTypeAssertion(ReadableStream)
472
- webidl.is.Blob = webidl.util.MakeTypeAssertion(Blob)
473
- webidl.is.URLSearchParams = webidl.util.MakeTypeAssertion(URLSearchParams)
474
- webidl.is.File = webidl.util.MakeTypeAssertion(globalThis.File ?? require('node:buffer').File)
475
- webidl.is.URL = webidl.util.MakeTypeAssertion(URL)
476
- webidl.is.AbortSignal = webidl.util.MakeTypeAssertion(AbortSignal)
477
- webidl.is.MessagePort = webidl.util.MakeTypeAssertion(MessagePort)
478
-
479
- // https://webidl.spec.whatwg.org/#es-DOMString
480
- webidl.converters.DOMString = function (V, prefix, argument, opts) {
481
- // 1. If V is null and the conversion is to an IDL type
482
- // associated with the [LegacyNullToEmptyString]
483
- // extended attribute, then return the DOMString value
484
- // that represents the empty string.
485
- if (V === null && opts?.legacyNullToEmptyString) {
486
- return ''
487
- }
488
-
489
- // 2. Let x be ? ToString(V).
490
- if (typeof V === 'symbol') {
491
- throw webidl.errors.exception({
492
- header: prefix,
493
- message: `${argument} is a symbol, which cannot be converted to a DOMString.`
494
- })
495
- }
496
-
497
- // 3. Return the IDL DOMString value that represents the
498
- // same sequence of code units as the one the
499
- // ECMAScript String value x represents.
500
- return String(V)
501
- }
502
-
503
- // https://webidl.spec.whatwg.org/#es-ByteString
504
- webidl.converters.ByteString = function (V, prefix, argument) {
505
- // 1. Let x be ? ToString(V).
506
- if (typeof V === 'symbol') {
507
- throw webidl.errors.exception({
508
- header: prefix,
509
- message: `${argument} is a symbol, which cannot be converted to a ByteString.`
510
- })
511
- }
512
-
513
- const x = String(V)
514
-
515
- // 2. If the value of any element of x is greater than
516
- // 255, then throw a TypeError.
517
- for (let index = 0; index < x.length; index++) {
518
- if (x.charCodeAt(index) > 255) {
519
- throw new TypeError(
520
- 'Cannot convert argument to a ByteString because the character at ' +
521
- `index ${index} has a value of ${x.charCodeAt(index)} which is greater than 255.`
522
- )
523
- }
524
- }
525
-
526
- // 3. Return an IDL ByteString value whose length is the
527
- // length of x, and where the value of each element is
528
- // the value of the corresponding element of x.
529
- return x
530
- }
531
-
532
- // https://webidl.spec.whatwg.org/#es-USVString
533
- // TODO: rewrite this so we can control the errors thrown
534
- webidl.converters.USVString = toUSVString
535
-
536
- // https://webidl.spec.whatwg.org/#es-boolean
537
- webidl.converters.boolean = function (V) {
538
- // 1. Let x be the result of computing ToBoolean(V).
539
- const x = Boolean(V)
540
-
541
- // 2. Return the IDL boolean value that is the one that represents
542
- // the same truth value as the ECMAScript Boolean value x.
543
- return x
544
- }
545
-
546
- // https://webidl.spec.whatwg.org/#es-any
547
- webidl.converters.any = function (V) {
548
- return V
549
- }
550
-
551
- // https://webidl.spec.whatwg.org/#es-long-long
552
- webidl.converters['long long'] = function (V, prefix, argument) {
553
- // 1. Let x be ? ConvertToInt(V, 64, "signed").
554
- const x = webidl.util.ConvertToInt(V, 64, 'signed', undefined, prefix, argument)
555
-
556
- // 2. Return the IDL long long value that represents
557
- // the same numeric value as x.
558
- return x
559
- }
560
-
561
- // https://webidl.spec.whatwg.org/#es-unsigned-long-long
562
- webidl.converters['unsigned long long'] = function (V, prefix, argument) {
563
- // 1. Let x be ? ConvertToInt(V, 64, "unsigned").
564
- const x = webidl.util.ConvertToInt(V, 64, 'unsigned', undefined, prefix, argument)
565
-
566
- // 2. Return the IDL unsigned long long value that
567
- // represents the same numeric value as x.
568
- return x
569
- }
570
-
571
- // https://webidl.spec.whatwg.org/#es-unsigned-long
572
- webidl.converters['unsigned long'] = function (V, prefix, argument) {
573
- // 1. Let x be ? ConvertToInt(V, 32, "unsigned").
574
- const x = webidl.util.ConvertToInt(V, 32, 'unsigned', undefined, prefix, argument)
575
-
576
- // 2. Return the IDL unsigned long value that
577
- // represents the same numeric value as x.
578
- return x
579
- }
580
-
581
- // https://webidl.spec.whatwg.org/#es-unsigned-short
582
- webidl.converters['unsigned short'] = function (V, prefix, argument, opts) {
583
- // 1. Let x be ? ConvertToInt(V, 16, "unsigned").
584
- const x = webidl.util.ConvertToInt(V, 16, 'unsigned', opts, prefix, argument)
585
-
586
- // 2. Return the IDL unsigned short value that represents
587
- // the same numeric value as x.
588
- return x
589
- }
590
-
591
- // https://webidl.spec.whatwg.org/#idl-ArrayBuffer
592
- webidl.converters.ArrayBuffer = function (V, prefix, argument, opts) {
593
- // 1. If Type(V) is not Object, or V does not have an
594
- // [[ArrayBufferData]] internal slot, then throw a
595
- // TypeError.
596
- // see: https://tc39.es/ecma262/#sec-properties-of-the-arraybuffer-instances
597
- // see: https://tc39.es/ecma262/#sec-properties-of-the-sharedarraybuffer-instances
598
- if (
599
- webidl.util.Type(V) !== OBJECT ||
600
- !types.isAnyArrayBuffer(V)
601
- ) {
602
- throw webidl.errors.conversionFailed({
603
- prefix,
604
- argument: `${argument} ("${webidl.util.Stringify(V)}")`,
605
- types: ['ArrayBuffer']
606
- })
607
- }
608
-
609
- // 2. If the conversion is not to an IDL type associated
610
- // with the [AllowShared] extended attribute, and
611
- // IsSharedArrayBuffer(V) is true, then throw a
612
- // TypeError.
613
- if (opts?.allowShared === false && types.isSharedArrayBuffer(V)) {
614
- throw webidl.errors.exception({
615
- header: 'ArrayBuffer',
616
- message: 'SharedArrayBuffer is not allowed.'
617
- })
618
- }
619
-
620
- // 3. If the conversion is not to an IDL type associated
621
- // with the [AllowResizable] extended attribute, and
622
- // IsResizableArrayBuffer(V) is true, then throw a
623
- // TypeError.
624
- if (V.resizable || V.growable) {
625
- throw webidl.errors.exception({
626
- header: 'ArrayBuffer',
627
- message: 'Received a resizable ArrayBuffer.'
628
- })
629
- }
630
-
631
- // 4. Return the IDL ArrayBuffer value that is a
632
- // reference to the same object as V.
633
- return V
634
- }
635
-
636
- webidl.converters.TypedArray = function (V, T, prefix, name, opts) {
637
- // 1. Let T be the IDL type V is being converted to.
638
-
639
- // 2. If Type(V) is not Object, or V does not have a
640
- // [[TypedArrayName]] internal slot with a value
641
- // equal to T’s name, then throw a TypeError.
642
- if (
643
- webidl.util.Type(V) !== OBJECT ||
644
- !types.isTypedArray(V) ||
645
- V.constructor.name !== T.name
646
- ) {
647
- throw webidl.errors.conversionFailed({
648
- prefix,
649
- argument: `${name} ("${webidl.util.Stringify(V)}")`,
650
- types: [T.name]
651
- })
652
- }
653
-
654
- // 3. If the conversion is not to an IDL type associated
655
- // with the [AllowShared] extended attribute, and
656
- // IsSharedArrayBuffer(V.[[ViewedArrayBuffer]]) is
657
- // true, then throw a TypeError.
658
- if (opts?.allowShared === false && types.isSharedArrayBuffer(V.buffer)) {
659
- throw webidl.errors.exception({
660
- header: 'ArrayBuffer',
661
- message: 'SharedArrayBuffer is not allowed.'
662
- })
663
- }
664
-
665
- // 4. If the conversion is not to an IDL type associated
666
- // with the [AllowResizable] extended attribute, and
667
- // IsResizableArrayBuffer(V.[[ViewedArrayBuffer]]) is
668
- // true, then throw a TypeError.
669
- if (V.buffer.resizable || V.buffer.growable) {
670
- throw webidl.errors.exception({
671
- header: 'ArrayBuffer',
672
- message: 'Received a resizable ArrayBuffer.'
673
- })
674
- }
675
-
676
- // 5. Return the IDL value of type T that is a reference
677
- // to the same object as V.
678
- return V
679
- }
680
-
681
- webidl.converters.DataView = function (V, prefix, name, opts) {
682
- // 1. If Type(V) is not Object, or V does not have a
683
- // [[DataView]] internal slot, then throw a TypeError.
684
- if (webidl.util.Type(V) !== OBJECT || !types.isDataView(V)) {
685
- throw webidl.errors.exception({
686
- header: prefix,
687
- message: `${name} is not a DataView.`
688
- })
689
- }
690
-
691
- // 2. If the conversion is not to an IDL type associated
692
- // with the [AllowShared] extended attribute, and
693
- // IsSharedArrayBuffer(V.[[ViewedArrayBuffer]]) is true,
694
- // then throw a TypeError.
695
- if (opts?.allowShared === false && types.isSharedArrayBuffer(V.buffer)) {
696
- throw webidl.errors.exception({
697
- header: 'ArrayBuffer',
698
- message: 'SharedArrayBuffer is not allowed.'
699
- })
700
- }
701
-
702
- // 3. If the conversion is not to an IDL type associated
703
- // with the [AllowResizable] extended attribute, and
704
- // IsResizableArrayBuffer(V.[[ViewedArrayBuffer]]) is
705
- // true, then throw a TypeError.
706
- if (V.buffer.resizable || V.buffer.growable) {
707
- throw webidl.errors.exception({
708
- header: 'ArrayBuffer',
709
- message: 'Received a resizable ArrayBuffer.'
710
- })
711
- }
712
-
713
- // 4. Return the IDL DataView value that is a reference
714
- // to the same object as V.
715
- return V
716
- }
717
-
718
- webidl.converters['sequence<ByteString>'] = webidl.sequenceConverter(
719
- webidl.converters.ByteString
720
- )
721
-
722
- webidl.converters['sequence<sequence<ByteString>>'] = webidl.sequenceConverter(
723
- webidl.converters['sequence<ByteString>']
724
- )
725
-
726
- webidl.converters['record<ByteString, ByteString>'] = webidl.recordConverter(
727
- webidl.converters.ByteString,
728
- webidl.converters.ByteString
729
- )
730
-
731
- webidl.converters.Blob = webidl.interfaceConverter(webidl.is.Blob, 'Blob')
732
-
733
- webidl.converters.AbortSignal = webidl.interfaceConverter(
734
- webidl.is.AbortSignal,
735
- 'AbortSignal'
736
- )
737
-
738
- module.exports = {
739
- webidl
740
- }