cf-workers-native 0.0.0-stage → 0.1.2-beta.local.sha2f5e4e6956f4

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 (629) hide show
  1. package/LICENSE +21 -0
  2. package/Package.swift +25 -0
  3. package/README.md +92 -2
  4. package/dist/android.d.ts +2 -0
  5. package/dist/android.js +1 -0
  6. package/dist/browser/abort/index.d.ts +13 -0
  7. package/dist/browser/abort/index.js +66 -0
  8. package/dist/browser/body/index.d.ts +24 -0
  9. package/dist/browser/body/index.js +116 -0
  10. package/dist/browser/body/stream-body.d.ts +13 -0
  11. package/dist/browser/body/stream-body.js +84 -0
  12. package/dist/browser/documents/body.d.ts +3 -0
  13. package/dist/browser/documents/body.js +48 -0
  14. package/dist/browser/documents/form-body.d.ts +1 -0
  15. package/dist/browser/documents/form-body.js +54 -0
  16. package/dist/browser/documents/host.d.ts +11 -0
  17. package/dist/browser/documents/host.js +256 -0
  18. package/dist/browser/documents/links-source.d.ts +1 -0
  19. package/dist/browser/documents/links-source.js +1 -0
  20. package/dist/browser/documents/links.d.ts +1 -0
  21. package/dist/browser/documents/links.js +33 -0
  22. package/dist/browser/documents/page-config.d.ts +5 -0
  23. package/dist/browser/documents/page-config.js +5 -0
  24. package/dist/browser/documents/page-source.d.ts +1 -0
  25. package/dist/browser/documents/page-source.js +1 -0
  26. package/dist/browser/documents/page.d.ts +2 -0
  27. package/dist/browser/documents/page.js +153 -0
  28. package/dist/browser/documents/registration.d.ts +5 -0
  29. package/dist/browser/documents/registration.js +75 -0
  30. package/dist/browser/documents/runtime.d.ts +7 -0
  31. package/dist/browser/documents/runtime.js +161 -0
  32. package/dist/browser/documents/service-worker.js +285 -0
  33. package/dist/browser/encoding/index.d.ts +7 -0
  34. package/dist/browser/encoding/index.js +3 -0
  35. package/dist/browser/fetch/LICENSE-3RD-PARTY.md +9 -0
  36. package/dist/browser/fetch/LICENSE-APACHE +177 -0
  37. package/dist/browser/fetch/host-call.d.ts +3 -0
  38. package/dist/browser/fetch/host-call.js +67 -0
  39. package/dist/browser/fetch/index.d.ts +5 -0
  40. package/dist/browser/fetch/index.js +96 -0
  41. package/dist/browser/fetch/interop.d.ts +6 -0
  42. package/dist/browser/fetch/interop.js +48 -0
  43. package/dist/browser/fetch/native-network.d.ts +20 -0
  44. package/dist/browser/fetch/native-network.js +233 -0
  45. package/dist/browser/fetch/outbound.d.ts +2 -0
  46. package/dist/browser/fetch/outbound.js +11 -0
  47. package/dist/browser/fetch/relay.d.ts +7 -0
  48. package/dist/browser/fetch/relay.js +100 -0
  49. package/dist/browser/fetch/scope.d.ts +8 -0
  50. package/dist/browser/fetch/scope.js +108 -0
  51. package/dist/browser/fetch/transport.d.ts +39 -0
  52. package/dist/browser/fetch/transport.js +136 -0
  53. package/dist/browser/headers/LICENSE-3RD-PARTY.md +9 -0
  54. package/dist/browser/headers/LICENSE-APACHE +177 -0
  55. package/dist/browser/headers/index.d.ts +20 -0
  56. package/dist/browser/headers/index.js +194 -0
  57. package/dist/browser/isolated/bridge.d.ts +8 -0
  58. package/dist/browser/isolated/bridge.js +267 -0
  59. package/dist/browser/isolated/protocol.d.ts +40 -0
  60. package/dist/browser/isolated/protocol.js +1 -0
  61. package/dist/browser/isolated/transport.d.ts +2 -0
  62. package/dist/browser/isolated/transport.js +157 -0
  63. package/dist/browser/request/LICENSE-3RD-PARTY.md +10 -0
  64. package/dist/browser/request/LICENSE-APACHE +177 -0
  65. package/dist/browser/request/index.d.ts +48 -0
  66. package/dist/browser/request/index.js +182 -0
  67. package/dist/browser/response/LICENSE-3RD-PARTY.md +10 -0
  68. package/dist/browser/response/LICENSE-APACHE +177 -0
  69. package/dist/browser/response/index.d.ts +43 -0
  70. package/dist/browser/response/index.js +192 -0
  71. package/dist/browser/response/status.d.ts +1 -0
  72. package/dist/browser/response/status.js +75 -0
  73. package/dist/browser/structured-clone/index.d.ts +1 -0
  74. package/dist/browser/structured-clone/index.js +479 -0
  75. package/dist/cloudflare/apis/cloudflare-node/index.d.ts +18 -0
  76. package/dist/cloudflare/apis/cloudflare-node/index.js +150 -0
  77. package/dist/cloudflare/apis/cloudflare-workers/index.d.ts +8 -0
  78. package/dist/cloudflare/apis/cloudflare-workers/index.js +37 -0
  79. package/dist/cloudflare/apis/types.d.ts +7 -0
  80. package/dist/cloudflare/apis/types.js +1 -0
  81. package/dist/cloudflare/bindings/config.d.ts +42 -0
  82. package/dist/cloudflare/bindings/config.js +280 -0
  83. package/dist/cloudflare/bindings/kv/contract.d.ts +6 -0
  84. package/dist/cloudflare/bindings/kv/contract.js +181 -0
  85. package/dist/cloudflare/bindings/kv/index.d.ts +18 -0
  86. package/dist/cloudflare/bindings/kv/index.js +61 -0
  87. package/dist/cloudflare/bindings/kv/storage.d.ts +25 -0
  88. package/dist/cloudflare/bindings/kv/storage.js +320 -0
  89. package/dist/cloudflare/bindings/kv/types.d.ts +50 -0
  90. package/dist/cloudflare/bindings/kv/types.js +1 -0
  91. package/dist/cloudflare/bindings/remote.d.ts +8 -0
  92. package/dist/cloudflare/bindings/remote.js +261 -0
  93. package/dist/cloudflare/workers/contract.d.ts +8 -0
  94. package/dist/cloudflare/workers/contract.js +65 -0
  95. package/dist/cloudflare/workers/feature.d.ts +10 -0
  96. package/dist/cloudflare/workers/feature.js +28 -0
  97. package/dist/cloudflare/workers/runtime.d.ts +23 -0
  98. package/dist/cloudflare/workers/runtime.js +121 -0
  99. package/dist/cloudflare/workers/types.d.ts +49 -0
  100. package/dist/cloudflare/workers/types.js +1 -0
  101. package/dist/cloudflare/workers/worker-runtime.d.ts +44 -0
  102. package/dist/cloudflare/workers/worker-runtime.js +267 -0
  103. package/dist/compat/assert/LICENSE-3RD-PARTY.md +5 -0
  104. package/dist/compat/assert/LICENSE-APACHE +177 -0
  105. package/dist/compat/assert/assertion-error.d.ts +26 -0
  106. package/dist/compat/assert/assertion-error.js +468 -0
  107. package/dist/compat/assert/diff.d.ts +26 -0
  108. package/dist/compat/assert/diff.js +329 -0
  109. package/dist/compat/assert/errors.d.ts +11 -0
  110. package/dist/compat/assert/errors.js +55 -0
  111. package/dist/compat/assert/index.cjs +24 -0
  112. package/dist/compat/assert/index.d.cts +43 -0
  113. package/dist/compat/assert/index.d.ts +50 -0
  114. package/dist/compat/assert/index.js +858 -0
  115. package/dist/compat/async-hooks/LICENSE-APACHE +177 -0
  116. package/dist/compat/async-hooks/NOTICE.md +8 -0
  117. package/dist/compat/async-hooks/callbacks.d.ts +7 -0
  118. package/dist/compat/async-hooks/callbacks.js +18 -0
  119. package/dist/compat/async-hooks/hooks.d.ts +10 -0
  120. package/dist/compat/async-hooks/hooks.js +111 -0
  121. package/dist/compat/async-hooks/index.d.ts +41 -0
  122. package/dist/compat/async-hooks/index.js +298 -0
  123. package/dist/compat/buffer/LICENSE-3RD-PARTY.md +15 -0
  124. package/dist/compat/buffer/LICENSE-APACHE +177 -0
  125. package/dist/compat/buffer/blob.d.ts +22 -0
  126. package/dist/compat/buffer/blob.js +210 -0
  127. package/dist/compat/buffer/bytes.d.ts +34 -0
  128. package/dist/compat/buffer/bytes.js +228 -0
  129. package/dist/compat/buffer/errors.d.ts +41 -0
  130. package/dist/compat/buffer/errors.js +265 -0
  131. package/dist/compat/buffer/index.d.ts +25 -0
  132. package/dist/compat/buffer/index.js +24 -0
  133. package/dist/compat/buffer/internal-buffer.d.ts +148 -0
  134. package/dist/compat/buffer/internal-buffer.js +1809 -0
  135. package/dist/compat/buffer/support.d.ts +13 -0
  136. package/dist/compat/buffer/support.js +65 -0
  137. package/dist/compat/child-process/LICENSE-3RD-PARTY.md +8 -0
  138. package/dist/compat/child-process/LICENSE-APACHE +177 -0
  139. package/dist/compat/child-process/errors.d.ts +4 -0
  140. package/dist/compat/child-process/errors.js +6 -0
  141. package/dist/compat/child-process/index.d.ts +49 -0
  142. package/dist/compat/child-process/index.js +96 -0
  143. package/dist/compat/cluster/LICENSE-3RD-PARTY.md +40 -0
  144. package/dist/compat/cluster/LICENSE-APACHE +177 -0
  145. package/dist/compat/cluster/errors.d.ts +4 -0
  146. package/dist/compat/cluster/errors.js +6 -0
  147. package/dist/compat/cluster/index.d.ts +47 -0
  148. package/dist/compat/cluster/index.js +88 -0
  149. package/dist/compat/constants/LICENSE-3RD-PARTY.md +6 -0
  150. package/dist/compat/constants/LICENSE-APACHE +177 -0
  151. package/dist/compat/constants/index.d.ts +481 -0
  152. package/dist/compat/constants/index.js +488 -0
  153. package/dist/compat/dgram/LICENSE-3RD-PARTY.md +8 -0
  154. package/dist/compat/dgram/LICENSE-APACHE +177 -0
  155. package/dist/compat/dgram/index.d.ts +10 -0
  156. package/dist/compat/dgram/index.js +132 -0
  157. package/dist/compat/diagnostics-channel/LICENSE-3RD-PARTY.md +13 -0
  158. package/dist/compat/diagnostics-channel/LICENSE-APACHE +177 -0
  159. package/dist/compat/diagnostics-channel/index.d.ts +73 -0
  160. package/dist/compat/diagnostics-channel/index.js +261 -0
  161. package/dist/compat/diagnostics-channel/native.d.ts +26 -0
  162. package/dist/compat/diagnostics-channel/native.js +154 -0
  163. package/dist/compat/dns/LICENSE-3RD-PARTY.md +5 -0
  164. package/dist/compat/dns/LICENSE-APACHE +177 -0
  165. package/dist/compat/dns/client.d.ts +72 -0
  166. package/dist/compat/dns/client.js +161 -0
  167. package/dist/compat/dns/constants.d.ts +27 -0
  168. package/dist/compat/dns/constants.js +31 -0
  169. package/dist/compat/dns/errors.d.ts +8 -0
  170. package/dist/compat/dns/errors.js +12 -0
  171. package/dist/compat/dns/index.d.ts +97 -0
  172. package/dist/compat/dns/index.js +127 -0
  173. package/dist/compat/dns/parser.d.ts +18 -0
  174. package/dist/compat/dns/parser.js +144 -0
  175. package/dist/compat/dns/promise-resolver.d.ts +82 -0
  176. package/dist/compat/dns/promise-resolver.js +113 -0
  177. package/dist/compat/dns/promises.d.ts +50 -0
  178. package/dist/compat/dns/promises.js +53 -0
  179. package/dist/compat/dns/resolver.d.ts +34 -0
  180. package/dist/compat/dns/resolver.js +415 -0
  181. package/dist/compat/domain/LICENSE-3RD-PARTY.md +5 -0
  182. package/dist/compat/domain/LICENSE-APACHE +177 -0
  183. package/dist/compat/domain/index.d.ts +22 -0
  184. package/dist/compat/domain/index.js +79 -0
  185. package/dist/compat/fs/index.d.ts +85 -0
  186. package/dist/compat/fs/index.js +255 -0
  187. package/dist/compat/fs/promises/index.d.ts +3 -0
  188. package/dist/compat/fs/promises/index.js +3 -0
  189. package/dist/compat/http/index.d.ts +322 -0
  190. package/dist/compat/http/index.js +1356 -0
  191. package/dist/compat/http/registry.d.ts +19 -0
  192. package/dist/compat/http/registry.js +13 -0
  193. package/dist/compat/http-agent/LICENSE-3RD-PARTY.md +5 -0
  194. package/dist/compat/http-agent/LICENSE-APACHE +177 -0
  195. package/dist/compat/http-agent/index.d.ts +7 -0
  196. package/dist/compat/http-agent/index.js +10 -0
  197. package/dist/compat/http-client/LICENSE-3RD-PARTY.md +5 -0
  198. package/dist/compat/http-client/LICENSE-APACHE +177 -0
  199. package/dist/compat/http-client/index.d.ts +6 -0
  200. package/dist/compat/http-client/index.js +7 -0
  201. package/dist/compat/http-incoming/LICENSE-3RD-PARTY.md +5 -0
  202. package/dist/compat/http-incoming/LICENSE-APACHE +177 -0
  203. package/dist/compat/http-incoming/index.d.ts +6 -0
  204. package/dist/compat/http-incoming/index.js +9 -0
  205. package/dist/compat/http2/LICENSE-3RD-PARTY.md +29 -0
  206. package/dist/compat/http2/LICENSE-APACHE +177 -0
  207. package/dist/compat/http2/constants.d.ts +255 -0
  208. package/dist/compat/http2/constants.js +515 -0
  209. package/dist/compat/http2/errors.d.ts +4 -0
  210. package/dist/compat/http2/errors.js +6 -0
  211. package/dist/compat/http2/index.d.ts +283 -0
  212. package/dist/compat/http2/index.js +68 -0
  213. package/dist/compat/https/LICENSE-3RD-PARTY.md +5 -0
  214. package/dist/compat/https/LICENSE-APACHE +177 -0
  215. package/dist/compat/https/agent.d.ts +10 -0
  216. package/dist/compat/https/agent.js +99 -0
  217. package/dist/compat/https/errors.d.ts +4 -0
  218. package/dist/compat/https/errors.js +6 -0
  219. package/dist/compat/https/index.d.ts +20 -0
  220. package/dist/compat/https/index.js +50 -0
  221. package/dist/compat/https/server.d.ts +8 -0
  222. package/dist/compat/https/server.js +27 -0
  223. package/dist/compat/immediate/index.d.ts +11 -0
  224. package/dist/compat/immediate/index.js +58 -0
  225. package/dist/compat/inspector/LICENSE-3RD-PARTY.md +34 -0
  226. package/dist/compat/inspector/LICENSE-APACHE +177 -0
  227. package/dist/compat/inspector/errors.d.ts +4 -0
  228. package/dist/compat/inspector/errors.js +6 -0
  229. package/dist/compat/inspector/index.d.ts +18 -0
  230. package/dist/compat/inspector/index.js +117 -0
  231. package/dist/compat/inspector/promises.d.ts +18 -0
  232. package/dist/compat/inspector/promises.js +114 -0
  233. package/dist/compat/module/index.cjs +2 -0
  234. package/dist/compat/module/index.d.cts +2 -0
  235. package/dist/compat/module/index.d.ts +11 -0
  236. package/dist/compat/module/index.js +44 -0
  237. package/dist/compat/module/resolve-unavailable.d.ts +1 -0
  238. package/dist/compat/module/resolve-unavailable.js +3 -0
  239. package/dist/compat/net/LICENSE-3RD-PARTY.md +15 -0
  240. package/dist/compat/net/LICENSE-APACHE +177 -0
  241. package/dist/compat/net/error-base.d.ts +14 -0
  242. package/dist/compat/net/error-base.js +62 -0
  243. package/dist/compat/net/errors.d.ts +76 -0
  244. package/dist/compat/net/errors.js +333 -0
  245. package/dist/compat/net/index.d.ts +23 -0
  246. package/dist/compat/net/index.js +46 -0
  247. package/dist/compat/net/internal-net.d.ts +236 -0
  248. package/dist/compat/net/internal-net.js +2292 -0
  249. package/dist/compat/net/ports.d.ts +32 -0
  250. package/dist/compat/net/ports.js +149 -0
  251. package/dist/compat/net/reader.d.ts +8 -0
  252. package/dist/compat/net/reader.js +36 -0
  253. package/dist/compat/net/sockets.d.ts +20 -0
  254. package/dist/compat/net/sockets.js +195 -0
  255. package/dist/compat/net/validators.d.ts +18 -0
  256. package/dist/compat/net/validators.js +154 -0
  257. package/dist/compat/os/LICENSE-3RD-PARTY.md +8 -0
  258. package/dist/compat/os/LICENSE-APACHE +177 -0
  259. package/dist/compat/os/index.d.ts +329 -0
  260. package/dist/compat/os/index.js +278 -0
  261. package/dist/compat/path/LICENSE-3RD-PARTY.md +35 -0
  262. package/dist/compat/path/LICENSE-APACHE +177 -0
  263. package/dist/compat/path/index.d.ts +4 -0
  264. package/dist/compat/path/index.js +11 -0
  265. package/dist/compat/path/internal-path.d.ts +95 -0
  266. package/dist/compat/path/internal-path.js +1542 -0
  267. package/dist/compat/path/posix/index.d.ts +4 -0
  268. package/dist/compat/path/posix/index.js +5 -0
  269. package/dist/compat/path/win32/index.d.ts +4 -0
  270. package/dist/compat/path/win32/index.js +5 -0
  271. package/dist/compat/perf-hooks/LICENSE-3RD-PARTY.md +5 -0
  272. package/dist/compat/perf-hooks/LICENSE-APACHE +177 -0
  273. package/dist/compat/perf-hooks/index.d.ts +85 -0
  274. package/dist/compat/perf-hooks/index.js +79 -0
  275. package/dist/compat/perf-hooks/performance.d.ts +96 -0
  276. package/dist/compat/perf-hooks/performance.js +445 -0
  277. package/dist/compat/punycode/LICENSE-3RD-PARTY.md +7 -0
  278. package/dist/compat/punycode/LICENSE-APACHE +177 -0
  279. package/dist/compat/punycode/index.d.ts +93 -0
  280. package/dist/compat/punycode/index.js +410 -0
  281. package/dist/compat/querystring/LICENSE-3RD-PARTY.md +35 -0
  282. package/dist/compat/querystring/LICENSE-APACHE +177 -0
  283. package/dist/compat/querystring/index.d.ts +14 -0
  284. package/dist/compat/querystring/index.js +18 -0
  285. package/dist/compat/querystring/internal-querystring.d.ts +22 -0
  286. package/dist/compat/querystring/internal-querystring.js +498 -0
  287. package/dist/compat/readline/LICENSE-3RD-PARTY.md +37 -0
  288. package/dist/compat/readline/LICENSE-APACHE +177 -0
  289. package/dist/compat/readline/index.d.ts +21 -0
  290. package/dist/compat/readline/index.js +56 -0
  291. package/dist/compat/readline/interface.d.ts +22 -0
  292. package/dist/compat/readline/interface.js +85 -0
  293. package/dist/compat/readline/internal-promises.d.ts +32 -0
  294. package/dist/compat/readline/internal-promises.js +104 -0
  295. package/dist/compat/readline/promises.d.ts +8 -0
  296. package/dist/compat/readline/promises.js +32 -0
  297. package/dist/compat/repl/LICENSE-3RD-PARTY.md +5 -0
  298. package/dist/compat/repl/LICENSE-APACHE +177 -0
  299. package/dist/compat/repl/builtin-modules.d.ts +1 -0
  300. package/dist/compat/repl/builtin-modules.js +101 -0
  301. package/dist/compat/repl/errors.d.ts +4 -0
  302. package/dist/compat/repl/errors.js +6 -0
  303. package/dist/compat/repl/index.d.ts +53 -0
  304. package/dist/compat/repl/index.js +106 -0
  305. package/dist/compat/sqlite/LICENSE-3RD-PARTY.md +6 -0
  306. package/dist/compat/sqlite/LICENSE-APACHE +177 -0
  307. package/dist/compat/sqlite/index.d.ts +12 -0
  308. package/dist/compat/sqlite/index.js +101 -0
  309. package/dist/compat/sqlite/native.d.ts +16 -0
  310. package/dist/compat/sqlite/native.js +33 -0
  311. package/dist/compat/stream/LICENSE-3RD-PARTY.md +13 -0
  312. package/dist/compat/stream/LICENSE-APACHE +177 -0
  313. package/dist/compat/stream/add-abort-signal.d.ts +4 -0
  314. package/dist/compat/stream/add-abort-signal.js +73 -0
  315. package/dist/compat/stream/compose.d.ts +1 -0
  316. package/dist/compat/stream/compose.js +313 -0
  317. package/dist/compat/stream/destroy.d.ts +5 -0
  318. package/dist/compat/stream/destroy.js +315 -0
  319. package/dist/compat/stream/duplex.d.ts +48 -0
  320. package/dist/compat/stream/duplex.js +789 -0
  321. package/dist/compat/stream/end-of-stream.d.ts +16 -0
  322. package/dist/compat/stream/end-of-stream.js +269 -0
  323. package/dist/compat/stream/errors.d.ts +40 -0
  324. package/dist/compat/stream/errors.js +86 -0
  325. package/dist/compat/stream/events.d.ts +6 -0
  326. package/dist/compat/stream/events.js +28 -0
  327. package/dist/compat/stream/index.cjs +27 -0
  328. package/dist/compat/stream/index.d.cts +25 -0
  329. package/dist/compat/stream/index.d.ts +20 -0
  330. package/dist/compat/stream/index.js +55 -0
  331. package/dist/compat/stream/legacy.d.ts +8 -0
  332. package/dist/compat/stream/legacy.js +105 -0
  333. package/dist/compat/stream/once.d.ts +7 -0
  334. package/dist/compat/stream/once.js +13 -0
  335. package/dist/compat/stream/pipeline.d.ts +5 -0
  336. package/dist/compat/stream/pipeline.js +567 -0
  337. package/dist/compat/stream/process.d.ts +1 -0
  338. package/dist/compat/stream/process.js +4 -0
  339. package/dist/compat/stream/promises.d.ts +7 -0
  340. package/dist/compat/stream/promises.js +60 -0
  341. package/dist/compat/stream/readable.d.ts +29 -0
  342. package/dist/compat/stream/readable.js +2267 -0
  343. package/dist/compat/stream/state.d.ts +8 -0
  344. package/dist/compat/stream/state.js +63 -0
  345. package/dist/compat/stream/transform.d.ts +2 -0
  346. package/dist/compat/stream/transform.js +202 -0
  347. package/dist/compat/stream/util.d.ts +55 -0
  348. package/dist/compat/stream/util.js +345 -0
  349. package/dist/compat/stream/validators.d.ts +2 -0
  350. package/dist/compat/stream/validators.js +14 -0
  351. package/dist/compat/stream/writable.d.ts +21 -0
  352. package/dist/compat/stream/writable.js +1325 -0
  353. package/dist/compat/stream-consumers/LICENSE-3RD-PARTY.md +5 -0
  354. package/dist/compat/stream-consumers/LICENSE-APACHE +177 -0
  355. package/dist/compat/stream-consumers/index.d.ts +14 -0
  356. package/dist/compat/stream-consumers/index.js +62 -0
  357. package/dist/compat/stream-consumers/iterable.d.ts +1 -0
  358. package/dist/compat/stream-consumers/iterable.js +34 -0
  359. package/dist/compat/stream-duplex/LICENSE-3RD-PARTY.md +13 -0
  360. package/dist/compat/stream-duplex/LICENSE-APACHE +177 -0
  361. package/dist/compat/stream-duplex/index.cjs +3 -0
  362. package/dist/compat/stream-duplex/index.d.cts +2 -0
  363. package/dist/compat/stream-duplex/index.d.ts +3 -0
  364. package/dist/compat/stream-duplex/index.js +8 -0
  365. package/dist/compat/stream-passthrough/LICENSE-3RD-PARTY.md +13 -0
  366. package/dist/compat/stream-passthrough/LICENSE-APACHE +177 -0
  367. package/dist/compat/stream-passthrough/index.cjs +3 -0
  368. package/dist/compat/stream-passthrough/index.d.cts +2 -0
  369. package/dist/compat/stream-passthrough/index.d.ts +3 -0
  370. package/dist/compat/stream-passthrough/index.js +8 -0
  371. package/dist/compat/stream-promises/LICENSE-3RD-PARTY.md +13 -0
  372. package/dist/compat/stream-promises/LICENSE-APACHE +177 -0
  373. package/dist/compat/stream-promises/index.d.ts +1 -0
  374. package/dist/compat/stream-promises/index.js +1 -0
  375. package/dist/compat/stream-readable/LICENSE-3RD-PARTY.md +13 -0
  376. package/dist/compat/stream-readable/LICENSE-APACHE +177 -0
  377. package/dist/compat/stream-readable/index.cjs +3 -0
  378. package/dist/compat/stream-readable/index.d.cts +2 -0
  379. package/dist/compat/stream-readable/index.d.ts +3 -0
  380. package/dist/compat/stream-readable/index.js +8 -0
  381. package/dist/compat/stream-transform/LICENSE-3RD-PARTY.md +13 -0
  382. package/dist/compat/stream-transform/LICENSE-APACHE +177 -0
  383. package/dist/compat/stream-transform/index.cjs +3 -0
  384. package/dist/compat/stream-transform/index.d.cts +2 -0
  385. package/dist/compat/stream-transform/index.d.ts +3 -0
  386. package/dist/compat/stream-transform/index.js +8 -0
  387. package/dist/compat/stream-web/LICENSE-MIT +22 -0
  388. package/dist/compat/stream-web/NOTICE.md +3 -0
  389. package/dist/compat/stream-web/context.d.ts +2 -0
  390. package/dist/compat/stream-web/context.js +35 -0
  391. package/dist/compat/stream-web/index.d.ts +80 -0
  392. package/dist/compat/stream-web/index.js +129 -0
  393. package/dist/compat/stream-web/interop.d.ts +6 -0
  394. package/dist/compat/stream-web/interop.js +72 -0
  395. package/dist/compat/stream-web/ponyfill.d.ts +1 -0
  396. package/dist/compat/stream-web/ponyfill.js +2093 -0
  397. package/dist/compat/stream-web/runtime.d.ts +16 -0
  398. package/dist/compat/stream-web/runtime.js +51 -0
  399. package/dist/compat/stream-writable/LICENSE-3RD-PARTY.md +13 -0
  400. package/dist/compat/stream-writable/LICENSE-APACHE +177 -0
  401. package/dist/compat/stream-writable/index.cjs +3 -0
  402. package/dist/compat/stream-writable/index.d.cts +2 -0
  403. package/dist/compat/stream-writable/index.d.ts +3 -0
  404. package/dist/compat/stream-writable/index.js +8 -0
  405. package/dist/compat/string-decoder/LICENSE-3RD-PARTY.md +38 -0
  406. package/dist/compat/string-decoder/LICENSE-APACHE +177 -0
  407. package/dist/compat/string-decoder/index.d.ts +33 -0
  408. package/dist/compat/string-decoder/index.js +518 -0
  409. package/dist/compat/test/LICENSE-3RD-PARTY.md +37 -0
  410. package/dist/compat/test/LICENSE-APACHE +177 -0
  411. package/dist/compat/test/index.d.ts +9 -0
  412. package/dist/compat/test/index.js +11 -0
  413. package/dist/compat/test/mock.d.ts +103 -0
  414. package/dist/compat/test/mock.js +397 -0
  415. package/dist/compat/test/validators.d.ts +2 -0
  416. package/dist/compat/test/validators.js +14 -0
  417. package/dist/compat/timers/LICENSE-3RD-PARTY.md +7 -0
  418. package/dist/compat/timers/LICENSE-APACHE +177 -0
  419. package/dist/compat/timers/errors.d.ts +28 -0
  420. package/dist/compat/timers/errors.js +206 -0
  421. package/dist/compat/timers/host.d.ts +11 -0
  422. package/dist/compat/timers/host.js +60 -0
  423. package/dist/compat/timers/index.cjs +3 -0
  424. package/dist/compat/timers/index.d.cts +23 -0
  425. package/dist/compat/timers/index.d.ts +36 -0
  426. package/dist/compat/timers/index.js +20 -0
  427. package/dist/compat/timers/installation.d.ts +4 -0
  428. package/dist/compat/timers/installation.js +61 -0
  429. package/dist/compat/timers/internal-promises.d.ts +19 -0
  430. package/dist/compat/timers/internal-promises.js +173 -0
  431. package/dist/compat/timers/promises.cjs +2 -0
  432. package/dist/compat/timers/promises.d.cts +12 -0
  433. package/dist/compat/timers/promises.d.ts +14 -0
  434. package/dist/compat/timers/promises.js +3 -0
  435. package/dist/compat/timers/timers.d.ts +32 -0
  436. package/dist/compat/timers/timers.js +147 -0
  437. package/dist/compat/timers/validation.d.ts +5 -0
  438. package/dist/compat/timers/validation.js +22 -0
  439. package/dist/compat/timers/wait.d.ts +4 -0
  440. package/dist/compat/timers/wait.js +91 -0
  441. package/dist/compat/tls-common/LICENSE-3RD-PARTY.md +11 -0
  442. package/dist/compat/tls-common/LICENSE-APACHE +177 -0
  443. package/dist/compat/tls-common/index.d.ts +14 -0
  444. package/dist/compat/tls-common/index.js +88 -0
  445. package/dist/compat/trace-events/LICENSE-3RD-PARTY.md +5 -0
  446. package/dist/compat/trace-events/LICENSE-APACHE +177 -0
  447. package/dist/compat/trace-events/index.d.ts +18 -0
  448. package/dist/compat/trace-events/index.js +88 -0
  449. package/dist/compat/tty/LICENSE-3RD-PARTY.md +8 -0
  450. package/dist/compat/tty/LICENSE-APACHE +177 -0
  451. package/dist/compat/tty/index.d.ts +17 -0
  452. package/dist/compat/tty/index.js +101 -0
  453. package/dist/compat/url/LICENSE-3RD-PARTY.md +63 -0
  454. package/dist/compat/url/LICENSE-ADA +18 -0
  455. package/dist/compat/url/LICENSE-APACHE +177 -0
  456. package/dist/compat/url/LICENSE-UNICODE +39 -0
  457. package/dist/compat/url/LICENSE-WHATWG-URL +21 -0
  458. package/dist/compat/url/brand.d.ts +4 -0
  459. package/dist/compat/url/brand.js +10 -0
  460. package/dist/compat/url/constants.d.ts +27 -0
  461. package/dist/compat/url/constants.js +28 -0
  462. package/dist/compat/url/errors.d.ts +44 -0
  463. package/dist/compat/url/errors.js +248 -0
  464. package/dist/compat/url/idna-data.d.ts +3958 -0
  465. package/dist/compat/url/idna-data.js +22 -0
  466. package/dist/compat/url/idna.d.ts +9 -0
  467. package/dist/compat/url/idna.js +47 -0
  468. package/dist/compat/url/index.d.ts +48 -0
  469. package/dist/compat/url/index.js +39 -0
  470. package/dist/compat/url/installation.d.ts +4 -0
  471. package/dist/compat/url/installation.js +61 -0
  472. package/dist/compat/url/internal-url.d.ts +34 -0
  473. package/dist/compat/url/internal-url.js +264 -0
  474. package/dist/compat/url/legacy-url.d.ts +28 -0
  475. package/dist/compat/url/legacy-url.js +870 -0
  476. package/dist/compat/url/parser-platform.d.ts +3 -0
  477. package/dist/compat/url/parser-platform.js +26 -0
  478. package/dist/compat/url/standard-url.d.ts +2 -0
  479. package/dist/compat/url/standard-url.js +3189 -0
  480. package/dist/compat/url/unicode.d.ts +2 -0
  481. package/dist/compat/url/unicode.js +119 -0
  482. package/dist/compat/url/validation.d.ts +2 -0
  483. package/dist/compat/url/validation.js +9 -0
  484. package/dist/compat/url/web-url.d.ts +27 -0
  485. package/dist/compat/url/web-url.js +119 -0
  486. package/dist/compat/util/LICENSE-3RD-PARTY.md +5 -0
  487. package/dist/compat/util/LICENSE-APACHE +177 -0
  488. package/dist/compat/util/additional.d.ts +11 -0
  489. package/dist/compat/util/additional.js +121 -0
  490. package/dist/compat/util/comparison-types.d.ts +16 -0
  491. package/dist/compat/util/comparison-types.js +50 -0
  492. package/dist/compat/util/comparisons.d.ts +1 -0
  493. package/dist/compat/util/comparisons.js +527 -0
  494. package/dist/compat/util/core.d.ts +18 -0
  495. package/dist/compat/util/core.js +265 -0
  496. package/dist/compat/util/debuglog.d.ts +1 -0
  497. package/dist/compat/util/debuglog.js +78 -0
  498. package/dist/compat/util/index.d.ts +35 -0
  499. package/dist/compat/util/index.js +77 -0
  500. package/dist/compat/util/inspect-binding.d.ts +13 -0
  501. package/dist/compat/util/inspect-binding.js +39 -0
  502. package/dist/compat/util/inspect-types.d.ts +13 -0
  503. package/dist/compat/util/inspect-types.js +30 -0
  504. package/dist/compat/util/inspect.d.ts +152 -0
  505. package/dist/compat/util/inspect.js +2503 -0
  506. package/dist/compat/util/mime.d.ts +24 -0
  507. package/dist/compat/util/mime.js +284 -0
  508. package/dist/compat/util/properties.d.ts +9 -0
  509. package/dist/compat/util/properties.js +76 -0
  510. package/dist/compat/v8/LICENSE-3RD-PARTY.md +6 -0
  511. package/dist/compat/v8/LICENSE-APACHE +177 -0
  512. package/dist/compat/v8/errors.d.ts +5 -0
  513. package/dist/compat/v8/errors.js +7 -0
  514. package/dist/compat/v8/index.d.ts +106 -0
  515. package/dist/compat/v8/index.js +280 -0
  516. package/dist/compat/vm/LICENSE-3RD-PARTY.md +39 -0
  517. package/dist/compat/vm/LICENSE-APACHE +177 -0
  518. package/dist/compat/vm/errors.d.ts +5 -0
  519. package/dist/compat/vm/errors.js +7 -0
  520. package/dist/compat/vm/index.d.ts +47 -0
  521. package/dist/compat/vm/index.js +231 -0
  522. package/dist/compat/vm/validation.d.ts +3 -0
  523. package/dist/compat/vm/validation.js +14 -0
  524. package/dist/compat/wasi/LICENSE-3RD-PARTY.md +8 -0
  525. package/dist/compat/wasi/LICENSE-APACHE +177 -0
  526. package/dist/compat/wasi/errors.d.ts +4 -0
  527. package/dist/compat/wasi/errors.js +6 -0
  528. package/dist/compat/wasi/index.d.ts +15 -0
  529. package/dist/compat/wasi/index.js +44 -0
  530. package/dist/compat/worker-threads/LICENSE-3RD-PARTY.md +5 -0
  531. package/dist/compat/worker-threads/LICENSE-APACHE +177 -0
  532. package/dist/compat/worker-threads/errors.d.ts +4 -0
  533. package/dist/compat/worker-threads/errors.js +6 -0
  534. package/dist/compat/worker-threads/index.d.ts +71 -0
  535. package/dist/compat/worker-threads/index.js +138 -0
  536. package/dist/compat/worker-threads/message-channel.d.ts +18 -0
  537. package/dist/compat/worker-threads/message-channel.js +157 -0
  538. package/dist/configured.d.ts +3 -0
  539. package/dist/configured.js +4 -0
  540. package/dist/environment.d.ts +4 -0
  541. package/dist/environment.js +18 -0
  542. package/dist/index.d.ts +11 -0
  543. package/dist/index.js +107 -0
  544. package/dist/ios.d.ts +2 -0
  545. package/dist/ios.js +1 -0
  546. package/dist/native-entry.d.ts +8 -0
  547. package/dist/native-entry.js +67 -0
  548. package/dist/shared/brotli/LICENSE-APACHE +201 -0
  549. package/dist/shared/brotli/LICENSE-MIT +9 -0
  550. package/dist/shared/brotli/NOTICE +3 -0
  551. package/dist/shared/brotli/index.d.ts +2 -0
  552. package/dist/shared/brotli/index.js +288 -0
  553. package/dist/shared/contracts/index.d.ts +42 -0
  554. package/dist/shared/contracts/index.js +88 -0
  555. package/dist/shared/contracts/testing.d.ts +22 -0
  556. package/dist/shared/contracts/testing.js +57 -0
  557. package/dist/shared/globals/index.d.ts +3 -0
  558. package/dist/shared/globals/index.js +87 -0
  559. package/dist/shared/globals/inject.d.ts +2 -0
  560. package/dist/shared/globals/inject.js +3 -0
  561. package/dist/shared/globals/install.d.ts +1 -0
  562. package/dist/shared/globals/install.js +15 -0
  563. package/dist/shared/globals/node-install.d.ts +1 -0
  564. package/dist/shared/globals/node-install.js +4 -0
  565. package/dist/shared/globals/platform.d.ts +104 -0
  566. package/dist/shared/globals/platform.js +37 -0
  567. package/dist/shared/globals/runtime.d.ts +6 -0
  568. package/dist/shared/globals/runtime.js +8 -0
  569. package/dist/shared/globals/symbols.d.ts +4 -0
  570. package/dist/shared/globals/symbols.js +35 -0
  571. package/dist/shared/globals/web.d.ts +4 -0
  572. package/dist/shared/globals/web.js +108 -0
  573. package/dist/shared/http-wire/LICENSE.llhttp +22 -0
  574. package/dist/shared/http-wire/LICENSE.undici +21 -0
  575. package/dist/shared/http-wire/NOTICE.md +14 -0
  576. package/dist/shared/http-wire/index.d.ts +27 -0
  577. package/dist/shared/http-wire/index.js +132 -0
  578. package/dist/shared/http-wire/wasm.d.ts +2 -0
  579. package/dist/shared/http-wire/wasm.js +2 -0
  580. package/dist/tooling/async.d.ts +7 -0
  581. package/dist/tooling/async.js +99 -0
  582. package/dist/tooling/build-isolation.d.ts +4 -0
  583. package/dist/tooling/build-isolation.js +34 -0
  584. package/dist/tooling/documents.d.ts +7 -0
  585. package/dist/tooling/documents.js +26 -0
  586. package/dist/tooling/esbuild.d.ts +15 -0
  587. package/dist/tooling/esbuild.js +193 -0
  588. package/dist/tooling/files.d.ts +2 -0
  589. package/dist/tooling/files.js +18 -0
  590. package/dist/tooling/opennext/build.d.ts +1 -0
  591. package/dist/tooling/opennext/build.js +121 -0
  592. package/dist/tooling/opennext/index.d.ts +3 -0
  593. package/dist/tooling/opennext/index.js +213 -0
  594. package/dist/tooling/opennext/plan.d.ts +9 -0
  595. package/dist/tooling/opennext/plan.js +36 -0
  596. package/dist/tooling/opennext/safety.d.ts +4 -0
  597. package/dist/tooling/opennext/safety.js +36 -0
  598. package/dist/tooling/route-permissions.d.ts +3 -0
  599. package/dist/tooling/route-permissions.js +15 -0
  600. package/dist/tooling/server-modules.d.ts +30 -0
  601. package/dist/tooling/server-modules.js +98 -0
  602. package/dist/tooling/server-only-html.d.ts +1 -0
  603. package/dist/tooling/server-only-html.js +66 -0
  604. package/dist/tooling/server-only.d.ts +6 -0
  605. package/dist/tooling/server-only.js +53 -0
  606. package/dist/tooling/server.d.ts +25 -0
  607. package/dist/tooling/server.js +981 -0
  608. package/dist/tooling/shared.d.ts +13 -0
  609. package/dist/tooling/shared.js +130 -0
  610. package/dist/tooling/vite.d.ts +18 -0
  611. package/dist/tooling/vite.js +448 -0
  612. package/dist/tooling/void/index.d.ts +3 -0
  613. package/dist/tooling/void/index.js +205 -0
  614. package/dist/tooling/void/plan.d.ts +17 -0
  615. package/dist/tooling/void/plan.js +288 -0
  616. package/native/android/build.gradle +68 -0
  617. package/native/android/consumer-rules.pro +2 -0
  618. package/native/android/src/main/AndroidManifest.xml +6 -0
  619. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +202 -0
  620. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +256 -0
  621. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNative.java +22 -0
  622. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeActivity.java +178 -0
  623. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeBridge.java +45 -0
  624. package/native/ios/DocumentBridge.swift +330 -0
  625. package/native/ios/NetworkBridge.swift +51 -0
  626. package/native/ios/SocketBridge.swift +180 -0
  627. package/native/ios/WorkersCapacitorPlugin.swift +152 -0
  628. package/native/ios-host/WorkersView.swift +194 -0
  629. package/package.json +154 -4
