deepv-code 1.0.182

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 (223) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +3 -0
  3. package/bundle/assets/help/README.md +113 -0
  4. package/bundle/assets/help/cli-help-knowledge.md +1382 -0
  5. package/bundle/assets/sounds/README.md +74 -0
  6. package/bundle/assets/sounds/confirmation-required.wav +0 -0
  7. package/bundle/assets/sounds/response-complete.wav +0 -0
  8. package/bundle/assets/sounds/selection-made.wav +0 -0
  9. package/bundle/dvcode.js +4442 -0
  10. package/bundle/fix-binary-permissions.js +215 -0
  11. package/bundle/login/templates/authSelectPage.html +870 -0
  12. package/bundle/login/templates/deepv.ico +0 -0
  13. package/bundle/login/templates/feishu.ico +0 -0
  14. package/bundle/node_modules/@vscode/ripgrep/bin/darwin-arm64-rg +0 -0
  15. package/bundle/node_modules/@vscode/ripgrep/bin/darwin-x64-rg +0 -0
  16. package/bundle/node_modules/@vscode/ripgrep/bin/linux-arm-rg +0 -0
  17. package/bundle/node_modules/@vscode/ripgrep/bin/linux-arm64-rg +0 -0
  18. package/bundle/node_modules/@vscode/ripgrep/bin/linux-x64-rg +0 -0
  19. package/bundle/node_modules/@vscode/ripgrep/bin/rg.exe +0 -0
  20. package/bundle/node_modules/@vscode/ripgrep/bin/win32-arm64-rg.exe +0 -0
  21. package/bundle/node_modules/@vscode/ripgrep/bin/win32-ia32-rg.exe +0 -0
  22. package/bundle/node_modules/@vscode/ripgrep/bin/win32-x64-rg.exe +0 -0
  23. package/bundle/node_modules/@vscode/ripgrep/lib/download.js +357 -0
  24. package/bundle/node_modules/@vscode/ripgrep/lib/index.d.ts +1 -0
  25. package/bundle/node_modules/@vscode/ripgrep/lib/index.js +42 -0
  26. package/bundle/node_modules/@vscode/ripgrep/lib/postinstall.js +121 -0
  27. package/bundle/node_modules/@vscode/ripgrep/package.json +24 -0
  28. package/bundle/node_modules/undici/LICENSE +21 -0
  29. package/bundle/node_modules/undici/README.md +472 -0
  30. package/bundle/node_modules/undici/docs/docs/api/Agent.md +83 -0
  31. package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
  32. package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
  33. package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +151 -0
  34. package/bundle/node_modules/undici/docs/docs/api/Client.md +281 -0
  35. package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
  36. package/bundle/node_modules/undici/docs/docs/api/Connector.md +115 -0
  37. package/bundle/node_modules/undici/docs/docs/api/ContentType.md +57 -0
  38. package/bundle/node_modules/undici/docs/docs/api/Cookies.md +101 -0
  39. package/bundle/node_modules/undici/docs/docs/api/Debug.md +62 -0
  40. package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +204 -0
  41. package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +1200 -0
  42. package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
  43. package/bundle/node_modules/undici/docs/docs/api/Errors.md +49 -0
  44. package/bundle/node_modules/undici/docs/docs/api/EventSource.md +45 -0
  45. package/bundle/node_modules/undici/docs/docs/api/Fetch.md +52 -0
  46. package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +262 -0
  47. package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
  48. package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
  49. package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
  50. package/bundle/node_modules/undici/docs/docs/api/MockClient.md +77 -0
  51. package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
  52. package/bundle/node_modules/undici/docs/docs/api/MockPool.md +548 -0
  53. package/bundle/node_modules/undici/docs/docs/api/Pool.md +84 -0
  54. package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
  55. package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +227 -0
  56. package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +96 -0
  57. package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +45 -0
  58. package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +117 -0
  59. package/bundle/node_modules/undici/docs/docs/api/Util.md +25 -0
  60. package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +85 -0
  61. package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
  62. package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
  63. package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
  64. package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
  65. package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +20 -0
  66. package/bundle/node_modules/undici/index-fetch.js +35 -0
  67. package/bundle/node_modules/undici/index.d.ts +3 -0
  68. package/bundle/node_modules/undici/index.js +183 -0
  69. package/bundle/node_modules/undici/lib/api/abort-signal.js +59 -0
  70. package/bundle/node_modules/undici/lib/api/api-connect.js +110 -0
  71. package/bundle/node_modules/undici/lib/api/api-pipeline.js +252 -0
  72. package/bundle/node_modules/undici/lib/api/api-request.js +199 -0
  73. package/bundle/node_modules/undici/lib/api/api-stream.js +209 -0
  74. package/bundle/node_modules/undici/lib/api/api-upgrade.js +110 -0
  75. package/bundle/node_modules/undici/lib/api/index.js +7 -0
  76. package/bundle/node_modules/undici/lib/api/readable.js +558 -0
  77. package/bundle/node_modules/undici/lib/api/util.js +95 -0
  78. package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +234 -0
  79. package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +461 -0
  80. package/bundle/node_modules/undici/lib/core/connect.js +164 -0
  81. package/bundle/node_modules/undici/lib/core/constants.js +143 -0
  82. package/bundle/node_modules/undici/lib/core/diagnostics.js +196 -0
  83. package/bundle/node_modules/undici/lib/core/errors.js +244 -0
  84. package/bundle/node_modules/undici/lib/core/request.js +397 -0
  85. package/bundle/node_modules/undici/lib/core/symbols.js +68 -0
  86. package/bundle/node_modules/undici/lib/core/tree.js +160 -0
  87. package/bundle/node_modules/undici/lib/core/util.js +988 -0
  88. package/bundle/node_modules/undici/lib/dispatcher/agent.js +135 -0
  89. package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +206 -0
  90. package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +1615 -0
  91. package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +798 -0
  92. package/bundle/node_modules/undici/lib/dispatcher/client.js +614 -0
  93. package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +161 -0
  94. package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
  95. package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +151 -0
  96. package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +159 -0
  97. package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +122 -0
  98. package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +191 -0
  99. package/bundle/node_modules/undici/lib/dispatcher/pool.js +118 -0
  100. package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +275 -0
  101. package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
  102. package/bundle/node_modules/undici/lib/global.js +32 -0
  103. package/bundle/node_modules/undici/lib/handler/cache-handler.js +448 -0
  104. package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
  105. package/bundle/node_modules/undici/lib/handler/decorator-handler.js +67 -0
  106. package/bundle/node_modules/undici/lib/handler/redirect-handler.js +227 -0
  107. package/bundle/node_modules/undici/lib/handler/retry-handler.js +342 -0
  108. package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +96 -0
  109. package/bundle/node_modules/undici/lib/handler/wrap-handler.js +95 -0
  110. package/bundle/node_modules/undici/lib/interceptor/cache.js +372 -0
  111. package/bundle/node_modules/undici/lib/interceptor/dns.js +432 -0
  112. package/bundle/node_modules/undici/lib/interceptor/dump.js +111 -0
  113. package/bundle/node_modules/undici/lib/interceptor/redirect.js +21 -0
  114. package/bundle/node_modules/undici/lib/interceptor/response-error.js +95 -0
  115. package/bundle/node_modules/undici/lib/interceptor/retry.js +19 -0
  116. package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  117. package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +97 -0
  118. package/bundle/node_modules/undici/lib/llhttp/constants.js +498 -0
  119. package/bundle/node_modules/undici/lib/llhttp/constants.js.map +1 -0
  120. package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
  121. package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
  122. package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
  123. package/bundle/node_modules/undici/lib/llhttp/utils.js +15 -0
  124. package/bundle/node_modules/undici/lib/llhttp/utils.js.map +1 -0
  125. package/bundle/node_modules/undici/lib/mock/mock-agent.js +224 -0
  126. package/bundle/node_modules/undici/lib/mock/mock-call-history.js +248 -0
  127. package/bundle/node_modules/undici/lib/mock/mock-client.js +64 -0
  128. package/bundle/node_modules/undici/lib/mock/mock-errors.js +19 -0
  129. package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
  130. package/bundle/node_modules/undici/lib/mock/mock-pool.js +64 -0
  131. package/bundle/node_modules/undici/lib/mock/mock-symbols.js +31 -0
  132. package/bundle/node_modules/undici/lib/mock/mock-utils.js +433 -0
  133. package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
  134. package/bundle/node_modules/undici/lib/util/cache.js +368 -0
  135. package/bundle/node_modules/undici/lib/util/date.js +259 -0
  136. package/bundle/node_modules/undici/lib/util/stats.js +32 -0
  137. package/bundle/node_modules/undici/lib/util/timers.js +423 -0
  138. package/bundle/node_modules/undici/lib/web/cache/cache.js +862 -0
  139. package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
  140. package/bundle/node_modules/undici/lib/web/cache/util.js +45 -0
  141. package/bundle/node_modules/undici/lib/web/cookies/constants.js +12 -0
  142. package/bundle/node_modules/undici/lib/web/cookies/index.js +199 -0
  143. package/bundle/node_modules/undici/lib/web/cookies/parse.js +322 -0
  144. package/bundle/node_modules/undici/lib/web/cookies/util.js +282 -0
  145. package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +399 -0
  146. package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +484 -0
  147. package/bundle/node_modules/undici/lib/web/eventsource/util.js +37 -0
  148. package/bundle/node_modules/undici/lib/web/fetch/LICENSE +21 -0
  149. package/bundle/node_modules/undici/lib/web/fetch/body.js +532 -0
  150. package/bundle/node_modules/undici/lib/web/fetch/constants.js +131 -0
  151. package/bundle/node_modules/undici/lib/web/fetch/data-url.js +744 -0
  152. package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +46 -0
  153. package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +501 -0
  154. package/bundle/node_modules/undici/lib/web/fetch/formdata.js +263 -0
  155. package/bundle/node_modules/undici/lib/web/fetch/global.js +40 -0
  156. package/bundle/node_modules/undici/lib/web/fetch/headers.js +719 -0
  157. package/bundle/node_modules/undici/lib/web/fetch/index.js +2258 -0
  158. package/bundle/node_modules/undici/lib/web/fetch/request.js +1099 -0
  159. package/bundle/node_modules/undici/lib/web/fetch/response.js +636 -0
  160. package/bundle/node_modules/undici/lib/web/fetch/util.js +1782 -0
  161. package/bundle/node_modules/undici/lib/web/fetch/webidl.js +740 -0
  162. package/bundle/node_modules/undici/lib/web/websocket/connection.js +325 -0
  163. package/bundle/node_modules/undici/lib/web/websocket/constants.js +126 -0
  164. package/bundle/node_modules/undici/lib/web/websocket/events.js +331 -0
  165. package/bundle/node_modules/undici/lib/web/websocket/frame.js +138 -0
  166. package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +70 -0
  167. package/bundle/node_modules/undici/lib/web/websocket/receiver.js +454 -0
  168. package/bundle/node_modules/undici/lib/web/websocket/sender.js +109 -0
  169. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +83 -0
  170. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +485 -0
  171. package/bundle/node_modules/undici/lib/web/websocket/util.js +338 -0
  172. package/bundle/node_modules/undici/lib/web/websocket/websocket.js +686 -0
  173. package/bundle/node_modules/undici/package.json +149 -0
  174. package/bundle/node_modules/undici/scripts/strip-comments.js +10 -0
  175. package/bundle/node_modules/undici/types/README.md +6 -0
  176. package/bundle/node_modules/undici/types/agent.d.ts +35 -0
  177. package/bundle/node_modules/undici/types/api.d.ts +43 -0
  178. package/bundle/node_modules/undici/types/balanced-pool.d.ts +29 -0
  179. package/bundle/node_modules/undici/types/cache-interceptor.d.ts +172 -0
  180. package/bundle/node_modules/undici/types/cache.d.ts +36 -0
  181. package/bundle/node_modules/undici/types/client-stats.d.ts +15 -0
  182. package/bundle/node_modules/undici/types/client.d.ts +110 -0
  183. package/bundle/node_modules/undici/types/connector.d.ts +34 -0
  184. package/bundle/node_modules/undici/types/content-type.d.ts +21 -0
  185. package/bundle/node_modules/undici/types/cookies.d.ts +30 -0
  186. package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +66 -0
  187. package/bundle/node_modules/undici/types/dispatcher.d.ts +281 -0
  188. package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +21 -0
  189. package/bundle/node_modules/undici/types/errors.d.ts +171 -0
  190. package/bundle/node_modules/undici/types/eventsource.d.ts +61 -0
  191. package/bundle/node_modules/undici/types/fetch.d.ts +210 -0
  192. package/bundle/node_modules/undici/types/formdata.d.ts +108 -0
  193. package/bundle/node_modules/undici/types/global-dispatcher.d.ts +9 -0
  194. package/bundle/node_modules/undici/types/global-origin.d.ts +7 -0
  195. package/bundle/node_modules/undici/types/h2c-client.d.ts +75 -0
  196. package/bundle/node_modules/undici/types/handlers.d.ts +15 -0
  197. package/bundle/node_modules/undici/types/header.d.ts +160 -0
  198. package/bundle/node_modules/undici/types/index.d.ts +75 -0
  199. package/bundle/node_modules/undici/types/interceptors.d.ts +34 -0
  200. package/bundle/node_modules/undici/types/mock-agent.d.ts +68 -0
  201. package/bundle/node_modules/undici/types/mock-call-history.d.ts +111 -0
  202. package/bundle/node_modules/undici/types/mock-client.d.ts +25 -0
  203. package/bundle/node_modules/undici/types/mock-errors.d.ts +12 -0
  204. package/bundle/node_modules/undici/types/mock-interceptor.d.ts +93 -0
  205. package/bundle/node_modules/undici/types/mock-pool.d.ts +25 -0
  206. package/bundle/node_modules/undici/types/patch.d.ts +29 -0
  207. package/bundle/node_modules/undici/types/pool-stats.d.ts +19 -0
  208. package/bundle/node_modules/undici/types/pool.d.ts +41 -0
  209. package/bundle/node_modules/undici/types/proxy-agent.d.ts +29 -0
  210. package/bundle/node_modules/undici/types/readable.d.ts +68 -0
  211. package/bundle/node_modules/undici/types/retry-agent.d.ts +8 -0
  212. package/bundle/node_modules/undici/types/retry-handler.d.ts +116 -0
  213. package/bundle/node_modules/undici/types/util.d.ts +18 -0
  214. package/bundle/node_modules/undici/types/utility.d.ts +7 -0
  215. package/bundle/node_modules/undici/types/webidl.d.ts +266 -0
  216. package/bundle/node_modules/undici/types/websocket.d.ts +184 -0
  217. package/bundle/sandbox-macos-permissive-closed.sb +26 -0
  218. package/bundle/sandbox-macos-permissive-open.sb +19 -0
  219. package/bundle/sandbox-macos-permissive-proxied.sb +31 -0
  220. package/bundle/sandbox-macos-restrictive-closed.sb +87 -0
  221. package/bundle/sandbox-macos-restrictive-open.sb +90 -0
  222. package/bundle/sandbox-macos-restrictive-proxied.sb +92 -0
  223. package/package.json +137 -0
@@ -0,0 +1,740 @@
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
+ }