@@ -0,0 +1,2503 @@
1
+ // @ts-nocheck
2
+ // Copyright (c) 2017-2022 Cloudflare, Inc.
3
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
4
+ // https://opensource.org/licenses/Apache-2.0
5
+ //
6
+ // Adapted from Deno, Node.js and DefinitelyTyped:
7
+ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
8
+ //
9
+ // Adapted from Node.js. Copyright Joyent, Inc. and other Node contributors.
10
+ //
11
+ // Permission is hereby granted, free of charge, to any person obtaining a
12
+ // copy of this software and associated documentation files (the
13
+ // "Software"), to deal in the Software without restriction, including
14
+ // without limitation the rights to use, copy, modify, merge, publish,
15
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ // persons to whom the Software is furnished to do so, subject to the
17
+ // following conditions:
18
+ //
19
+ // The above copyright notice and this permission notice shall be included
20
+ // in all copies or substantial portions of the Software.
21
+ //
22
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
25
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
28
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ /* TODO: the following is adopted code, enabling linting one day */
30
+ /* eslint-disable */
31
+ import internal from "./inspect-binding.js";
32
+ import { Buffer } from "node:buffer";
33
+ import { isAsyncFunction, isGeneratorFunction, isAnyArrayBuffer, isArrayBuffer, isArgumentsObject, isBoxedPrimitive, isDataView, isMap, isMapIterator, isModuleNamespaceObject, isNativeError, isPromise, isSet, isSetIterator, isWeakMap, isWeakSet, isRegExp, isDate, isTypedArray, isStringObject, isNumberObject, isBooleanObject, isBigIntObject, } from "./inspect-types.js";
34
+ // import { ALL_PROPERTIES, ONLY_ENUMERABLE, getOwnNonIndexProperties } from "node-internal:internal_utils";
35
+ import { validateObject, validateString, kValidateObjectAllowArray, } from "../net/validators.js";
36
+ // Simplified assertions to avoid `Assertions require every name in the call target to be
37
+ // declared with an explicit type` TypeScript error
38
+ function assert(value, message = "Assertion failed") {
39
+ if (!value)
40
+ throw new Error(message);
41
+ }
42
+ assert.fail = function (message = "Assertion failed") {
43
+ throw new Error(message);
44
+ };
45
+ function isError(e) {
46
+ // An error could be an instance of Error while not being a native error
47
+ // or could be from a different realm and not be instance of Error but still
48
+ // be a native error.
49
+ return isNativeError(e) || e instanceof Error;
50
+ }
51
+ const typedArrayPrototype = Object.getPrototypeOf(Uint8Array).prototype;
52
+ const typedArrayPrototypeLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "length").get;
53
+ const typedArrayPrototypeToStringTag = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
54
+ const setPrototypeSize = Object.getOwnPropertyDescriptor(Set.prototype, "size").get;
55
+ const mapPrototypeSize = Object.getOwnPropertyDescriptor(Map.prototype, "size").get;
56
+ let maxStack_ErrorName;
57
+ let maxStack_ErrorMessage;
58
+ function isStackOverflowError(err) {
59
+ if (maxStack_ErrorMessage === undefined) {
60
+ try {
61
+ function overflowStack() {
62
+ overflowStack();
63
+ }
64
+ overflowStack();
65
+ }
66
+ catch (err) {
67
+ assert(isError(err));
68
+ maxStack_ErrorMessage = err.message;
69
+ maxStack_ErrorName = err.name;
70
+ }
71
+ }
72
+ return (err &&
73
+ err.name === maxStack_ErrorName &&
74
+ err.message === maxStack_ErrorMessage);
75
+ }
76
+ export const customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
77
+ const colorRegExp = /\u001b\[\d\d?m/g;
78
+ function removeColors(str) {
79
+ return str.replace(colorRegExp, "");
80
+ }
81
+ const builtInObjects = new Set(Object.getOwnPropertyNames(globalThis).filter((e) => /^[A-Z][a-zA-Z0-9]+$/.exec(e) !== null));
82
+ // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
83
+ const isUndetectableObject = (v) => typeof v === "undefined" && v !== undefined;
84
+ // These options must stay in sync with `getUserOptions`. So if any option will
85
+ // be added or removed, `getUserOptions` must also be updated accordingly.
86
+ export const inspectDefaultOptions = Object.seal({
87
+ showHidden: false,
88
+ depth: 2,
89
+ colors: false,
90
+ customInspect: true,
91
+ showProxy: false,
92
+ maxArrayLength: 100,
93
+ maxStringLength: 10000,
94
+ breakLength: 80,
95
+ compact: 3,
96
+ sorted: false,
97
+ getters: false,
98
+ numericSeparator: false,
99
+ });
100
+ const kObjectType = 0;
101
+ const kArrayType = 1;
102
+ const kArrayExtrasType = 2;
103
+ const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c\x7f-\x9f]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
104
+ const strEscapeSequencesReplacer = /[\x00-\x1f\x27\x5c\x7f-\x9f]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
105
+ const strEscapeSequencesRegExpSingle = /[\x00-\x1f\x5c\x7f-\x9f]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
106
+ const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c\x7f-\x9f]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
107
+ const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/;
108
+ const numberRegExp = /^(0|[1-9][0-9]*)$/;
109
+ const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g;
110
+ const classRegExp = /^(\s+[^(]*?)\s*{/;
111
+ // eslint-disable-next-line node-core/no-unescaped-regexp-dot
112
+ const stripCommentsRegExp = /(\/\/.*?\n)|(\/\*(.|\n)*?\*\/)/g;
113
+ const kMinLineLength = 16;
114
+ // Constants to map the iterator state.
115
+ const kWeak = 0;
116
+ const kIterator = 1;
117
+ const kMapEntries = 2;
118
+ // Escaped control characters (plus the single quote and the backslash). Use
119
+ // empty strings to fill up unused entries.
120
+ const meta = [
121
+ "\\x00",
122
+ "\\x01",
123
+ "\\x02",
124
+ "\\x03",
125
+ "\\x04",
126
+ "\\x05",
127
+ "\\x06",
128
+ "\\x07", // x07
129
+ "\\b",
130
+ "\\t",
131
+ "\\n",
132
+ "\\x0B",
133
+ "\\f",
134
+ "\\r",
135
+ "\\x0E",
136
+ "\\x0F", // x0F
137
+ "\\x10",
138
+ "\\x11",
139
+ "\\x12",
140
+ "\\x13",
141
+ "\\x14",
142
+ "\\x15",
143
+ "\\x16",
144
+ "\\x17", // x17
145
+ "\\x18",
146
+ "\\x19",
147
+ "\\x1A",
148
+ "\\x1B",
149
+ "\\x1C",
150
+ "\\x1D",
151
+ "\\x1E",
152
+ "\\x1F", // x1F
153
+ "",
154
+ "",
155
+ "",
156
+ "",
157
+ "",
158
+ "",
159
+ "",
160
+ "\\'",
161
+ "",
162
+ "",
163
+ "",
164
+ "",
165
+ "",
166
+ "",
167
+ "",
168
+ "", // x2F
169
+ "",
170
+ "",
171
+ "",
172
+ "",
173
+ "",
174
+ "",
175
+ "",
176
+ "",
177
+ "",
178
+ "",
179
+ "",
180
+ "",
181
+ "",
182
+ "",
183
+ "",
184
+ "", // x3F
185
+ "",
186
+ "",
187
+ "",
188
+ "",
189
+ "",
190
+ "",
191
+ "",
192
+ "",
193
+ "",
194
+ "",
195
+ "",
196
+ "",
197
+ "",
198
+ "",
199
+ "",
200
+ "", // x4F
201
+ "",
202
+ "",
203
+ "",
204
+ "",
205
+ "",
206
+ "",
207
+ "",
208
+ "",
209
+ "",
210
+ "",
211
+ "",
212
+ "",
213
+ "\\\\",
214
+ "",
215
+ "",
216
+ "", // x5F
217
+ "",
218
+ "",
219
+ "",
220
+ "",
221
+ "",
222
+ "",
223
+ "",
224
+ "",
225
+ "",
226
+ "",
227
+ "",
228
+ "",
229
+ "",
230
+ "",
231
+ "",
232
+ "", // x6F
233
+ "",
234
+ "",
235
+ "",
236
+ "",
237
+ "",
238
+ "",
239
+ "",
240
+ "",
241
+ "",
242
+ "",
243
+ "",
244
+ "",
245
+ "",
246
+ "",
247
+ "",
248
+ "\\x7F", // x7F
249
+ "\\x80",
250
+ "\\x81",
251
+ "\\x82",
252
+ "\\x83",
253
+ "\\x84",
254
+ "\\x85",
255
+ "\\x86",
256
+ "\\x87", // x87
257
+ "\\x88",
258
+ "\\x89",
259
+ "\\x8A",
260
+ "\\x8B",
261
+ "\\x8C",
262
+ "\\x8D",
263
+ "\\x8E",
264
+ "\\x8F", // x8F
265
+ "\\x90",
266
+ "\\x91",
267
+ "\\x92",
268
+ "\\x93",
269
+ "\\x94",
270
+ "\\x95",
271
+ "\\x96",
272
+ "\\x97", // x97
273
+ "\\x98",
274
+ "\\x99",
275
+ "\\x9A",
276
+ "\\x9B",
277
+ "\\x9C",
278
+ "\\x9D",
279
+ "\\x9E",
280
+ "\\x9F", // x9F
281
+ ];
282
+ // Regex used for ansi escape code splitting
283
+ // Adopted from https://github.com/chalk/ansi-regex/blob/HEAD/index.js
284
+ // License: MIT, authors: @sindresorhus, Qix-, arjunmehta and LitoMore
285
+ // Matches all ansi escape code sequences in a string
286
+ const ansiPattern = new RegExp("[\\u001B\\u009B][[\\]()#;?]*" +
287
+ "(?:(?:(?:(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]+)*" +
288
+ "|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]*)*)?" +
289
+ "(?:\\u0007|\\u001B\\u005C|\\u009C))" +
290
+ "|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?" +
291
+ "[\\dA-PR-TZcf-nq-uy=><~]))", "g");
292
+ const ansi = new RegExp(ansiPattern, "g");
293
+ function getUserOptions(ctx, isCrossContext) {
294
+ const ret = {
295
+ stylize: ctx.stylize,
296
+ showHidden: ctx.showHidden,
297
+ depth: ctx.depth,
298
+ colors: ctx.colors,
299
+ customInspect: ctx.customInspect,
300
+ showProxy: ctx.showProxy,
301
+ maxArrayLength: ctx.maxArrayLength,
302
+ maxStringLength: ctx.maxStringLength,
303
+ breakLength: ctx.breakLength,
304
+ compact: ctx.compact,
305
+ sorted: ctx.sorted,
306
+ getters: ctx.getters,
307
+ numericSeparator: ctx.numericSeparator,
308
+ ...ctx.userOptions,
309
+ };
310
+ // Typically, the target value will be an instance of `Object`. If that is
311
+ // *not* the case, the object may come from another vm.Context, and we want
312
+ // to avoid passing it objects from this Context in that case, so we remove
313
+ // the prototype from the returned object itself + the `stylize()` function,
314
+ // and remove all other non-primitives, including non-primitive user options.
315
+ if (isCrossContext) {
316
+ Object.setPrototypeOf(ret, null);
317
+ for (const key of Object.keys(ret)) {
318
+ if ((typeof ret[key] === "object" || typeof ret[key] === "function") &&
319
+ ret[key] !== null) {
320
+ delete ret[key];
321
+ }
322
+ }
323
+ ret.stylize = Object.setPrototypeOf((value, flavour) => {
324
+ let stylized;
325
+ try {
326
+ stylized = `${ctx.stylize(value, flavour)}`;
327
+ }
328
+ catch {
329
+ // Continue regardless of error.
330
+ }
331
+ if (typeof stylized !== "string")
332
+ return value;
333
+ // `stylized` is a string as it should be, which is safe to pass along.
334
+ return stylized;
335
+ }, null);
336
+ }
337
+ return ret;
338
+ }
339
+ export function inspect(value, opts) {
340
+ // Default options
341
+ const ctx = {
342
+ budget: {},
343
+ indentationLvl: 0,
344
+ seen: [],
345
+ currentDepth: 0,
346
+ stylize: stylizeNoColor,
347
+ showHidden: inspectDefaultOptions.showHidden,
348
+ depth: inspectDefaultOptions.depth,
349
+ colors: inspectDefaultOptions.colors,
350
+ customInspect: inspectDefaultOptions.customInspect,
351
+ showProxy: inspectDefaultOptions.showProxy,
352
+ maxArrayLength: inspectDefaultOptions.maxArrayLength,
353
+ maxStringLength: inspectDefaultOptions.maxStringLength,
354
+ breakLength: inspectDefaultOptions.breakLength,
355
+ compact: inspectDefaultOptions.compact,
356
+ sorted: inspectDefaultOptions.sorted,
357
+ getters: inspectDefaultOptions.getters,
358
+ numericSeparator: inspectDefaultOptions.numericSeparator,
359
+ };
360
+ if (arguments.length > 1) {
361
+ // Legacy...
362
+ if (arguments.length > 2) {
363
+ if (arguments[2] !== undefined) {
364
+ ctx.depth = arguments[2];
365
+ }
366
+ if (arguments.length > 3 && arguments[3] !== undefined) {
367
+ ctx.colors = arguments[3];
368
+ }
369
+ }
370
+ // Set user-specified options
371
+ if (typeof opts === "boolean") {
372
+ ctx.showHidden = opts;
373
+ }
374
+ else if (opts) {
375
+ const optKeys = Object.keys(opts);
376
+ for (let i = 0; i < optKeys.length; ++i) {
377
+ const key = optKeys[i];
378
+ // TODO(BridgeAR): Find a solution what to do about stylize. Either make
379
+ // this function public or add a new API with a similar or better
380
+ // functionality.
381
+ if (Object.prototype.hasOwnProperty.call(inspectDefaultOptions, key) ||
382
+ key === "stylize") {
383
+ ctx[key] =
384
+ opts[key];
385
+ }
386
+ else if (ctx.userOptions === undefined) {
387
+ // This is required to pass through the actual user input.
388
+ ctx.userOptions = opts;
389
+ }
390
+ }
391
+ }
392
+ }
393
+ if (ctx.colors)
394
+ ctx.stylize = stylizeWithColor;
395
+ if (ctx.maxArrayLength === null)
396
+ ctx.maxArrayLength = Infinity;
397
+ if (ctx.maxStringLength === null)
398
+ ctx.maxStringLength = Infinity;
399
+ return formatValue(ctx, value, 0);
400
+ }
401
+ inspect.custom = customInspectSymbol;
402
+ Object.defineProperty(inspect, "defaultOptions", {
403
+ get() {
404
+ return inspectDefaultOptions;
405
+ },
406
+ set(options) {
407
+ validateObject(options, "options");
408
+ return Object.assign(inspectDefaultOptions, options);
409
+ },
410
+ });
411
+ // Set Graphics Rendition https://en.wikipedia.org/wiki/ANSI_escape_code#graphics
412
+ // Each color consists of an array with the color code as first entry and the
413
+ // reset code as second entry.
414
+ const defaultFG = 39;
415
+ const defaultBG = 49;
416
+ const colors = {
417
+ // @ts-ignore
418
+ __proto__: null,
419
+ reset: [0, 0],
420
+ bold: [1, 22],
421
+ dim: [2, 22], // Alias: faint
422
+ italic: [3, 23],
423
+ underline: [4, 24],
424
+ blink: [5, 25],
425
+ // Swap foreground and background colors
426
+ inverse: [7, 27], // Alias: swapcolors, swapColors
427
+ hidden: [8, 28], // Alias: conceal
428
+ strikethrough: [9, 29], // Alias: strikeThrough, crossedout, crossedOut
429
+ doubleunderline: [21, 24], // Alias: doubleUnderline
430
+ black: [30, defaultFG],
431
+ red: [31, defaultFG],
432
+ green: [32, defaultFG],
433
+ yellow: [33, defaultFG],
434
+ blue: [34, defaultFG],
435
+ magenta: [35, defaultFG],
436
+ cyan: [36, defaultFG],
437
+ white: [37, defaultFG],
438
+ bgBlack: [40, defaultBG],
439
+ bgRed: [41, defaultBG],
440
+ bgGreen: [42, defaultBG],
441
+ bgYellow: [43, defaultBG],
442
+ bgBlue: [44, defaultBG],
443
+ bgMagenta: [45, defaultBG],
444
+ bgCyan: [46, defaultBG],
445
+ bgWhite: [47, defaultBG],
446
+ framed: [51, 54],
447
+ overlined: [53, 55],
448
+ gray: [90, defaultFG], // Alias: grey, blackBright
449
+ redBright: [91, defaultFG],
450
+ greenBright: [92, defaultFG],
451
+ yellowBright: [93, defaultFG],
452
+ blueBright: [94, defaultFG],
453
+ magentaBright: [95, defaultFG],
454
+ cyanBright: [96, defaultFG],
455
+ whiteBright: [97, defaultFG],
456
+ bgGray: [100, defaultBG], // Alias: bgGrey, bgBlackBright
457
+ bgRedBright: [101, defaultBG],
458
+ bgGreenBright: [102, defaultBG],
459
+ bgYellowBright: [103, defaultBG],
460
+ bgBlueBright: [104, defaultBG],
461
+ bgMagentaBright: [105, defaultBG],
462
+ bgCyanBright: [106, defaultBG],
463
+ bgWhiteBright: [107, defaultBG],
464
+ };
465
+ inspect.colors = colors;
466
+ function defineColorAlias(target, alias) {
467
+ Object.defineProperty(inspect.colors, alias, {
468
+ get() {
469
+ return this[target];
470
+ },
471
+ set(value) {
472
+ this[target] = value;
473
+ },
474
+ configurable: true,
475
+ enumerable: false,
476
+ });
477
+ }
478
+ defineColorAlias("gray", "grey");
479
+ defineColorAlias("gray", "blackBright");
480
+ defineColorAlias("bgGray", "bgGrey");
481
+ defineColorAlias("bgGray", "bgBlackBright");
482
+ defineColorAlias("dim", "faint");
483
+ defineColorAlias("strikethrough", "crossedout");
484
+ defineColorAlias("strikethrough", "strikeThrough");
485
+ defineColorAlias("strikethrough", "crossedOut");
486
+ defineColorAlias("hidden", "conceal");
487
+ defineColorAlias("inverse", "swapColors");
488
+ defineColorAlias("inverse", "swapcolors");
489
+ defineColorAlias("doubleunderline", "doubleUnderline");
490
+ // TODO(BridgeAR): Add function style support for more complex styles.
491
+ // Don't use 'blue' not visible on cmd.exe
492
+ inspect.styles = {
493
+ __proto__: null,
494
+ special: "cyan",
495
+ number: "yellow",
496
+ bigint: "yellow",
497
+ boolean: "yellow",
498
+ undefined: "grey",
499
+ null: "bold",
500
+ string: "green",
501
+ symbol: "green",
502
+ date: "magenta",
503
+ name: undefined,
504
+ // TODO(BridgeAR): Highlight regular expressions properly.
505
+ regexp: "red",
506
+ module: "underline",
507
+ };
508
+ function addQuotes(str, quotes) {
509
+ if (quotes === -1) {
510
+ return `"${str}"`;
511
+ }
512
+ if (quotes === -2) {
513
+ return `\`${str}\``;
514
+ }
515
+ return `'${str}'`;
516
+ }
517
+ function escapeFn(str) {
518
+ const charCode = str.charCodeAt(0);
519
+ return meta.length > charCode
520
+ ? meta[charCode]
521
+ : `\\u${charCode.toString(16)}`;
522
+ }
523
+ // Escape control characters, single quotes and the backslash.
524
+ // This is similar to JSON stringify escaping.
525
+ function strEscape(str) {
526
+ let escapeTest = strEscapeSequencesRegExp;
527
+ let escapeReplace = strEscapeSequencesReplacer;
528
+ let singleQuote = 39;
529
+ // Check for double quotes. If not present, do not escape single quotes and
530
+ // instead wrap the text in double quotes. If double quotes exist, check for
531
+ // backticks. If they do not exist, use those as fallback instead of the
532
+ // double quotes.
533
+ if (str.includes("'")) {
534
+ // This invalidates the charCode and therefore can not be matched for
535
+ // anymore.
536
+ if (!str.includes('"')) {
537
+ singleQuote = -1;
538
+ }
539
+ else if (!str.includes("`") && !str.includes("${")) {
540
+ singleQuote = -2;
541
+ }
542
+ if (singleQuote !== 39) {
543
+ escapeTest = strEscapeSequencesRegExpSingle;
544
+ escapeReplace = strEscapeSequencesReplacerSingle;
545
+ }
546
+ }
547
+ // Some magic numbers that worked out fine while benchmarking with v8 6.0
548
+ if (str.length < 5000 && escapeTest.exec(str) === null)
549
+ return addQuotes(str, singleQuote);
550
+ if (str.length > 100) {
551
+ str = str.replace(escapeReplace, escapeFn);
552
+ return addQuotes(str, singleQuote);
553
+ }
554
+ let result = "";
555
+ let last = 0;
556
+ for (let i = 0; i < str.length; i++) {
557
+ const point = str.charCodeAt(i);
558
+ if (point === singleQuote ||
559
+ point === 92 ||
560
+ point < 32 ||
561
+ (point > 126 && point < 160)) {
562
+ if (last === i) {
563
+ result += meta[point];
564
+ }
565
+ else {
566
+ result += `${str.slice(last, i)}${meta[point]}`;
567
+ }
568
+ last = i + 1;
569
+ }
570
+ else if (point >= 0xd800 && point <= 0xdfff) {
571
+ if (point <= 0xdbff && i + 1 < str.length) {
572
+ const point = str.charCodeAt(i + 1);
573
+ if (point >= 0xdc00 && point <= 0xdfff) {
574
+ i++;
575
+ continue;
576
+ }
577
+ }
578
+ result += `${str.slice(last, i)}\\u${point.toString(16)}`;
579
+ last = i + 1;
580
+ }
581
+ }
582
+ if (last !== str.length) {
583
+ result += str.slice(last);
584
+ }
585
+ return addQuotes(result, singleQuote);
586
+ }
587
+ function stylizeWithColor(str, styleType) {
588
+ const style = inspect.styles[styleType];
589
+ if (style !== undefined) {
590
+ const color = inspect.colors[style];
591
+ if (color !== undefined)
592
+ return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`;
593
+ }
594
+ return str;
595
+ }
596
+ function stylizeNoColor(str) {
597
+ return str;
598
+ }
599
+ // Return a new empty array to push in the results of the default formatter.
600
+ function getEmptyFormatArray() {
601
+ return [];
602
+ }
603
+ function isInstanceof(object, proto) {
604
+ try {
605
+ return object instanceof proto;
606
+ }
607
+ catch {
608
+ return false;
609
+ }
610
+ }
611
+ // Special-case for some builtin prototypes in case their `constructor` property has been tampered.
612
+ const wellKnownPrototypes = new Map()
613
+ .set(Array.prototype, { name: "Array", constructor: Array })
614
+ .set(ArrayBuffer.prototype, { name: "ArrayBuffer", constructor: ArrayBuffer })
615
+ .set(Function.prototype, { name: "Function", constructor: Function })
616
+ .set(Map.prototype, { name: "Map", constructor: Map })
617
+ .set(Set.prototype, { name: "Set", constructor: Set })
618
+ .set(Object.prototype, { name: "Object", constructor: Object })
619
+ .set(Object.getPrototypeOf(Uint8Array).prototype, {
620
+ name: "TypedArray",
621
+ constructor: Object.getPrototypeOf(Uint8Array),
622
+ })
623
+ .set(RegExp.prototype, { name: "RegExp", constructor: RegExp })
624
+ .set(Date.prototype, { name: "Date", constructor: Date })
625
+ .set(DataView.prototype, { name: "DataView", constructor: DataView })
626
+ .set(Error.prototype, { name: "Error", constructor: Error })
627
+ .set(Boolean.prototype, { name: "Boolean", constructor: Boolean })
628
+ .set(Number.prototype, { name: "Number", constructor: Number })
629
+ .set(String.prototype, { name: "String", constructor: String })
630
+ .set(Promise.prototype, { name: "Promise", constructor: Promise })
631
+ .set(WeakMap.prototype, { name: "WeakMap", constructor: WeakMap })
632
+ .set(WeakSet.prototype, { name: "WeakSet", constructor: WeakSet });
633
+ function getConstructorName(obj, ctx, recurseTimes, protoProps) {
634
+ let firstProto;
635
+ const tmp = obj;
636
+ while (obj || isUndetectableObject(obj)) {
637
+ const wellKnownPrototypeNameAndConstructor = wellKnownPrototypes.get(obj);
638
+ if (wellKnownPrototypeNameAndConstructor !== undefined) {
639
+ const { name, constructor } = wellKnownPrototypeNameAndConstructor;
640
+ if (Function.prototype[Symbol.hasInstance].call(constructor, tmp)) {
641
+ if (protoProps !== undefined && firstProto !== obj) {
642
+ addPrototypeProperties(ctx, tmp, firstProto || tmp, recurseTimes, protoProps);
643
+ }
644
+ return name;
645
+ }
646
+ }
647
+ const descriptor = Object.getOwnPropertyDescriptor(obj, "constructor");
648
+ if (descriptor !== undefined &&
649
+ typeof descriptor.value === "function" &&
650
+ descriptor.value.name !== "" &&
651
+ isInstanceof(tmp, descriptor.value)) {
652
+ if (protoProps !== undefined &&
653
+ (firstProto !== obj || !builtInObjects.has(descriptor.value.name))) {
654
+ addPrototypeProperties(ctx, tmp, firstProto || tmp, recurseTimes, protoProps);
655
+ }
656
+ return String(descriptor.value.name);
657
+ }
658
+ obj = Object.getPrototypeOf(obj);
659
+ if (firstProto === undefined) {
660
+ firstProto = obj;
661
+ }
662
+ }
663
+ if (firstProto === null) {
664
+ return null;
665
+ }
666
+ const res = internal.getConstructorName(tmp);
667
+ if (ctx.depth !== null && recurseTimes > ctx.depth) {
668
+ return `${res} <Complex prototype>`;
669
+ }
670
+ const protoConstr = getConstructorName(firstProto, ctx, recurseTimes + 1, protoProps);
671
+ if (protoConstr === null) {
672
+ return `${res} <${inspect(firstProto, {
673
+ ...ctx,
674
+ customInspect: false,
675
+ depth: -1,
676
+ })}>`;
677
+ }
678
+ return `${res} <${protoConstr}>`;
679
+ }
680
+ // This function has the side effect of adding prototype properties to the
681
+ // `output` argument (which is an array). This is intended to highlight user
682
+ // defined prototype properties.
683
+ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
684
+ let depth = 0;
685
+ let keys;
686
+ let keySet;
687
+ do {
688
+ if (depth !== 0 || main === obj) {
689
+ obj = Object.getPrototypeOf(obj);
690
+ // Stop as soon as a null prototype is encountered.
691
+ if (obj === null) {
692
+ return;
693
+ }
694
+ // Stop as soon as a built-in object type is detected.
695
+ const descriptor = Object.getOwnPropertyDescriptor(obj, "constructor");
696
+ if (descriptor !== undefined &&
697
+ typeof descriptor.value === "function" &&
698
+ builtInObjects.has(descriptor.value.name)) {
699
+ return;
700
+ }
701
+ }
702
+ if (depth === 0) {
703
+ keySet = new Set();
704
+ }
705
+ else {
706
+ keys.forEach((key) => keySet.add(key));
707
+ }
708
+ // Get all own property names and symbols.
709
+ keys = Reflect.ownKeys(obj);
710
+ ctx.seen.push(main);
711
+ for (const key of keys) {
712
+ // Ignore the `constructor` property and keys that exist on layers above.
713
+ if (key === "constructor" ||
714
+ Object.prototype.hasOwnProperty.call(main, key) ||
715
+ (depth !== 0 && keySet.has(key))) {
716
+ continue;
717
+ }
718
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
719
+ if (typeof desc?.value === "function") {
720
+ continue;
721
+ }
722
+ const value = formatProperty(ctx, obj, recurseTimes, key, kObjectType, desc, main);
723
+ if (ctx.colors) {
724
+ // Faint!
725
+ output.push(`\u001b[2m${value}\u001b[22m`);
726
+ }
727
+ else {
728
+ output.push(value);
729
+ }
730
+ }
731
+ ctx.seen.pop();
732
+ // Limit the inspection to up to three prototype layers. Using `recurseTimes`
733
+ // is not a good choice here, because it's as if the properties are declared
734
+ // on the current object from the users perspective.
735
+ } while (++depth !== 3);
736
+ }
737
+ function getPrefix(constructor, tag, fallback, size = "") {
738
+ if (constructor === null) {
739
+ if (tag !== "" && fallback !== tag) {
740
+ return `[${fallback}${size}: null prototype] [${tag}] `;
741
+ }
742
+ return `[${fallback}${size}: null prototype] `;
743
+ }
744
+ if (tag !== "" && constructor !== tag) {
745
+ return `${constructor}${size} [${tag}] `;
746
+ }
747
+ return `${constructor}${size} `;
748
+ }
749
+ // Look up the keys of the object.
750
+ function getKeys(value, showHidden) {
751
+ let keys;
752
+ const symbols = Object.getOwnPropertySymbols(value);
753
+ if (showHidden) {
754
+ keys = Object.getOwnPropertyNames(value);
755
+ if (symbols.length !== 0)
756
+ keys.push(...symbols);
757
+ }
758
+ else {
759
+ // This might throw if `value` is a Module Namespace Object from an
760
+ // unevaluated module, but we don't want to perform the actual type
761
+ // check because it's expensive.
762
+ // TODO(devsnek): track https://github.com/tc39/ecma262/issues/1209
763
+ // and modify this logic as needed.
764
+ try {
765
+ keys = Object.keys(value);
766
+ }
767
+ catch (err) {
768
+ assert(isNativeError(err) &&
769
+ err.name === "ReferenceError" &&
770
+ isModuleNamespaceObject(value));
771
+ keys = Object.getOwnPropertyNames(value);
772
+ }
773
+ if (symbols.length !== 0) {
774
+ const filter = (key) => Object.prototype.propertyIsEnumerable.call(value, key);
775
+ keys.push(...symbols.filter(filter));
776
+ }
777
+ }
778
+ return keys;
779
+ }
780
+ function getCtxStyle(value, constructor, tag) {
781
+ let fallback = "";
782
+ if (constructor === null) {
783
+ fallback = internal.getConstructorName(value);
784
+ if (fallback === tag) {
785
+ fallback = "Object";
786
+ }
787
+ }
788
+ return getPrefix(constructor, tag, fallback);
789
+ }
790
+ function formatProxy(ctx, proxy, recurseTimes) {
791
+ if (ctx.depth !== null && recurseTimes > ctx.depth) {
792
+ return ctx.stylize("Proxy [Array]", "special");
793
+ }
794
+ recurseTimes += 1;
795
+ ctx.indentationLvl += 2;
796
+ const res = [
797
+ formatValue(ctx, proxy.target, recurseTimes),
798
+ formatValue(ctx, proxy.handler, recurseTimes),
799
+ ];
800
+ ctx.indentationLvl -= 2;
801
+ return reduceToSingleString(ctx, res, "", ["Proxy [", "]"], kArrayExtrasType, recurseTimes);
802
+ }
803
+ // Note: using `formatValue` directly requires the indentation level to be
804
+ // corrected by setting `ctx.indentationLvL += diff` and then to decrease the
805
+ // value afterwards again.
806
+ function formatValue(ctx, value, recurseTimes, typedArray) {
807
+ // Primitive types cannot have properties.
808
+ if (typeof value !== "object" &&
809
+ typeof value !== "function" &&
810
+ !isUndetectableObject(value)) {
811
+ return formatPrimitive(ctx.stylize, value, ctx);
812
+ }
813
+ if (value === null) {
814
+ return ctx.stylize("null", "null");
815
+ }
816
+ // Memorize the context for custom inspection on proxies.
817
+ const context = value;
818
+ let proxies = 0;
819
+ // Always check for proxies to prevent side effects and to prevent triggering
820
+ // any proxy handlers.
821
+ let proxy = internal.getProxyDetails(value);
822
+ if (proxy !== undefined) {
823
+ if (proxy === null || proxy.target === null) {
824
+ return ctx.stylize("<Revoked Proxy>", "special");
825
+ }
826
+ if (ctx.showProxy) {
827
+ return formatProxy(ctx, proxy, recurseTimes);
828
+ }
829
+ do {
830
+ if (proxy === null || proxy.target === null) {
831
+ let formatted = ctx.stylize("<Revoked Proxy>", "special");
832
+ for (let i = 0; i < proxies; i++) {
833
+ formatted = `${ctx.stylize("Proxy(", "special")}${formatted}${ctx.stylize(")", "special")}`;
834
+ }
835
+ return formatted;
836
+ }
837
+ value = proxy.target;
838
+ proxy = internal.getProxyDetails(value);
839
+ proxies += 1;
840
+ } while (proxy !== undefined);
841
+ }
842
+ // Provide a hook for user-specified inspect functions.
843
+ // Check that value is an object with an inspect function on it.
844
+ if (ctx.customInspect) {
845
+ let maybeCustom = value[customInspectSymbol];
846
+ // WORKERD SPECIFIC PATCH: if `value` is a JSG resource type, use a well-known custom inspect
847
+ const maybeResourceTypeInspect = value[internal.kResourceTypeInspect];
848
+ if (typeof maybeResourceTypeInspect === "object") {
849
+ maybeCustom = formatJsgResourceType.bind(context, maybeResourceTypeInspect);
850
+ }
851
+ if (typeof maybeCustom === "function" &&
852
+ // Filter out the util module, its inspect function is special.
853
+ maybeCustom !== inspect &&
854
+ // Also filter out any prototype objects using the circular check.
855
+ !(value.constructor &&
856
+ value.constructor.prototype === value)) {
857
+ // This makes sure the recurseTimes are reported as before while using
858
+ // a counter internally.
859
+ const depth = ctx.depth === null ? null : ctx.depth - recurseTimes;
860
+ const isCrossContext = proxies !== 0 || !(context instanceof Object);
861
+ const ret = Function.prototype.call.call(maybeCustom, context, depth, getUserOptions(ctx, isCrossContext), inspect);
862
+ // If the custom inspection method returned `this`, don't go into
863
+ // infinite recursion.
864
+ if (ret !== context) {
865
+ if (typeof ret !== "string") {
866
+ return formatValue(ctx, ret, recurseTimes);
867
+ }
868
+ return ret.replaceAll("\n", `\n${" ".repeat(ctx.indentationLvl)}`);
869
+ }
870
+ }
871
+ }
872
+ // Using an array here is actually better for the average case than using
873
+ // a Set. `seen` will only check for the depth and will never grow too large.
874
+ if (ctx.seen.includes(value)) {
875
+ let index = 1;
876
+ if (ctx.circular === undefined) {
877
+ ctx.circular = new Map();
878
+ ctx.circular.set(value, index);
879
+ }
880
+ else {
881
+ index = ctx.circular.get(value);
882
+ if (index === undefined) {
883
+ index = ctx.circular.size + 1;
884
+ ctx.circular.set(value, index);
885
+ }
886
+ }
887
+ return ctx.stylize(`[Circular *${index}]`, "special");
888
+ }
889
+ let formatted = formatRaw(ctx, value, recurseTimes, typedArray);
890
+ if (proxies !== 0) {
891
+ for (let i = 0; i < proxies; i++) {
892
+ formatted = `${ctx.stylize("Proxy(", "special")}${formatted}${ctx.stylize(")", "special")}`;
893
+ }
894
+ }
895
+ return formatted;
896
+ }
897
+ function formatRaw(ctx, value, recurseTimes, typedArray) {
898
+ let keys;
899
+ let protoProps;
900
+ if (ctx.showHidden && (ctx.depth === null || recurseTimes <= ctx.depth)) {
901
+ protoProps = [];
902
+ }
903
+ const constructor = getConstructorName(value, ctx, recurseTimes, protoProps);
904
+ // Reset the variable to check for this later on.
905
+ if (protoProps !== undefined && protoProps.length === 0) {
906
+ protoProps = undefined;
907
+ }
908
+ let tag = value[Symbol.toStringTag];
909
+ // Only list the tag in case it's non-enumerable / not an own property.
910
+ // Otherwise we'd print this twice.
911
+ if (typeof tag !== "string" ||
912
+ (tag !== "" &&
913
+ (ctx.showHidden
914
+ ? Object.prototype.hasOwnProperty
915
+ : Object.prototype.propertyIsEnumerable).call(value, Symbol.toStringTag))) {
916
+ tag = "";
917
+ }
918
+ let base = "";
919
+ let formatter = getEmptyFormatArray;
920
+ let braces;
921
+ let noIterator = true;
922
+ let i = 0;
923
+ const filter = ctx.showHidden
924
+ ? internal.ALL_PROPERTIES
925
+ : internal.ONLY_ENUMERABLE;
926
+ let extrasType = kObjectType;
927
+ // Iterators and the rest are split to reduce checks.
928
+ // We have to check all values in case the constructor is set to null.
929
+ // Otherwise it would not possible to identify all types properly.
930
+ const isEntriesObject = hasEntries(value);
931
+ if (Symbol.iterator in value ||
932
+ constructor === null ||
933
+ isEntriesObject) {
934
+ noIterator = false;
935
+ if (isEntriesObject) {
936
+ // WORKERD SPECIFIC PATCH: if `value` is an object with entries, format them like a map
937
+ const size = value[kEntries].length;
938
+ const prefix = getPrefix(constructor, tag, "Object", `(${size})`);
939
+ keys = getKeys(value, ctx.showHidden);
940
+ // Remove `kEntries` and `size` from keys
941
+ keys.splice(keys.indexOf(kEntries), 1);
942
+ const sizeIndex = keys.indexOf("size");
943
+ if (sizeIndex !== -1)
944
+ keys.splice(sizeIndex, 1);
945
+ formatter = formatMap.bind(null, value[kEntries][Symbol.iterator]());
946
+ if (size === 0 && keys.length === 0 && protoProps === undefined)
947
+ return `${prefix}{}`;
948
+ braces = [`${prefix}{`, "}"];
949
+ }
950
+ else if (Array.isArray(value)) {
951
+ // Only set the constructor for non ordinary ("Array [...]") arrays.
952
+ const prefix = constructor !== "Array" || tag !== ""
953
+ ? getPrefix(constructor, tag, "Array", `(${value.length})`)
954
+ : "";
955
+ keys = internal.getOwnNonIndexProperties(value, filter);
956
+ braces = [`${prefix}[`, "]"];
957
+ if (value.length === 0 && keys.length === 0 && protoProps === undefined)
958
+ return `${braces[0]}]`;
959
+ extrasType = kArrayExtrasType;
960
+ formatter = formatArray;
961
+ }
962
+ else if (isSet(value)) {
963
+ const size = setPrototypeSize.call(value);
964
+ const prefix = getPrefix(constructor, tag, "Set", `(${size})`);
965
+ keys = getKeys(value, ctx.showHidden);
966
+ formatter =
967
+ constructor !== null
968
+ ? formatSet.bind(null, value)
969
+ : formatSet.bind(null, Set.prototype.values.call(value));
970
+ if (size === 0 && keys.length === 0 && protoProps === undefined)
971
+ return `${prefix}{}`;
972
+ braces = [`${prefix}{`, "}"];
973
+ }
974
+ else if (isMap(value)) {
975
+ const size = mapPrototypeSize.call(value);
976
+ const prefix = getPrefix(constructor, tag, "Map", `(${size})`);
977
+ keys = getKeys(value, ctx.showHidden);
978
+ formatter =
979
+ constructor !== null
980
+ ? formatMap.bind(null, value)
981
+ : formatMap.bind(null, Map.prototype.entries.call(value));
982
+ if (size === 0 && keys.length === 0 && protoProps === undefined)
983
+ return `${prefix}{}`;
984
+ braces = [`${prefix}{`, "}"];
985
+ }
986
+ else if (isTypedArray(value)) {
987
+ keys = internal.getOwnNonIndexProperties(value, filter);
988
+ let bound = value;
989
+ let fallback = "";
990
+ if (constructor === null) {
991
+ fallback = typedArrayPrototypeToStringTag.call(value);
992
+ // Reconstruct the array information.
993
+ bound = new globalThis[fallback](value);
994
+ }
995
+ const size = typedArrayPrototypeLength.call(value);
996
+ const prefix = getPrefix(constructor, tag, fallback, `(${size})`);
997
+ braces = [`${prefix}[`, "]"];
998
+ if (value.length === 0 && keys.length === 0 && !ctx.showHidden)
999
+ return `${braces[0]}]`;
1000
+ // Special handle the value. The original value is required below. The
1001
+ // bound function is required to reconstruct missing information.
1002
+ formatter = formatTypedArray.bind(null, bound, size);
1003
+ extrasType = kArrayExtrasType;
1004
+ }
1005
+ else if (isMapIterator(value)) {
1006
+ keys = getKeys(value, ctx.showHidden);
1007
+ braces = getIteratorBraces("Map", tag);
1008
+ // Add braces to the formatter parameters.
1009
+ formatter = formatIterator.bind(null, braces);
1010
+ }
1011
+ else if (isSetIterator(value)) {
1012
+ keys = getKeys(value, ctx.showHidden);
1013
+ braces = getIteratorBraces("Set", tag);
1014
+ // Add braces to the formatter parameters.
1015
+ formatter = formatIterator.bind(null, braces);
1016
+ }
1017
+ else {
1018
+ noIterator = true;
1019
+ }
1020
+ }
1021
+ if (noIterator) {
1022
+ keys = getKeys(value, ctx.showHidden);
1023
+ braces = ["{", "}"];
1024
+ if (constructor === "Object") {
1025
+ if (isArgumentsObject(value)) {
1026
+ braces[0] = "[Arguments] {";
1027
+ }
1028
+ else if (tag !== "") {
1029
+ braces[0] = `${getPrefix(constructor, tag, "Object")}{`;
1030
+ }
1031
+ if (keys.length === 0 && protoProps === undefined) {
1032
+ return `${braces[0]}}`;
1033
+ }
1034
+ }
1035
+ else if (typeof value === "function") {
1036
+ base = getFunctionBase(ctx, value, constructor, tag);
1037
+ if (keys.length === 0 && protoProps === undefined)
1038
+ return ctx.stylize(base, "special");
1039
+ }
1040
+ else if (isRegExp(value)) {
1041
+ // Make RegExps say that they are RegExps
1042
+ base = RegExp.prototype.toString.call(constructor !== null ? value : new RegExp(value));
1043
+ const prefix = getPrefix(constructor, tag, "RegExp");
1044
+ if (prefix !== "RegExp ")
1045
+ base = `${prefix}${base}`;
1046
+ if ((keys.length === 0 && protoProps === undefined) ||
1047
+ (ctx.depth !== null && recurseTimes > ctx.depth)) {
1048
+ return ctx.stylize(base, "regexp");
1049
+ }
1050
+ }
1051
+ else if (isDate(value)) {
1052
+ // Make dates with properties first say the date
1053
+ base = Number.isNaN(Date.prototype.getTime.call(value))
1054
+ ? Date.prototype.toString.call(value)
1055
+ : Date.prototype.toISOString.call(value);
1056
+ const prefix = getPrefix(constructor, tag, "Date");
1057
+ if (prefix !== "Date ")
1058
+ base = `${prefix}${base}`;
1059
+ if (keys.length === 0 && protoProps === undefined) {
1060
+ return ctx.stylize(base, "date");
1061
+ }
1062
+ }
1063
+ else if (isError(value)) {
1064
+ base = formatError(value, constructor, tag, ctx, keys);
1065
+ if (keys.length === 0 && protoProps === undefined)
1066
+ return base;
1067
+ }
1068
+ else if (isAnyArrayBuffer(value)) {
1069
+ // Fast path for ArrayBuffer and SharedArrayBuffer.
1070
+ // Can't do the same for DataView because it has a non-primitive
1071
+ // .buffer property that we need to recurse for.
1072
+ const arrayType = isArrayBuffer(value)
1073
+ ? "ArrayBuffer"
1074
+ : "SharedArrayBuffer";
1075
+ const prefix = getPrefix(constructor, tag, arrayType);
1076
+ if (typedArray === undefined) {
1077
+ formatter = formatArrayBuffer;
1078
+ }
1079
+ else if (keys.length === 0 && protoProps === undefined) {
1080
+ return (prefix +
1081
+ `{ byteLength: ${formatNumber(ctx.stylize, value.byteLength, false)} }`);
1082
+ }
1083
+ braces[0] = `${prefix}{`;
1084
+ keys.unshift("byteLength");
1085
+ }
1086
+ else if (isDataView(value)) {
1087
+ braces[0] = `${getPrefix(constructor, tag, "DataView")}{`;
1088
+ // .buffer goes last, it's not a primitive like the others.
1089
+ keys.unshift("byteLength", "byteOffset", "buffer");
1090
+ }
1091
+ else if (isPromise(value)) {
1092
+ braces[0] = `${getPrefix(constructor, tag, "Promise")}{`;
1093
+ formatter = formatPromise;
1094
+ }
1095
+ else if (isWeakSet(value)) {
1096
+ braces[0] = `${getPrefix(constructor, tag, "WeakSet")}{`;
1097
+ formatter = ctx.showHidden ? formatWeakSet : formatWeakCollection;
1098
+ }
1099
+ else if (isWeakMap(value)) {
1100
+ braces[0] = `${getPrefix(constructor, tag, "WeakMap")}{`;
1101
+ formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
1102
+ }
1103
+ else if (isModuleNamespaceObject(value)) {
1104
+ braces[0] = `${getPrefix(constructor, tag, "Module")}{`;
1105
+ // Special handle keys for namespace objects.
1106
+ formatter = formatNamespaceObject.bind(null, keys);
1107
+ }
1108
+ else if (isBoxedPrimitive(value)) {
1109
+ base = getBoxedBase(value, ctx, keys, constructor, tag);
1110
+ if (keys.length === 0 && protoProps === undefined) {
1111
+ return base;
1112
+ }
1113
+ }
1114
+ else {
1115
+ if (keys.length === 0 && protoProps === undefined) {
1116
+ return `${getCtxStyle(value, constructor, tag)}{}`;
1117
+ }
1118
+ braces[0] = `${getCtxStyle(value, constructor, tag)}{`;
1119
+ }
1120
+ }
1121
+ if (ctx.depth !== null && recurseTimes > ctx.depth) {
1122
+ let constructorName = getCtxStyle(value, constructor, tag).slice(0, -1);
1123
+ if (constructor !== null)
1124
+ constructorName = `[${constructorName}]`;
1125
+ return ctx.stylize(constructorName, "special");
1126
+ }
1127
+ recurseTimes += 1;
1128
+ ctx.seen.push(value);
1129
+ ctx.currentDepth = recurseTimes;
1130
+ let output;
1131
+ const indentationLvl = ctx.indentationLvl;
1132
+ try {
1133
+ output = formatter(ctx, value, recurseTimes);
1134
+ for (i = 0; i < keys.length; i++) {
1135
+ output.push(formatProperty(ctx, value, recurseTimes, keys[i], extrasType));
1136
+ }
1137
+ if (protoProps !== undefined) {
1138
+ output.push(...protoProps);
1139
+ }
1140
+ }
1141
+ catch (err) {
1142
+ const constructorName = getCtxStyle(value, constructor, tag).slice(0, -1);
1143
+ return handleMaxCallStackSize(ctx, err, constructorName, indentationLvl);
1144
+ }
1145
+ if (ctx.circular !== undefined) {
1146
+ const index = ctx.circular.get(value);
1147
+ if (index !== undefined) {
1148
+ const reference = ctx.stylize(`<ref *${index}>`, "special");
1149
+ // Add reference always to the very beginning of the output.
1150
+ if (ctx.compact !== true) {
1151
+ base = base === "" ? reference : `${reference} ${base}`;
1152
+ }
1153
+ else {
1154
+ braces[0] = `${reference} ${braces[0]}`;
1155
+ }
1156
+ }
1157
+ }
1158
+ ctx.seen.pop();
1159
+ if (ctx.sorted) {
1160
+ const comparator = ctx.sorted === true ? undefined : ctx.sorted;
1161
+ if (extrasType === kObjectType) {
1162
+ output.sort(comparator);
1163
+ }
1164
+ else if (keys.length > 1) {
1165
+ const sorted = output
1166
+ .slice(output.length - keys.length)
1167
+ .sort(comparator);
1168
+ output.splice(output.length - keys.length, keys.length, ...sorted);
1169
+ }
1170
+ }
1171
+ const res = reduceToSingleString(ctx, output, base, braces, extrasType, recurseTimes, value);
1172
+ const budget = ctx.budget[ctx.indentationLvl] || 0;
1173
+ const newLength = budget + res.length;
1174
+ ctx.budget[ctx.indentationLvl] = newLength;
1175
+ // If any indentationLvl exceeds this limit, limit further inspecting to the
1176
+ // minimum. Otherwise the recursive algorithm might continue inspecting the
1177
+ // object even though the maximum string size (~2 ** 28 on 32 bit systems and
1178
+ // ~2 ** 30 on 64 bit systems) exceeded. The actual output is not limited at
1179
+ // exactly 2 ** 27 but a bit higher. This depends on the object shape.
1180
+ // This limit also makes sure that huge objects don't block the event loop
1181
+ // significantly.
1182
+ if (newLength > 2 ** 27) {
1183
+ ctx.depth = -1;
1184
+ }
1185
+ return res;
1186
+ }
1187
+ function getIteratorBraces(type, tag) {
1188
+ if (tag !== `${type} Iterator`) {
1189
+ if (tag !== "")
1190
+ tag += "] [";
1191
+ tag += `${type} Iterator`;
1192
+ }
1193
+ return [`[${tag}] {`, "}"];
1194
+ }
1195
+ function getBoxedBase(value, ctx, keys, constructor, tag) {
1196
+ let fn;
1197
+ let type;
1198
+ if (isNumberObject(value)) {
1199
+ fn = Number.prototype.valueOf;
1200
+ type = "Number";
1201
+ }
1202
+ else if (isStringObject(value)) {
1203
+ fn = String.prototype.valueOf;
1204
+ type = "String";
1205
+ // For boxed Strings, we have to remove the 0-n indexed entries,
1206
+ // since they just noisy up the output and are redundant
1207
+ // Make boxed primitive Strings look like such
1208
+ keys.splice(0, value.length);
1209
+ }
1210
+ else if (isBooleanObject(value)) {
1211
+ fn = Boolean.prototype.valueOf;
1212
+ type = "Boolean";
1213
+ }
1214
+ else if (isBigIntObject(value)) {
1215
+ fn = BigInt.prototype.valueOf;
1216
+ type = "BigInt";
1217
+ }
1218
+ else {
1219
+ fn = Symbol.prototype.valueOf;
1220
+ type = "Symbol";
1221
+ }
1222
+ let base = `[${type}`;
1223
+ if (type !== constructor) {
1224
+ if (constructor === null) {
1225
+ base += " (null prototype)";
1226
+ }
1227
+ else {
1228
+ base += ` (${constructor})`;
1229
+ }
1230
+ }
1231
+ base += `: ${formatPrimitive(stylizeNoColor, fn.call(value), ctx)}]`;
1232
+ if (tag !== "" && tag !== constructor) {
1233
+ base += ` [${tag}]`;
1234
+ }
1235
+ if (keys.length !== 0 || ctx.stylize === stylizeNoColor)
1236
+ return base;
1237
+ return ctx.stylize(base, type.toLowerCase());
1238
+ }
1239
+ function getClassBase(value, constructor, tag) {
1240
+ const hasName = Object.prototype.hasOwnProperty.call(value, "name");
1241
+ const name = (hasName && value.name) || "(anonymous)";
1242
+ let base = `class ${name}`;
1243
+ if (constructor !== "Function" && constructor !== null) {
1244
+ base += ` [${constructor}]`;
1245
+ }
1246
+ if (tag !== "" && constructor !== tag) {
1247
+ base += ` [${tag}]`;
1248
+ }
1249
+ if (constructor !== null) {
1250
+ const superName = Object.getPrototypeOf(value).name;
1251
+ if (superName) {
1252
+ base += ` extends ${superName}`;
1253
+ }
1254
+ }
1255
+ else {
1256
+ base += " extends [null prototype]";
1257
+ }
1258
+ return `[${base}]`;
1259
+ }
1260
+ function getFunctionBase(ctx, value, constructor, tag) {
1261
+ const stringified = Function.prototype.toString.call(value);
1262
+ if (stringified.startsWith("class") && stringified.endsWith("}")) {
1263
+ const slice = stringified.slice(5, -1);
1264
+ const bracketIndex = slice.indexOf("{");
1265
+ if (bracketIndex !== -1 &&
1266
+ (!slice.slice(0, bracketIndex).includes("(") ||
1267
+ // Slow path to guarantee that it's indeed a class.
1268
+ classRegExp.exec(slice.replace(stripCommentsRegExp, "")) !== null)) {
1269
+ return getClassBase(value, constructor, tag);
1270
+ }
1271
+ }
1272
+ let type = "Function";
1273
+ if (isGeneratorFunction(value)) {
1274
+ type = `Generator${type}`;
1275
+ }
1276
+ if (isAsyncFunction(value)) {
1277
+ type = `Async${type}`;
1278
+ }
1279
+ let base = `[${type}`;
1280
+ if (constructor === null) {
1281
+ base += " (null prototype)";
1282
+ }
1283
+ if (value.name === "") {
1284
+ base += " (anonymous)";
1285
+ }
1286
+ else {
1287
+ base += `: ${typeof value.name === "string" ? value.name : formatValue(ctx, value.name, NaN)}`;
1288
+ }
1289
+ base += "]";
1290
+ if (constructor !== type && constructor !== null) {
1291
+ base += ` ${constructor}`;
1292
+ }
1293
+ if (tag !== "" && constructor !== tag) {
1294
+ base += ` [${tag}]`;
1295
+ }
1296
+ return base;
1297
+ }
1298
+ export function identicalSequenceRange(a, b) {
1299
+ for (let i = 0; i < a.length - 3; i++) {
1300
+ // Find the first entry of b that matches the current entry of a.
1301
+ const pos = b.indexOf(a[i]);
1302
+ if (pos !== -1) {
1303
+ const rest = b.length - pos;
1304
+ if (rest > 3) {
1305
+ let len = 1;
1306
+ const maxLen = Math.min(a.length - i, rest);
1307
+ // Count the number of consecutive entries.
1308
+ while (maxLen > len && a[i + len] === b[pos + len]) {
1309
+ len++;
1310
+ }
1311
+ if (len > 3) {
1312
+ return { len, offset: i };
1313
+ }
1314
+ }
1315
+ }
1316
+ }
1317
+ return { len: 0, offset: 0 };
1318
+ }
1319
+ function getStackString(ctx, error) {
1320
+ if (error.stack) {
1321
+ if (typeof error.stack === "string") {
1322
+ return error.stack;
1323
+ }
1324
+ // This 'NaN' is a very strange Nodeism, but is necessary for correct behaviour!
1325
+ return formatValue(ctx, error.stack, NaN);
1326
+ }
1327
+ return Error.prototype.toString.call(error);
1328
+ }
1329
+ function getStackFrames(ctx, err, stack) {
1330
+ const frames = stack.split("\n");
1331
+ let cause;
1332
+ try {
1333
+ ({ cause } = err);
1334
+ }
1335
+ catch {
1336
+ // If 'cause' is a getter that throws, ignore it.
1337
+ }
1338
+ // Remove stack frames identical to frames in cause.
1339
+ if (cause != null && isError(cause)) {
1340
+ const causeStack = getStackString(ctx, cause);
1341
+ const causeStackStart = causeStack.indexOf("\n at");
1342
+ if (causeStackStart !== -1) {
1343
+ const causeFrames = causeStack.slice(causeStackStart + 1).split("\n");
1344
+ const { len, offset } = identicalSequenceRange(frames, causeFrames);
1345
+ if (len > 0) {
1346
+ const skipped = len - 2;
1347
+ const msg = ` ... ${skipped} lines matching cause stack trace ...`;
1348
+ frames.splice(offset + 1, skipped, ctx.stylize(msg, "undefined"));
1349
+ }
1350
+ }
1351
+ }
1352
+ return frames;
1353
+ }
1354
+ function improveStack(stack, constructor, name, tag) {
1355
+ if (typeof name !== "string") {
1356
+ stack = stack.replace(`${name}`, `${name} [${getPrefix(constructor, tag, "Error").slice(0, -1)}]`);
1357
+ }
1358
+ // A stack trace may contain arbitrary data. Only manipulate the output
1359
+ // for "regular errors" (errors that "look normal") for now.
1360
+ let len = typeof name === "string" ? name.length : undefined;
1361
+ if (constructor === null ||
1362
+ (typeof name === "string" &&
1363
+ name.endsWith("Error") &&
1364
+ stack.startsWith(name) &&
1365
+ (stack.length === len ||
1366
+ stack[len] === ":" ||
1367
+ stack[len] === "\n"))) {
1368
+ let fallback = "Error";
1369
+ if (constructor === null) {
1370
+ const start = /^([A-Z][a-z_ A-Z0-9[\]()-]+)(?::|\n {4}at)/.exec(stack) ||
1371
+ /^([a-z_A-Z0-9-]*Error)$/.exec(stack);
1372
+ fallback = (start && start[1]) || "";
1373
+ len = fallback.length;
1374
+ fallback = fallback || "Error";
1375
+ }
1376
+ const prefix = getPrefix(constructor, tag, fallback).slice(0, -1);
1377
+ if (name !== prefix) {
1378
+ if (typeof name === "string" && prefix.includes(name)) {
1379
+ if (len === 0) {
1380
+ stack = `${prefix}: ${stack}`;
1381
+ }
1382
+ else {
1383
+ stack = `${prefix}${stack.slice(len)}`;
1384
+ }
1385
+ }
1386
+ else {
1387
+ stack = `${prefix} [${name}]${stack.slice(len)}`;
1388
+ }
1389
+ }
1390
+ }
1391
+ return stack;
1392
+ }
1393
+ function removeDuplicateErrorKeys(ctx, keys, err, stack) {
1394
+ if (!ctx.showHidden && keys.length !== 0) {
1395
+ for (const name of ["name", "message", "stack"]) {
1396
+ const index = keys.indexOf(name);
1397
+ // Only hide the property in case it's part of the original stack
1398
+ if (index !== -1 &&
1399
+ (typeof err[name] !== "string" || stack.includes(err[name]))) {
1400
+ keys.splice(index, 1);
1401
+ }
1402
+ }
1403
+ }
1404
+ }
1405
+ function markNodeModules(ctx, line) {
1406
+ let tempLine = "";
1407
+ let nodeModule;
1408
+ let pos = 0;
1409
+ while ((nodeModule = nodeModulesRegExp.exec(line)) !== null) {
1410
+ // '/node_modules/'.length === 14
1411
+ tempLine += line.slice(pos, nodeModule.index + 14);
1412
+ tempLine += ctx.stylize(nodeModule[1], "module");
1413
+ pos = nodeModule.index + nodeModule[0].length;
1414
+ }
1415
+ if (pos !== 0) {
1416
+ line = tempLine + line.slice(pos);
1417
+ }
1418
+ return line;
1419
+ }
1420
+ function formatError(err, constructor, tag, ctx, keys) {
1421
+ const name = err.name != null ? err.name : "Error";
1422
+ let stack = getStackString(ctx, err);
1423
+ removeDuplicateErrorKeys(ctx, keys, err, stack);
1424
+ if ("cause" in err && (keys.length === 0 || !keys.includes("cause"))) {
1425
+ keys.push("cause");
1426
+ }
1427
+ // Print errors aggregated into AggregateError
1428
+ if (Array.isArray(err.errors) &&
1429
+ (keys.length === 0 || !keys.includes("errors"))) {
1430
+ keys.push("errors");
1431
+ }
1432
+ stack = improveStack(stack, constructor, name, tag);
1433
+ // Ignore the error message if it's contained in the stack.
1434
+ let pos = (err.message && stack.indexOf(err.message)) || -1;
1435
+ if (pos !== -1)
1436
+ pos += err.message.length;
1437
+ // Wrap the error in brackets in case it has no stack trace.
1438
+ const stackStart = stack.indexOf("\n at", pos);
1439
+ if (stackStart === -1) {
1440
+ stack = `[${stack}]`;
1441
+ }
1442
+ else {
1443
+ let newStack = stack.slice(0, stackStart);
1444
+ const stackFramePart = stack.slice(stackStart + 1);
1445
+ const lines = getStackFrames(ctx, err, stackFramePart);
1446
+ if (ctx.colors) {
1447
+ // Highlight userland code and node modules.
1448
+ for (let line of lines) {
1449
+ newStack += "\n";
1450
+ line = markNodeModules(ctx, line);
1451
+ newStack += line;
1452
+ }
1453
+ }
1454
+ else {
1455
+ newStack += `\n${lines.join("\n")}`;
1456
+ }
1457
+ stack = newStack;
1458
+ }
1459
+ // The message and the stack have to be indented as well!
1460
+ if (ctx.indentationLvl !== 0) {
1461
+ const indentation = " ".repeat(ctx.indentationLvl);
1462
+ stack = stack.replaceAll("\n", `\n${indentation}`);
1463
+ }
1464
+ return stack;
1465
+ }
1466
+ function groupArrayElements(ctx, output, value) {
1467
+ let totalLength = 0;
1468
+ let maxLength = 0;
1469
+ let i = 0;
1470
+ let outputLength = output.length;
1471
+ if (ctx.maxArrayLength !== null && ctx.maxArrayLength < output.length) {
1472
+ // This makes sure the "... n more items" part is not taken into account.
1473
+ outputLength--;
1474
+ }
1475
+ const separatorSpace = 2; // Add 1 for the space and 1 for the separator.
1476
+ const dataLen = Array.from({ length: outputLength });
1477
+ // Calculate the total length of all output entries and the individual max
1478
+ // entries length of all output entries. We have to remove colors first,
1479
+ // otherwise the length would not be calculated properly.
1480
+ for (; i < outputLength; i++) {
1481
+ const len = getStringWidth(output[i], ctx.colors);
1482
+ dataLen[i] = len;
1483
+ totalLength += len + separatorSpace;
1484
+ if (maxLength < len)
1485
+ maxLength = len;
1486
+ }
1487
+ // Add two to `maxLength` as we add a single whitespace character plus a comma
1488
+ // in-between two entries.
1489
+ const actualMax = maxLength + separatorSpace;
1490
+ // Check if at least three entries fit next to each other and prevent grouping
1491
+ // of arrays that contains entries of very different length (i.e., if a single
1492
+ // entry is longer than 1/5 of all other entries combined). Otherwise the
1493
+ // space in-between small entries would be enormous.
1494
+ if (actualMax * 3 + ctx.indentationLvl < ctx.breakLength &&
1495
+ (totalLength / actualMax > 5 || maxLength <= 6)) {
1496
+ const approxCharHeights = 2.5;
1497
+ const averageBias = Math.sqrt(actualMax - totalLength / output.length);
1498
+ const biasedMax = Math.max(actualMax - 3 - averageBias, 1);
1499
+ // Dynamically check how many columns seem possible.
1500
+ const columns = Math.min(
1501
+ // Ideally a square should be drawn. We expect a character to be about 2.5
1502
+ // times as high as wide. This is the area formula to calculate a square
1503
+ // which contains n rectangles of size `actualMax * approxCharHeights`.
1504
+ // Divide that by `actualMax` to receive the correct number of columns.
1505
+ // The added bias increases the columns for short entries.
1506
+ Math.round(Math.sqrt(approxCharHeights * biasedMax * outputLength) / biasedMax),
1507
+ // Do not exceed the breakLength.
1508
+ Math.floor((ctx.breakLength - ctx.indentationLvl) / actualMax),
1509
+ // Limit array grouping for small `compact` modes as the user requested
1510
+ // minimal grouping.
1511
+ (ctx.compact === false
1512
+ ? 0
1513
+ : ctx.compact === true
1514
+ ? inspectDefaultOptions.compact
1515
+ : ctx.compact) * 4,
1516
+ // Limit the columns to a maximum of fifteen.
1517
+ 15);
1518
+ // Return with the original output if no grouping should happen.
1519
+ if (columns <= 1) {
1520
+ return output;
1521
+ }
1522
+ const tmp = [];
1523
+ const maxLineLength = [];
1524
+ for (let i = 0; i < columns; i++) {
1525
+ let lineMaxLength = 0;
1526
+ for (let j = i; j < output.length; j += columns) {
1527
+ if (dataLen[j] > lineMaxLength) {
1528
+ lineMaxLength = dataLen[j];
1529
+ }
1530
+ }
1531
+ lineMaxLength += separatorSpace;
1532
+ maxLineLength[i] = lineMaxLength;
1533
+ }
1534
+ let order = String.prototype.padStart;
1535
+ if (value !== undefined) {
1536
+ for (let i = 0; i < output.length; i++) {
1537
+ if (typeof value[i] !== "number" && typeof value[i] !== "bigint") {
1538
+ order = String.prototype.padEnd;
1539
+ break;
1540
+ }
1541
+ }
1542
+ }
1543
+ // Each iteration creates a single line of grouped entries.
1544
+ for (let i = 0; i < outputLength; i += columns) {
1545
+ // The last lines may contain less entries than columns.
1546
+ const max = Math.min(i + columns, outputLength);
1547
+ let str = "";
1548
+ let j = i;
1549
+ for (; j < max - 1; j++) {
1550
+ // Calculate extra color padding in case it's active. This has to be
1551
+ // done line by line as some lines might contain more colors than
1552
+ // others.
1553
+ const padding = maxLineLength[j - i] + output[j].length - dataLen[j];
1554
+ str += order.call(`${output[j]}, `, padding, " ");
1555
+ }
1556
+ if (order === String.prototype.padStart) {
1557
+ const padding = maxLineLength[j - i] +
1558
+ output[j].length -
1559
+ dataLen[j] -
1560
+ separatorSpace;
1561
+ str += output[j].padStart(padding, " ");
1562
+ }
1563
+ else {
1564
+ str += output[j];
1565
+ }
1566
+ tmp.push(str);
1567
+ }
1568
+ if (ctx.maxArrayLength !== null && ctx.maxArrayLength < output.length) {
1569
+ tmp.push(output[outputLength]);
1570
+ }
1571
+ output = tmp;
1572
+ }
1573
+ return output;
1574
+ }
1575
+ function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) {
1576
+ if (isStackOverflowError(err)) {
1577
+ ctx.seen.pop();
1578
+ ctx.indentationLvl = indentationLvl;
1579
+ return ctx.stylize(`[${constructorName}: Inspection interrupted ` +
1580
+ "prematurely. Maximum call stack size exceeded.]", "special");
1581
+ }
1582
+ /* c8 ignore next */
1583
+ assert.fail(err.stack);
1584
+ }
1585
+ function addNumericSeparator(integerString) {
1586
+ let result = "";
1587
+ let i = integerString.length;
1588
+ const start = integerString.startsWith("-") ? 1 : 0;
1589
+ for (; i >= start + 4; i -= 3) {
1590
+ result = `_${integerString.slice(i - 3, i)}${result}`;
1591
+ }
1592
+ return i === integerString.length
1593
+ ? integerString
1594
+ : `${integerString.slice(0, i)}${result}`;
1595
+ }
1596
+ function addNumericSeparatorEnd(integerString) {
1597
+ let result = "";
1598
+ let i = 0;
1599
+ for (; i < integerString.length - 3; i += 3) {
1600
+ result += `${integerString.slice(i, i + 3)}_`;
1601
+ }
1602
+ return i === 0 ? integerString : `${result}${integerString.slice(i)}`;
1603
+ }
1604
+ const remainingText = (remaining) => `... ${remaining} more item${remaining > 1 ? "s" : ""}`;
1605
+ function formatNumber(fn, number, numericSeparator) {
1606
+ if (!numericSeparator) {
1607
+ // Format -0 as '-0'. Checking `number === -0` won't distinguish 0 from -0.
1608
+ if (Object.is(number, -0)) {
1609
+ return fn("-0", "number");
1610
+ }
1611
+ return fn(`${number}`, "number");
1612
+ }
1613
+ const integer = Math.trunc(number);
1614
+ const string = String(integer);
1615
+ if (integer === number) {
1616
+ if (!Number.isFinite(number) || string.includes("e")) {
1617
+ return fn(string, "number");
1618
+ }
1619
+ return fn(`${addNumericSeparator(string)}`, "number");
1620
+ }
1621
+ if (Number.isNaN(number)) {
1622
+ return fn(string, "number");
1623
+ }
1624
+ return fn(`${addNumericSeparator(string)}.${addNumericSeparatorEnd(String(number).slice(string.length + 1))}`, "number");
1625
+ }
1626
+ function formatBigInt(fn, bigint, numericSeparator) {
1627
+ const string = String(bigint);
1628
+ if (!numericSeparator) {
1629
+ return fn(`${string}n`, "bigint");
1630
+ }
1631
+ return fn(`${addNumericSeparator(string)}n`, "bigint");
1632
+ }
1633
+ function formatPrimitive(fn, value, ctx) {
1634
+ if (typeof value === "string") {
1635
+ let trailer = "";
1636
+ if (ctx.maxStringLength !== null && value.length > ctx.maxStringLength) {
1637
+ const remaining = value.length - ctx.maxStringLength;
1638
+ value = value.slice(0, ctx.maxStringLength);
1639
+ trailer = `... ${remaining} more character${remaining > 1 ? "s" : ""}`;
1640
+ }
1641
+ if (ctx.compact !== true &&
1642
+ // We do not support handling Unicode characters width with
1643
+ // the readline getStringWidth function as there are
1644
+ // performance implications.
1645
+ value.length > kMinLineLength &&
1646
+ value.length > ctx.breakLength - ctx.indentationLvl - 4) {
1647
+ return (value
1648
+ .split(/(?<=\n)/)
1649
+ .map((line) => fn(strEscape(line), "string"))
1650
+ .join(` +\n${" ".repeat(ctx.indentationLvl + 2)}`) + trailer);
1651
+ }
1652
+ return fn(strEscape(value), "string") + trailer;
1653
+ }
1654
+ if (typeof value === "number")
1655
+ return formatNumber(fn, value, ctx.numericSeparator);
1656
+ if (typeof value === "bigint")
1657
+ return formatBigInt(fn, value, ctx.numericSeparator);
1658
+ if (typeof value === "boolean")
1659
+ return fn(`${value}`, "boolean");
1660
+ if (typeof value === "undefined")
1661
+ return fn("undefined", "undefined");
1662
+ // es6 symbol primitive
1663
+ return fn(Symbol.prototype.toString.call(value), "symbol");
1664
+ }
1665
+ function formatNamespaceObject(keys, ctx, value, recurseTimes) {
1666
+ const output = new Array(keys.length);
1667
+ for (let i = 0; i < keys.length; i++) {
1668
+ try {
1669
+ output[i] = formatProperty(ctx, value, recurseTimes, keys[i], kObjectType);
1670
+ }
1671
+ catch (err) {
1672
+ assert(isNativeError(err) && err.name === "ReferenceError");
1673
+ // Use the existing functionality. This makes sure the indentation and
1674
+ // line breaks are always correct. Otherwise it is very difficult to keep
1675
+ // this aligned, even though this is a hacky way of dealing with this.
1676
+ const tmp = { [keys[i]]: "" };
1677
+ output[i] = formatProperty(ctx, tmp, recurseTimes, keys[i], kObjectType);
1678
+ const pos = output[i].lastIndexOf(" ");
1679
+ // We have to find the last whitespace and have to replace that value as
1680
+ // it will be visualized as a regular string.
1681
+ output[i] =
1682
+ output[i].slice(0, pos + 1) +
1683
+ ctx.stylize("<uninitialized>", "special");
1684
+ }
1685
+ }
1686
+ // Reset the keys to an empty array. This prevents duplicated inspection.
1687
+ keys.length = 0;
1688
+ return output;
1689
+ }
1690
+ // The array is sparse and/or has extra keys
1691
+ function formatSpecialArray(ctx, value, recurseTimes, maxLength, output, i) {
1692
+ const keys = Object.keys(value);
1693
+ let index = i;
1694
+ for (; i < keys.length && output.length < maxLength; i++) {
1695
+ const key = keys[i];
1696
+ const tmp = +key;
1697
+ // Arrays can only have up to 2^32 - 1 entries
1698
+ if (tmp > 2 ** 32 - 2) {
1699
+ break;
1700
+ }
1701
+ if (`${index}` !== key) {
1702
+ if (numberRegExp.exec(key) === null) {
1703
+ break;
1704
+ }
1705
+ const emptyItems = tmp - index;
1706
+ const ending = emptyItems > 1 ? "s" : "";
1707
+ const message = `<${emptyItems} empty item${ending}>`;
1708
+ output.push(ctx.stylize(message, "undefined"));
1709
+ index = tmp;
1710
+ if (output.length === maxLength) {
1711
+ break;
1712
+ }
1713
+ }
1714
+ output.push(formatProperty(ctx, value, recurseTimes, key, kArrayType));
1715
+ index++;
1716
+ }
1717
+ const remaining = value.length - index;
1718
+ if (output.length !== maxLength) {
1719
+ if (remaining > 0) {
1720
+ const ending = remaining > 1 ? "s" : "";
1721
+ const message = `<${remaining} empty item${ending}>`;
1722
+ output.push(ctx.stylize(message, "undefined"));
1723
+ }
1724
+ }
1725
+ else if (remaining > 0) {
1726
+ output.push(remainingText(remaining));
1727
+ }
1728
+ return output;
1729
+ }
1730
+ function formatArrayBuffer(ctx, value) {
1731
+ let buffer;
1732
+ try {
1733
+ buffer = new Uint8Array(value);
1734
+ }
1735
+ catch {
1736
+ return [ctx.stylize("(detached)", "special")];
1737
+ }
1738
+ const maxArrayLength = ctx.maxArrayLength;
1739
+ let str = Buffer.prototype.hexSlice
1740
+ .call(buffer, 0, Math.min(maxArrayLength, buffer.length))
1741
+ .replace(/(.{2})/g, "$1 ")
1742
+ .trim();
1743
+ const remaining = buffer.length - maxArrayLength;
1744
+ if (remaining > 0)
1745
+ str += ` ... ${remaining} more byte${remaining > 1 ? "s" : ""}`;
1746
+ return [`${ctx.stylize("[Uint8Contents]", "special")}: <${str}>`];
1747
+ }
1748
+ function formatArray(ctx, value, recurseTimes) {
1749
+ const valLen = value.length;
1750
+ const len = Math.min(Math.max(0, ctx.maxArrayLength), valLen);
1751
+ const remaining = valLen - len;
1752
+ const output = [];
1753
+ for (let i = 0; i < len; i++) {
1754
+ // Special handle sparse arrays.
1755
+ if (!Object.prototype.hasOwnProperty.call(value, i)) {
1756
+ return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
1757
+ }
1758
+ output.push(formatProperty(ctx, value, recurseTimes, i, kArrayType));
1759
+ }
1760
+ if (remaining > 0) {
1761
+ output.push(remainingText(remaining));
1762
+ }
1763
+ return output;
1764
+ }
1765
+ function formatTypedArray(value, length, ctx, _ignored, recurseTimes) {
1766
+ const maxLength = Math.min(Math.max(0, ctx.maxArrayLength), length);
1767
+ const remaining = value.length - maxLength;
1768
+ const output = new Array(maxLength);
1769
+ const elementFormatter = value.length > 0 && typeof value[0] === "number"
1770
+ ? formatNumber
1771
+ : formatBigInt;
1772
+ for (let i = 0; i < maxLength; ++i) {
1773
+ // @ts-expect-error `value[i]` assumed to be of correct numeric type
1774
+ output[i] = elementFormatter(ctx.stylize, value[i], ctx.numericSeparator);
1775
+ }
1776
+ if (remaining > 0) {
1777
+ output[maxLength] = remainingText(remaining);
1778
+ }
1779
+ if (ctx.showHidden) {
1780
+ // .buffer goes last, it's not a primitive like the others.
1781
+ // All besides `BYTES_PER_ELEMENT` are actually getters.
1782
+ ctx.indentationLvl += 2;
1783
+ for (const key of [
1784
+ "BYTES_PER_ELEMENT",
1785
+ "length",
1786
+ "byteLength",
1787
+ "byteOffset",
1788
+ "buffer",
1789
+ ]) {
1790
+ const str = formatValue(ctx, value[key], recurseTimes, true);
1791
+ output.push(`[${key}]: ${str}`);
1792
+ }
1793
+ ctx.indentationLvl -= 2;
1794
+ }
1795
+ return output;
1796
+ }
1797
+ function formatSet(value, ctx, _ignored, recurseTimes) {
1798
+ const length = isSet(value) ? value.size : NaN;
1799
+ const maxLength = Math.min(Math.max(0, ctx.maxArrayLength), length);
1800
+ const remaining = length - maxLength;
1801
+ const output = [];
1802
+ ctx.indentationLvl += 2;
1803
+ let i = 0;
1804
+ for (const v of value) {
1805
+ if (i >= maxLength)
1806
+ break;
1807
+ output.push(formatValue(ctx, v, recurseTimes));
1808
+ i++;
1809
+ }
1810
+ if (remaining > 0) {
1811
+ output.push(remainingText(remaining));
1812
+ }
1813
+ ctx.indentationLvl -= 2;
1814
+ return output;
1815
+ }
1816
+ function formatMap(value, ctx, _ignored, recurseTimes) {
1817
+ const length = isMap(value) ? value.size : NaN;
1818
+ const maxLength = Math.min(Math.max(0, ctx.maxArrayLength), length);
1819
+ const remaining = length - maxLength;
1820
+ const output = [];
1821
+ ctx.indentationLvl += 2;
1822
+ let i = 0;
1823
+ for (const { 0: k, 1: v } of value) {
1824
+ if (i >= maxLength)
1825
+ break;
1826
+ output.push(`${formatValue(ctx, k, recurseTimes)} => ${formatValue(ctx, v, recurseTimes)}`);
1827
+ i++;
1828
+ }
1829
+ if (remaining > 0) {
1830
+ output.push(remainingText(remaining));
1831
+ }
1832
+ ctx.indentationLvl -= 2;
1833
+ return output;
1834
+ }
1835
+ function formatSetIterInner(ctx, recurseTimes, entries, state) {
1836
+ const maxArrayLength = Math.max(ctx.maxArrayLength, 0);
1837
+ const maxLength = Math.min(maxArrayLength, entries.length);
1838
+ const output = new Array(maxLength);
1839
+ ctx.indentationLvl += 2;
1840
+ for (let i = 0; i < maxLength; i++) {
1841
+ output[i] = formatValue(ctx, entries[i], recurseTimes);
1842
+ }
1843
+ ctx.indentationLvl -= 2;
1844
+ if (state === kWeak && !ctx.sorted) {
1845
+ // Sort all entries to have a halfway reliable output (if more entries than
1846
+ // retrieved ones exist, we can not reliably return the same output) if the
1847
+ // output is not sorted anyway.
1848
+ output.sort();
1849
+ }
1850
+ const remaining = entries.length - maxLength;
1851
+ if (remaining > 0) {
1852
+ output.push(remainingText(remaining));
1853
+ }
1854
+ return output;
1855
+ }
1856
+ function formatMapIterInner(ctx, recurseTimes, entries, state) {
1857
+ const maxArrayLength = Math.max(ctx.maxArrayLength, 0);
1858
+ // Entries exist as [key1, val1, key2, val2, ...]
1859
+ const len = entries.length / 2;
1860
+ const remaining = len - maxArrayLength;
1861
+ const maxLength = Math.min(maxArrayLength, len);
1862
+ const output = new Array(maxLength);
1863
+ let i = 0;
1864
+ ctx.indentationLvl += 2;
1865
+ if (state === kWeak) {
1866
+ for (; i < maxLength; i++) {
1867
+ const pos = i * 2;
1868
+ output[i] =
1869
+ `${formatValue(ctx, entries[pos], recurseTimes)} => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
1870
+ }
1871
+ // Sort all entries to have a halfway reliable output (if more entries than
1872
+ // retrieved ones exist, we can not reliably return the same output) if the
1873
+ // output is not sorted anyway.
1874
+ if (!ctx.sorted)
1875
+ output.sort();
1876
+ }
1877
+ else {
1878
+ for (; i < maxLength; i++) {
1879
+ const pos = i * 2;
1880
+ const res = [
1881
+ formatValue(ctx, entries[pos], recurseTimes),
1882
+ formatValue(ctx, entries[pos + 1], recurseTimes),
1883
+ ];
1884
+ output[i] = reduceToSingleString(ctx, res, "", ["[", "]"], kArrayExtrasType, recurseTimes);
1885
+ }
1886
+ }
1887
+ ctx.indentationLvl -= 2;
1888
+ if (remaining > 0) {
1889
+ output.push(remainingText(remaining));
1890
+ }
1891
+ return output;
1892
+ }
1893
+ function formatWeakCollection(ctx) {
1894
+ return [ctx.stylize("<items unknown>", "special")];
1895
+ }
1896
+ function formatWeakSet(ctx, value, recurseTimes) {
1897
+ const { entries } = internal.previewEntries(value);
1898
+ return formatSetIterInner(ctx, recurseTimes, entries, kWeak);
1899
+ }
1900
+ function formatWeakMap(ctx, value, recurseTimes) {
1901
+ const { entries } = internal.previewEntries(value);
1902
+ return formatMapIterInner(ctx, recurseTimes, entries, kWeak);
1903
+ }
1904
+ function formatIterator(braces, ctx, value, recurseTimes) {
1905
+ const { entries, isKeyValue } = internal.previewEntries(value);
1906
+ if (isKeyValue) {
1907
+ // Mark entry iterators as such.
1908
+ braces[0] = braces[0].replace(/ Iterator] {$/, " Entries] {");
1909
+ return formatMapIterInner(ctx, recurseTimes, entries, kMapEntries);
1910
+ }
1911
+ return formatSetIterInner(ctx, recurseTimes, entries, kIterator);
1912
+ }
1913
+ function formatPromise(ctx, value, recurseTimes) {
1914
+ let output;
1915
+ const { state, result } = internal.getPromiseDetails(value);
1916
+ if (state === internal.kPending) {
1917
+ output = [ctx.stylize("<pending>", "special")];
1918
+ }
1919
+ else {
1920
+ ctx.indentationLvl += 2;
1921
+ const str = formatValue(ctx, result, recurseTimes);
1922
+ ctx.indentationLvl -= 2;
1923
+ output = [
1924
+ state === internal.kRejected
1925
+ ? `${ctx.stylize("<rejected>", "special")} ${str}`
1926
+ : str,
1927
+ ];
1928
+ }
1929
+ return output;
1930
+ }
1931
+ function formatProperty(ctx, value, recurseTimes, key, type, desc, original = value) {
1932
+ let name, str;
1933
+ let extra = " ";
1934
+ desc = desc ||
1935
+ Object.getOwnPropertyDescriptor(value, key) || {
1936
+ value: value[key],
1937
+ enumerable: true,
1938
+ };
1939
+ if (desc.value !== undefined) {
1940
+ const diff = ctx.compact !== true || type !== kObjectType ? 2 : 3;
1941
+ ctx.indentationLvl += diff;
1942
+ str = formatValue(ctx, desc.value, recurseTimes);
1943
+ if (diff === 3 && ctx.breakLength < getStringWidth(str, ctx.colors)) {
1944
+ extra = `\n${" ".repeat(ctx.indentationLvl)}`;
1945
+ }
1946
+ ctx.indentationLvl -= diff;
1947
+ }
1948
+ else if (desc.get !== undefined) {
1949
+ const label = desc.set !== undefined ? "Getter/Setter" : "Getter";
1950
+ const s = ctx.stylize;
1951
+ const sp = "special";
1952
+ if (ctx.getters &&
1953
+ (ctx.getters === true ||
1954
+ (ctx.getters === "get" && desc.set === undefined) ||
1955
+ (ctx.getters === "set" && desc.set !== undefined))) {
1956
+ try {
1957
+ const tmp = desc.get.call(original);
1958
+ ctx.indentationLvl += 2;
1959
+ if (tmp === null) {
1960
+ str = `${s(`[${label}:`, sp)} ${s("null", "null")}${s("]", sp)}`;
1961
+ }
1962
+ else if (typeof tmp === "object") {
1963
+ str = `${s(`[${label}]`, sp)} ${formatValue(ctx, tmp, recurseTimes)}`;
1964
+ }
1965
+ else {
1966
+ const primitive = formatPrimitive(s, tmp, ctx);
1967
+ str = `${s(`[${label}:`, sp)} ${primitive}${s("]", sp)}`;
1968
+ }
1969
+ ctx.indentationLvl -= 2;
1970
+ }
1971
+ catch (err) {
1972
+ const message = `<Inspection threw (${isError(err) ? err.message : String(err)})>`;
1973
+ str = `${s(`[${label}:`, sp)} ${message}${s("]", sp)}`;
1974
+ }
1975
+ }
1976
+ else {
1977
+ str = ctx.stylize(`[${label}]`, sp);
1978
+ }
1979
+ }
1980
+ else if (desc.set !== undefined) {
1981
+ str = ctx.stylize("[Setter]", "special");
1982
+ }
1983
+ else {
1984
+ str = ctx.stylize("undefined", "undefined");
1985
+ }
1986
+ if (type === kArrayType) {
1987
+ return str;
1988
+ }
1989
+ if (typeof key === "symbol") {
1990
+ const tmp = Symbol.prototype.toString
1991
+ .call(key)
1992
+ .replace(strEscapeSequencesReplacer, escapeFn);
1993
+ name = ctx.stylize(tmp, "symbol");
1994
+ }
1995
+ else if (keyStrRegExp.exec(key) !== null) {
1996
+ name =
1997
+ key === "__proto__"
1998
+ ? "['__proto__']"
1999
+ : ctx.stylize(key, "name");
2000
+ }
2001
+ else {
2002
+ name = ctx.stylize(strEscape(key), "string");
2003
+ }
2004
+ if (desc.enumerable === false) {
2005
+ name = `[${name}]`;
2006
+ }
2007
+ return `${name}:${extra}${str}`;
2008
+ }
2009
+ function isBelowBreakLength(ctx, output, start, base) {
2010
+ // Each entry is separated by at least a comma. Thus, we start with a total
2011
+ // length of at least `output.length`. In addition, some cases have a
2012
+ // whitespace in-between each other that is added to the total as well.
2013
+ // TODO(BridgeAR): Add Unicode support. Use the readline getStringWidth
2014
+ // function. Check the performance overhead and make it an opt-in in case it's
2015
+ // significant.
2016
+ let totalLength = output.length + start;
2017
+ if (totalLength + output.length > ctx.breakLength)
2018
+ return false;
2019
+ for (let i = 0; i < output.length; i++) {
2020
+ if (ctx.colors) {
2021
+ totalLength += removeColors(output[i]).length;
2022
+ }
2023
+ else {
2024
+ totalLength += output[i].length;
2025
+ }
2026
+ if (totalLength > ctx.breakLength) {
2027
+ return false;
2028
+ }
2029
+ }
2030
+ // Do not line up properties on the same line if `base` contains line breaks.
2031
+ return base === "" || !base.includes("\n");
2032
+ }
2033
+ function reduceToSingleString(ctx, output, base, braces, extrasType, recurseTimes, value) {
2034
+ if (ctx.compact !== true) {
2035
+ if (typeof ctx.compact === "number" && ctx.compact >= 1) {
2036
+ // Memorize the original output length. In case the output is grouped,
2037
+ // prevent lining up the entries on a single line.
2038
+ const entries = output.length;
2039
+ // Group array elements together if the array contains at least six
2040
+ // separate entries.
2041
+ if (extrasType === kArrayExtrasType && entries > 6) {
2042
+ output = groupArrayElements(ctx, output, value);
2043
+ }
2044
+ // `ctx.currentDepth` is set to the most inner depth of the currently
2045
+ // inspected object part while `recurseTimes` is the actual current depth
2046
+ // that is inspected.
2047
+ //
2048
+ // Example:
2049
+ //
2050
+ // const a = { first: [ 1, 2, 3 ], second: { inner: [ 1, 2, 3 ] } }
2051
+ //
2052
+ // The deepest depth of `a` is 2 (a.second.inner) and `a.first` has a max
2053
+ // depth of 1.
2054
+ //
2055
+ // Consolidate all entries of the local most inner depth up to
2056
+ // `ctx.compact`, as long as the properties are smaller than
2057
+ // `ctx.breakLength`.
2058
+ if (ctx.currentDepth - recurseTimes < ctx.compact &&
2059
+ entries === output.length) {
2060
+ // Line up all entries on a single line in case the entries do not
2061
+ // exceed `breakLength`. Add 10 as constant to start next to all other
2062
+ // factors that may reduce `breakLength`.
2063
+ const start = output.length +
2064
+ ctx.indentationLvl +
2065
+ braces[0].length +
2066
+ base.length +
2067
+ 10;
2068
+ if (isBelowBreakLength(ctx, output, start, base)) {
2069
+ const joinedOutput = output.join(", ");
2070
+ if (!joinedOutput.includes("\n")) {
2071
+ return (`${base ? `${base} ` : ""}${braces[0]} ${joinedOutput}` +
2072
+ ` ${braces[1]}`);
2073
+ }
2074
+ }
2075
+ }
2076
+ }
2077
+ // Line up each entry on an individual line.
2078
+ const indentation = `\n${" ".repeat(ctx.indentationLvl)}`;
2079
+ return (`${base ? `${base} ` : ""}${braces[0]}${indentation} ` +
2080
+ `${output.join(`,${indentation} `)}${indentation}${braces[1]}`);
2081
+ }
2082
+ // Line up all entries on a single line in case the entries do not exceed
2083
+ // `breakLength`.
2084
+ if (isBelowBreakLength(ctx, output, 0, base)) {
2085
+ return (`${braces[0]}${base ? ` ${base}` : ""} ${output.join(", ")} ` + braces[1]);
2086
+ }
2087
+ const indentation = " ".repeat(ctx.indentationLvl);
2088
+ // If the opening "brace" is too large, like in the case of "Set {",
2089
+ // we need to force the first item to be on the next line or the
2090
+ // items will not line up correctly.
2091
+ const ln = base === "" && braces[0].length === 1
2092
+ ? " "
2093
+ : `${base ? ` ${base}` : ""}\n${indentation} `;
2094
+ // Line up each entry on an individual line.
2095
+ return `${braces[0]}${ln}${output.join(`,\n${indentation} `)} ${braces[1]}`;
2096
+ }
2097
+ function hasBuiltInToString(value) {
2098
+ // Prevent triggering proxy traps.
2099
+ const proxyTarget = internal.getProxyDetails(value);
2100
+ if (proxyTarget !== undefined) {
2101
+ if (proxyTarget === null || proxyTarget.target === null) {
2102
+ return true;
2103
+ }
2104
+ return hasBuiltInToString(proxyTarget.target);
2105
+ }
2106
+ // Count objects that have no `toString` function as built-in.
2107
+ if (typeof value?.toString !== "function") {
2108
+ return true;
2109
+ }
2110
+ // The object has a own `toString` property. Thus it's not not a built-in one.
2111
+ if (Object.prototype.hasOwnProperty.call(value, "toString")) {
2112
+ return false;
2113
+ }
2114
+ // Find the object that has the `toString` property as own property in the
2115
+ // prototype chain.
2116
+ let pointer = value;
2117
+ do {
2118
+ pointer = Object.getPrototypeOf(pointer);
2119
+ } while (!Object.prototype.hasOwnProperty.call(pointer, "toString"));
2120
+ // Check closer if the object is a built-in.
2121
+ const descriptor = Object.getOwnPropertyDescriptor(pointer, "constructor");
2122
+ return (descriptor !== undefined &&
2123
+ typeof descriptor.value === "function" &&
2124
+ builtInObjects.has(descriptor.value.name));
2125
+ }
2126
+ const firstErrorLine = (error) => (isError(error) ? error.message : String(error)).split("\n", 1)[0];
2127
+ let CIRCULAR_ERROR_MESSAGE;
2128
+ function tryStringify(arg) {
2129
+ try {
2130
+ return JSON.stringify(arg);
2131
+ }
2132
+ catch (err) {
2133
+ // Populate the circular error message lazily
2134
+ if (!CIRCULAR_ERROR_MESSAGE) {
2135
+ try {
2136
+ const a = {};
2137
+ a.a = a;
2138
+ JSON.stringify(a);
2139
+ }
2140
+ catch (circularError) {
2141
+ CIRCULAR_ERROR_MESSAGE = firstErrorLine(circularError);
2142
+ }
2143
+ }
2144
+ if (typeof err === "object" &&
2145
+ err !== null &&
2146
+ "name" in err &&
2147
+ err.name === "TypeError" &&
2148
+ firstErrorLine(err) === CIRCULAR_ERROR_MESSAGE) {
2149
+ return "[Circular]";
2150
+ }
2151
+ throw err;
2152
+ }
2153
+ }
2154
+ export function format(...args) {
2155
+ return formatWithOptionsInternal(undefined, args);
2156
+ }
2157
+ export function formatWithOptions(inspectOptions, ...args) {
2158
+ validateObject(inspectOptions, "inspectOptions", kValidateObjectAllowArray);
2159
+ return formatWithOptionsInternal(inspectOptions, args);
2160
+ }
2161
+ function formatNumberNoColor(number, options) {
2162
+ return formatNumber(stylizeNoColor, number, options?.numericSeparator ?? inspectDefaultOptions.numericSeparator);
2163
+ }
2164
+ function formatBigIntNoColor(bigint, options) {
2165
+ return formatBigInt(stylizeNoColor, bigint, options?.numericSeparator ?? inspectDefaultOptions.numericSeparator);
2166
+ }
2167
+ function formatWithOptionsInternal(inspectOptions, args) {
2168
+ const first = args[0];
2169
+ let a = 0;
2170
+ let str = "";
2171
+ let join = "";
2172
+ if (typeof first === "string") {
2173
+ if (args.length === 1) {
2174
+ return first;
2175
+ }
2176
+ let tempStr;
2177
+ let lastPos = 0;
2178
+ for (let i = 0; i < first.length - 1; i++) {
2179
+ if (first.charCodeAt(i) === 37) {
2180
+ // '%'
2181
+ const nextChar = first.charCodeAt(++i);
2182
+ if (a + 1 !== args.length) {
2183
+ switch (nextChar) {
2184
+ case 115: {
2185
+ // 's'
2186
+ const tempArg = args[++a];
2187
+ if (typeof tempArg === "number") {
2188
+ tempStr = formatNumberNoColor(tempArg, inspectOptions);
2189
+ }
2190
+ else if (typeof tempArg === "bigint") {
2191
+ tempStr = formatBigIntNoColor(tempArg, inspectOptions);
2192
+ }
2193
+ else if (typeof tempArg !== "object" ||
2194
+ tempArg === null ||
2195
+ !hasBuiltInToString(tempArg)) {
2196
+ tempStr = String(tempArg);
2197
+ }
2198
+ else {
2199
+ tempStr = inspect(tempArg, {
2200
+ ...inspectOptions,
2201
+ compact: 3,
2202
+ colors: false,
2203
+ depth: 0,
2204
+ });
2205
+ }
2206
+ break;
2207
+ }
2208
+ case 106: // 'j'
2209
+ tempStr = tryStringify(args[++a]);
2210
+ break;
2211
+ case 100: {
2212
+ // 'd'
2213
+ const tempNum = args[++a];
2214
+ if (typeof tempNum === "bigint") {
2215
+ tempStr = formatBigIntNoColor(tempNum, inspectOptions);
2216
+ }
2217
+ else if (typeof tempNum === "symbol") {
2218
+ tempStr = "NaN";
2219
+ }
2220
+ else {
2221
+ tempStr = formatNumberNoColor(Number(tempNum), inspectOptions);
2222
+ }
2223
+ break;
2224
+ }
2225
+ case 79: // 'O'
2226
+ tempStr = inspect(args[++a], inspectOptions);
2227
+ break;
2228
+ case 111: // 'o'
2229
+ tempStr = inspect(args[++a], {
2230
+ ...inspectOptions,
2231
+ showHidden: true,
2232
+ showProxy: true,
2233
+ depth: 4,
2234
+ });
2235
+ break;
2236
+ case 105: {
2237
+ // 'i'
2238
+ const tempInteger = args[++a];
2239
+ if (typeof tempInteger === "bigint") {
2240
+ tempStr = formatBigIntNoColor(tempInteger, inspectOptions);
2241
+ }
2242
+ else if (typeof tempInteger === "symbol") {
2243
+ tempStr = "NaN";
2244
+ }
2245
+ else {
2246
+ tempStr = formatNumberNoColor(Number.parseInt(tempInteger), inspectOptions);
2247
+ }
2248
+ break;
2249
+ }
2250
+ case 102: {
2251
+ // 'f'
2252
+ const tempFloat = args[++a];
2253
+ if (typeof tempFloat === "symbol") {
2254
+ tempStr = "NaN";
2255
+ }
2256
+ else {
2257
+ tempStr = formatNumberNoColor(Number.parseFloat(tempFloat), inspectOptions);
2258
+ }
2259
+ break;
2260
+ }
2261
+ case 99: // 'c'
2262
+ a += 1;
2263
+ tempStr = "";
2264
+ break;
2265
+ case 37: // '%'
2266
+ str += first.slice(lastPos, i);
2267
+ lastPos = i + 1;
2268
+ continue;
2269
+ default: // Any other character is not a correct placeholder
2270
+ continue;
2271
+ }
2272
+ if (lastPos !== i - 1) {
2273
+ str += first.slice(lastPos, i - 1);
2274
+ }
2275
+ str += tempStr;
2276
+ lastPos = i + 1;
2277
+ }
2278
+ else if (nextChar === 37) {
2279
+ str += first.slice(lastPos, i);
2280
+ lastPos = i + 1;
2281
+ }
2282
+ }
2283
+ }
2284
+ if (lastPos !== 0) {
2285
+ a++;
2286
+ join = " ";
2287
+ if (lastPos < first.length) {
2288
+ str += first.slice(lastPos);
2289
+ }
2290
+ }
2291
+ }
2292
+ while (a < args.length) {
2293
+ const value = args[a];
2294
+ str += join;
2295
+ str += typeof value !== "string" ? inspect(value, inspectOptions) : value;
2296
+ join = " ";
2297
+ a++;
2298
+ }
2299
+ return str;
2300
+ }
2301
+ export function isZeroWidthCodePoint(code) {
2302
+ return (code <= 0x1f || // C0 control codes
2303
+ (code >= 0x7f && code <= 0x9f) || // C1 control codes
2304
+ (code >= 0x300 && code <= 0x36f) || // Combining Diacritical Marks
2305
+ (code >= 0x200b && code <= 0x200f) || // Modifying Invisible Characters
2306
+ // Combining Diacritical Marks for Symbols
2307
+ (code >= 0x20d0 && code <= 0x20ff) ||
2308
+ (code >= 0xfe00 && code <= 0xfe0f) || // Variation Selectors
2309
+ (code >= 0xfe20 && code <= 0xfe2f) || // Combining Half Marks
2310
+ (code >= 0xe0100 && code <= 0xe01ef)); // Variation Selectors
2311
+ }
2312
+ /**
2313
+ * Returns the number of columns required to display the given string.
2314
+ */
2315
+ export function getStringWidth(str, removeControlChars = true) {
2316
+ let width = 0;
2317
+ if (removeControlChars)
2318
+ str = stripVTControlCharacters(str);
2319
+ str = str.normalize("NFC");
2320
+ for (const char of str) {
2321
+ const code = char.codePointAt(0);
2322
+ if (isFullWidthCodePoint(code)) {
2323
+ width += 2;
2324
+ }
2325
+ else if (!isZeroWidthCodePoint(code)) {
2326
+ width++;
2327
+ }
2328
+ }
2329
+ return width;
2330
+ }
2331
+ /**
2332
+ * Returns true if the character represented by a given
2333
+ * Unicode code point is full-width. Otherwise returns false.
2334
+ */
2335
+ const isFullWidthCodePoint = (code) => {
2336
+ // Code points are partially derived from:
2337
+ // https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt
2338
+ return (code >= 0x1100 &&
2339
+ (code <= 0x115f || // Hangul Jamo
2340
+ code === 0x2329 || // LEFT-POINTING ANGLE BRACKET
2341
+ code === 0x232a || // RIGHT-POINTING ANGLE BRACKET
2342
+ // CJK Radicals Supplement .. Enclosed CJK Letters and Months
2343
+ (code >= 0x2e80 && code <= 0x3247 && code !== 0x303f) ||
2344
+ // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
2345
+ (code >= 0x3250 && code <= 0x4dbf) ||
2346
+ // CJK Unified Ideographs .. Yi Radicals
2347
+ (code >= 0x4e00 && code <= 0xa4c6) ||
2348
+ // Hangul Jamo Extended-A
2349
+ (code >= 0xa960 && code <= 0xa97c) ||
2350
+ // Hangul Syllables
2351
+ (code >= 0xac00 && code <= 0xd7a3) ||
2352
+ // CJK Compatibility Ideographs
2353
+ (code >= 0xf900 && code <= 0xfaff) ||
2354
+ // Vertical Forms
2355
+ (code >= 0xfe10 && code <= 0xfe19) ||
2356
+ // CJK Compatibility Forms .. Small Form Variants
2357
+ (code >= 0xfe30 && code <= 0xfe6b) ||
2358
+ // Halfwidth and Fullwidth Forms
2359
+ (code >= 0xff01 && code <= 0xff60) ||
2360
+ (code >= 0xffe0 && code <= 0xffe6) ||
2361
+ // Kana Supplement
2362
+ (code >= 0x1b000 && code <= 0x1b001) ||
2363
+ // Enclosed Ideographic Supplement
2364
+ (code >= 0x1f200 && code <= 0x1f251) ||
2365
+ // Miscellaneous Symbols and Pictographs 0x1f300 - 0x1f5ff
2366
+ // Emoticons 0x1f600 - 0x1f64f
2367
+ (code >= 0x1f300 && code <= 0x1f64f) ||
2368
+ // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
2369
+ (code >= 0x20000 && code <= 0x3fffd)));
2370
+ };
2371
+ /**
2372
+ * Remove all VT control characters. Use to estimate displayed string width.
2373
+ */
2374
+ export function stripVTControlCharacters(str) {
2375
+ validateString(str, "str");
2376
+ return str.replace(ansi, "");
2377
+ }
2378
+ // ================================================================================================
2379
+ // WORKERD SPECIFIC CODE
2380
+ // Called from C++ on `console.log()`s to format values
2381
+ export function formatLog(...args) {
2382
+ const level = args.pop();
2383
+ const structuredLogging = args.pop();
2384
+ const colors = args.pop();
2385
+ const inspectOptions = { colors };
2386
+ try {
2387
+ const message = formatWithOptions(inspectOptions, ...args);
2388
+ if (structuredLogging) {
2389
+ return JSON.stringify({
2390
+ timestamp: Date.now(),
2391
+ level,
2392
+ message,
2393
+ });
2394
+ }
2395
+ else {
2396
+ return message;
2397
+ }
2398
+ }
2399
+ catch (err) {
2400
+ return `<Formatting threw (${isError(err) ? err.stack : String(err)})>`;
2401
+ }
2402
+ }
2403
+ function isBuiltinPrototype(proto) {
2404
+ if (proto === null)
2405
+ return true;
2406
+ // JSG resource type prototypes carry the kResourceTypeInspect symbol.
2407
+ // These are not "built-in" in the JS-engine sense even though their
2408
+ // constructors are own properties of globalThis (per Web IDL). The
2409
+ // prototype walk must continue through them to collect accessor
2410
+ // properties (e.g. Blob.prototype.size).
2411
+ if (typeof proto === "object" &&
2412
+ proto !== null &&
2413
+ internal.kResourceTypeInspect in proto) {
2414
+ return false;
2415
+ }
2416
+ const descriptor = Object.getOwnPropertyDescriptor(proto, "constructor");
2417
+ return (descriptor !== undefined &&
2418
+ typeof descriptor.value === "function" &&
2419
+ builtInObjects.has(descriptor.value.name));
2420
+ }
2421
+ // Native Workers RPC references cannot be constructed in this Web runtime.
2422
+ function isRpcWildcardType(_value) {
2423
+ return false;
2424
+ }
2425
+ function isEntry(value) {
2426
+ return Array.isArray(value) && value.length === 2;
2427
+ }
2428
+ function maybeGetEntries(value) {
2429
+ // If this value is an RPC type with a wildcard property handler (e.g. `RpcStub`), don't try to
2430
+ // call `entries()` on it. This won't be an `entries()` function, and calling it with `.call()`
2431
+ // would dispose the stub.
2432
+ if (isRpcWildcardType(value))
2433
+ return;
2434
+ const entriesFunction = value["entries"];
2435
+ if (typeof entriesFunction !== "function")
2436
+ return;
2437
+ const entriesIterator = entriesFunction.call(value);
2438
+ if (typeof entriesIterator !== "object" || entriesIterator === null)
2439
+ return;
2440
+ if (!(Symbol.iterator in entriesIterator))
2441
+ return;
2442
+ const entries = Array.from(entriesIterator);
2443
+ if (!entries.every(isEntry))
2444
+ return;
2445
+ return entries;
2446
+ }
2447
+ const kEntries = Symbol("kEntries");
2448
+ function hasEntries(value) {
2449
+ return typeof value === "object" && value !== null && kEntries in value;
2450
+ }
2451
+ // Default custom inspect implementation for JSG resource types
2452
+ function formatJsgResourceType(additionalProperties, depth, options) {
2453
+ const name = this.constructor.name;
2454
+ if (depth < 0)
2455
+ return options.stylize(`[${name}]`, "special");
2456
+ // Build a plain object for inspection. If this value has an `entries()` function, add those
2457
+ // entries for map-like `K => V` formatting. Note we can't use a `Map` here as a key may have
2458
+ // multiple values (e.g. URLSearchParams).
2459
+ const record = {};
2460
+ const maybeEntries = maybeGetEntries(this);
2461
+ if (maybeEntries !== undefined)
2462
+ record[kEntries] = maybeEntries;
2463
+ // Add all instance and prototype non-function-valued properties
2464
+ let current = this;
2465
+ do {
2466
+ // `Object.getOwnPropertyDescriptor()` throws `Illegal Invocation` for our prototypes here.
2467
+ for (const key of Object.getOwnPropertyNames(current)) {
2468
+ // If this property is unimplemented, don't try to log it
2469
+ if (additionalProperties[key] === false)
2470
+ continue;
2471
+ const value = this[key];
2472
+ // Ignore function-valued and static properties
2473
+ if (typeof value === "function" ||
2474
+ this.constructor.propertyIsEnumerable(key))
2475
+ continue;
2476
+ record[key] = value;
2477
+ }
2478
+ } while (!isBuiltinPrototype((current = Object.getPrototypeOf(current))));
2479
+ // Add additional inspect-only properties as non-enumerable so they appear in square brackets
2480
+ for (const [key, symbol] of Object.entries(additionalProperties)) {
2481
+ // This is an additional property if it's not an unimplemented marker
2482
+ if (symbol !== false) {
2483
+ Object.defineProperty(record, key, {
2484
+ value: this[symbol],
2485
+ enumerable: false,
2486
+ });
2487
+ }
2488
+ }
2489
+ // Format the plain object
2490
+ const inspected = inspect(record, {
2491
+ ...options,
2492
+ depth: options.depth == null ? null : depth,
2493
+ showHidden: true, // Show non-enumerable inspect-only properties
2494
+ });
2495
+ if (maybeEntries === undefined) {
2496
+ return `${name} ${inspected}`;
2497
+ }
2498
+ else {
2499
+ // Inspecting a entries object gives something like `Object(1) { 'a' => '1' }`, whereas we want
2500
+ // something like `Headers(1) { 'a' => '1' }`.
2501
+ return `${name}${inspected.replace("Object", "")}`;
2502
+ }
2503
+ }