@blazetrails/ruby-compat 0.0.0-stage → 0.1.0-alpha0.1

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 (622) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +6 -0
  3. package/README.md +440 -2
  4. package/dist/argument-error.d.ts +15 -0
  5. package/dist/argument-error.js +15 -0
  6. package/dist/argument-error.js.map +1 -0
  7. package/dist/array.d.ts +415 -0
  8. package/dist/array.js +1330 -0
  9. package/dist/array.js.map +1 -0
  10. package/dist/async-context-adapter.d.ts +19 -0
  11. package/dist/async-context-adapter.js +139 -0
  12. package/dist/async-context-adapter.js.map +1 -0
  13. package/dist/backtrace-location.d.ts +77 -0
  14. package/dist/backtrace-location.js +155 -0
  15. package/dist/backtrace-location.js.map +1 -0
  16. package/dist/base64.d.ts +73 -0
  17. package/dist/base64.js +164 -0
  18. package/dist/base64.js.map +1 -0
  19. package/dist/benchmark.d.ts +19 -0
  20. package/dist/benchmark.js +16 -0
  21. package/dist/benchmark.js.map +1 -0
  22. package/dist/big-decimal.d.ts +110 -0
  23. package/dist/big-decimal.js +582 -0
  24. package/dist/big-decimal.js.map +1 -0
  25. package/dist/bundler.d.ts +44 -0
  26. package/dist/bundler.js +101 -0
  27. package/dist/bundler.js.map +1 -0
  28. package/dist/cgi.d.ts +89 -0
  29. package/dist/cgi.js +168 -0
  30. package/dist/cgi.js.map +1 -0
  31. package/dist/child-process-adapter.d.ts +110 -0
  32. package/dist/child-process-adapter.js +272 -0
  33. package/dist/child-process-adapter.js.map +1 -0
  34. package/dist/class-module.d.ts +10 -0
  35. package/dist/class-module.js +10 -0
  36. package/dist/class-module.js.map +1 -0
  37. package/dist/classpath.d.ts +90 -0
  38. package/dist/classpath.js +207 -0
  39. package/dist/classpath.js.map +1 -0
  40. package/dist/closed-queue-error.d.ts +10 -0
  41. package/dist/closed-queue-error.js +10 -0
  42. package/dist/closed-queue-error.js.map +1 -0
  43. package/dist/comparable.d.ts +127 -0
  44. package/dist/comparable.js +376 -0
  45. package/dist/comparable.js.map +1 -0
  46. package/dist/complex.d.ts +48 -0
  47. package/dist/complex.js +162 -0
  48. package/dist/complex.js.map +1 -0
  49. package/dist/concurrent/atomic-boolean.d.ts +24 -0
  50. package/dist/concurrent/atomic-boolean.js +43 -0
  51. package/dist/concurrent/atomic-boolean.js.map +1 -0
  52. package/dist/concurrent/atomic-fixnum.d.ts +21 -0
  53. package/dist/concurrent/atomic-fixnum.js +35 -0
  54. package/dist/concurrent/atomic-fixnum.js.map +1 -0
  55. package/dist/concurrent/count-down-latch.d.ts +20 -0
  56. package/dist/concurrent/count-down-latch.js +50 -0
  57. package/dist/concurrent/count-down-latch.js.map +1 -0
  58. package/dist/concurrent/cyclic-barrier.d.ts +18 -0
  59. package/dist/concurrent/cyclic-barrier.js +50 -0
  60. package/dist/concurrent/cyclic-barrier.js.map +1 -0
  61. package/dist/concurrent/event.d.ts +19 -0
  62. package/dist/concurrent/event.js +31 -0
  63. package/dist/concurrent/event.js.map +1 -0
  64. package/dist/concurrent/map.d.ts +149 -0
  65. package/dist/concurrent/map.js +202 -0
  66. package/dist/concurrent/map.js.map +1 -0
  67. package/dist/concurrent/read-write-lock.d.ts +25 -0
  68. package/dist/concurrent/read-write-lock.js +70 -0
  69. package/dist/concurrent/read-write-lock.js.map +1 -0
  70. package/dist/concurrent/semaphore.d.ts +24 -0
  71. package/dist/concurrent/semaphore.js +74 -0
  72. package/dist/concurrent/semaphore.js.map +1 -0
  73. package/dist/concurrent/timer-task.d.ts +52 -0
  74. package/dist/concurrent/timer-task.js +112 -0
  75. package/dist/concurrent/timer-task.js.map +1 -0
  76. package/dist/constants.generated.d.ts +2 -0
  77. package/dist/constants.generated.js +64 -0
  78. package/dist/constants.generated.js.map +1 -0
  79. package/dist/converter-not-found-error.d.ts +14 -0
  80. package/dist/converter-not-found-error.js +14 -0
  81. package/dist/converter-not-found-error.js.map +1 -0
  82. package/dist/crypto-adapter.d.ts +64 -0
  83. package/dist/crypto-adapter.js +365 -0
  84. package/dist/crypto-adapter.js.map +1 -0
  85. package/dist/delegate.d.ts +156 -0
  86. package/dist/delegate.js +306 -0
  87. package/dist/delegate.js.map +1 -0
  88. package/dist/digest.d.ts +99 -0
  89. package/dist/digest.js +131 -0
  90. package/dist/digest.js.map +1 -0
  91. package/dist/dir.d.ts +218 -0
  92. package/dist/dir.js +599 -0
  93. package/dist/dir.js.map +1 -0
  94. package/dist/encoding-error.d.ts +14 -0
  95. package/dist/encoding-error.js +17 -0
  96. package/dist/encoding-error.js.map +1 -0
  97. package/dist/encoding.d.ts +121 -0
  98. package/dist/encoding.js +306 -0
  99. package/dist/encoding.js.map +1 -0
  100. package/dist/ensure.d.ts +15 -0
  101. package/dist/ensure.js +35 -0
  102. package/dist/ensure.js.map +1 -0
  103. package/dist/enumerable.d.ts +375 -0
  104. package/dist/enumerable.js +1100 -0
  105. package/dist/enumerable.js.map +1 -0
  106. package/dist/enumerator.d.ts +321 -0
  107. package/dist/enumerator.js +642 -0
  108. package/dist/enumerator.js.map +1 -0
  109. package/dist/eof-error.d.ts +14 -0
  110. package/dist/eof-error.js +14 -0
  111. package/dist/eof-error.js.map +1 -0
  112. package/dist/errno.d.ts +327 -0
  113. package/dist/errno.js +452 -0
  114. package/dist/errno.js.map +1 -0
  115. package/dist/exc-detailed-message.d.ts +15 -0
  116. package/dist/exc-detailed-message.js +106 -0
  117. package/dist/exc-detailed-message.js.map +1 -0
  118. package/dist/exc-to-s.d.ts +10 -0
  119. package/dist/exc-to-s.js +21 -0
  120. package/dist/exc-to-s.js.map +1 -0
  121. package/dist/exception.d.ts +34 -0
  122. package/dist/exception.js +99 -0
  123. package/dist/exception.js.map +1 -0
  124. package/dist/fiber-error.d.ts +12 -0
  125. package/dist/fiber-error.js +12 -0
  126. package/dist/fiber-error.js.map +1 -0
  127. package/dist/fiber.d.ts +51 -0
  128. package/dist/fiber.js +178 -0
  129. package/dist/fiber.js.map +1 -0
  130. package/dist/file-utils.d.ts +480 -0
  131. package/dist/file-utils.js +1823 -0
  132. package/dist/file-utils.js.map +1 -0
  133. package/dist/file.d.ts +635 -0
  134. package/dist/file.js +1312 -0
  135. package/dist/file.js.map +1 -0
  136. package/dist/float-domain-error.d.ts +17 -0
  137. package/dist/float-domain-error.js +17 -0
  138. package/dist/float-domain-error.js.map +1 -0
  139. package/dist/fork-children.d.ts +23 -0
  140. package/dist/fork-children.js +32 -0
  141. package/dist/fork-children.js.map +1 -0
  142. package/dist/frozen-error.d.ts +33 -0
  143. package/dist/frozen-error.js +42 -0
  144. package/dist/frozen-error.js.map +1 -0
  145. package/dist/fs-adapter.d.ts +158 -0
  146. package/dist/fs-adapter.js +253 -0
  147. package/dist/fs-adapter.js.map +1 -0
  148. package/dist/gem/deprecate.d.ts +10 -0
  149. package/dist/gem/deprecate.js +8 -0
  150. package/dist/gem/deprecate.js.map +1 -0
  151. package/dist/gem/requirement.d.ts +64 -0
  152. package/dist/gem/requirement.js +91 -0
  153. package/dist/gem/requirement.js.map +1 -0
  154. package/dist/gem/version.d.ts +50 -0
  155. package/dist/gem/version.js +148 -0
  156. package/dist/gem/version.js.map +1 -0
  157. package/dist/gem.d.ts +59 -0
  158. package/dist/gem.js +82 -0
  159. package/dist/gem.js.map +1 -0
  160. package/dist/hash.d.ts +967 -0
  161. package/dist/hash.js +1572 -0
  162. package/dist/hash.js.map +1 -0
  163. package/dist/http-adapter.d.ts +123 -0
  164. package/dist/http-adapter.js +220 -0
  165. package/dist/http-adapter.js.map +1 -0
  166. package/dist/immediate-executor.d.ts +20 -0
  167. package/dist/immediate-executor.js +39 -0
  168. package/dist/immediate-executor.js.map +1 -0
  169. package/dist/include.d.ts +778 -0
  170. package/dist/include.js +2195 -0
  171. package/dist/include.js.map +1 -0
  172. package/dist/index-error.d.ts +13 -0
  173. package/dist/index-error.js +13 -0
  174. package/dist/index-error.js.map +1 -0
  175. package/dist/index.d.ts +174 -0
  176. package/dist/index.js +166 -0
  177. package/dist/index.js.map +1 -0
  178. package/dist/invalid-byte-sequence-error.d.ts +62 -0
  179. package/dist/invalid-byte-sequence-error.js +75 -0
  180. package/dist/invalid-byte-sequence-error.js.map +1 -0
  181. package/dist/io-error.d.ts +14 -0
  182. package/dist/io-error.js +17 -0
  183. package/dist/io-error.js.map +1 -0
  184. package/dist/io.d.ts +867 -0
  185. package/dist/io.js +1960 -0
  186. package/dist/io.js.map +1 -0
  187. package/dist/ipaddr.d.ts +79 -0
  188. package/dist/ipaddr.js +405 -0
  189. package/dist/ipaddr.js.map +1 -0
  190. package/dist/json.d.ts +67 -0
  191. package/dist/json.js +185 -0
  192. package/dist/json.js.map +1 -0
  193. package/dist/kernel-catch.d.ts +59 -0
  194. package/dist/kernel-catch.js +184 -0
  195. package/dist/kernel-catch.js.map +1 -0
  196. package/dist/kernel-float.d.ts +19 -0
  197. package/dist/kernel-float.js +54 -0
  198. package/dist/kernel-float.js.map +1 -0
  199. package/dist/kernel-fork.d.ts +30 -0
  200. package/dist/kernel-fork.js +72 -0
  201. package/dist/kernel-fork.js.map +1 -0
  202. package/dist/kernel-format.d.ts +27 -0
  203. package/dist/kernel-format.js +901 -0
  204. package/dist/kernel-format.js.map +1 -0
  205. package/dist/kernel-hash.d.ts +7 -0
  206. package/dist/kernel-hash.js +33 -0
  207. package/dist/kernel-hash.js.map +1 -0
  208. package/dist/kernel-integer.d.ts +49 -0
  209. package/dist/kernel-integer.js +170 -0
  210. package/dist/kernel-integer.js.map +1 -0
  211. package/dist/kernel-rand.d.ts +16 -0
  212. package/dist/kernel-rand.js +237 -0
  213. package/dist/kernel-rand.js.map +1 -0
  214. package/dist/kernel-system.d.ts +40 -0
  215. package/dist/kernel-system.js +97 -0
  216. package/dist/kernel-system.js.map +1 -0
  217. package/dist/kernel-warn.d.ts +35 -0
  218. package/dist/kernel-warn.js +73 -0
  219. package/dist/kernel-warn.js.map +1 -0
  220. package/dist/key-error.d.ts +44 -0
  221. package/dist/key-error.js +59 -0
  222. package/dist/key-error.js.map +1 -0
  223. package/dist/keyword-splat.d.ts +41 -0
  224. package/dist/keyword-splat.js +65 -0
  225. package/dist/keyword-splat.js.map +1 -0
  226. package/dist/load-error.d.ts +19 -0
  227. package/dist/load-error.js +19 -0
  228. package/dist/load-error.js.map +1 -0
  229. package/dist/load.d.ts +121 -0
  230. package/dist/load.js +263 -0
  231. package/dist/load.js.map +1 -0
  232. package/dist/loaded-features.d.ts +13 -0
  233. package/dist/loaded-features.js +15 -0
  234. package/dist/loaded-features.js.map +1 -0
  235. package/dist/local-jump-error.d.ts +12 -0
  236. package/dist/local-jump-error.js +12 -0
  237. package/dist/local-jump-error.js.map +1 -0
  238. package/dist/logger/formatter.d.ts +21 -0
  239. package/dist/logger/formatter.js +43 -0
  240. package/dist/logger/formatter.js.map +1 -0
  241. package/dist/logger/log-device.d.ts +52 -0
  242. package/dist/logger/log-device.js +104 -0
  243. package/dist/logger/log-device.js.map +1 -0
  244. package/dist/logger/severity.d.ts +23 -0
  245. package/dist/logger/severity.js +42 -0
  246. package/dist/logger/severity.js.map +1 -0
  247. package/dist/logger.d.ts +127 -0
  248. package/dist/logger.js +215 -0
  249. package/dist/logger.js.map +1 -0
  250. package/dist/marshal.d.ts +83 -0
  251. package/dist/marshal.js +1487 -0
  252. package/dist/marshal.js.map +1 -0
  253. package/dist/match-data.d.ts +161 -0
  254. package/dist/match-data.js +284 -0
  255. package/dist/match-data.js.map +1 -0
  256. package/dist/method-cache.d.ts +17 -0
  257. package/dist/method-cache.js +19 -0
  258. package/dist/method-cache.js.map +1 -0
  259. package/dist/method-missing-proxy.d.ts +53 -0
  260. package/dist/method-missing-proxy.js +154 -0
  261. package/dist/method-missing-proxy.js.map +1 -0
  262. package/dist/method.d.ts +132 -0
  263. package/dist/method.js +320 -0
  264. package/dist/method.js.map +1 -0
  265. package/dist/monitor.d.ts +114 -0
  266. package/dist/monitor.js +270 -0
  267. package/dist/monitor.js.map +1 -0
  268. package/dist/mutex.d.ts +51 -0
  269. package/dist/mutex.js +150 -0
  270. package/dist/mutex.js.map +1 -0
  271. package/dist/name-error.d.ts +45 -0
  272. package/dist/name-error.js +54 -0
  273. package/dist/name-error.js.map +1 -0
  274. package/dist/net/http/exceptions.d.ts +31 -0
  275. package/dist/net/http/exceptions.js +46 -0
  276. package/dist/net/http/exceptions.js.map +1 -0
  277. package/dist/net/http/request.d.ts +137 -0
  278. package/dist/net/http/request.js +559 -0
  279. package/dist/net/http/request.js.map +1 -0
  280. package/dist/net/http/requests.d.ts +197 -0
  281. package/dist/net/http/requests.js +197 -0
  282. package/dist/net/http/requests.js.map +1 -0
  283. package/dist/net/http/response.d.ts +141 -0
  284. package/dist/net/http/response.js +416 -0
  285. package/dist/net/http/response.js.map +1 -0
  286. package/dist/net/http/responses.d.ts +345 -0
  287. package/dist/net/http/responses.js +486 -0
  288. package/dist/net/http/responses.js.map +1 -0
  289. package/dist/net/http.d.ts +278 -0
  290. package/dist/net/http.js +760 -0
  291. package/dist/net/http.js.map +1 -0
  292. package/dist/net/protocol.d.ts +227 -0
  293. package/dist/net/protocol.js +392 -0
  294. package/dist/net/protocol.js.map +1 -0
  295. package/dist/nil-class.d.ts +10 -0
  296. package/dist/nil-class.js +27 -0
  297. package/dist/nil-class.js.map +1 -0
  298. package/dist/no-method-error.d.ts +38 -0
  299. package/dist/no-method-error.js +45 -0
  300. package/dist/no-method-error.js.map +1 -0
  301. package/dist/not-implemented-error.d.ts +13 -0
  302. package/dist/not-implemented-error.js +14 -0
  303. package/dist/not-implemented-error.js.map +1 -0
  304. package/dist/numeric.d.ts +211 -0
  305. package/dist/numeric.js +802 -0
  306. package/dist/numeric.js.map +1 -0
  307. package/dist/object-space.d.ts +34 -0
  308. package/dist/object-space.js +152 -0
  309. package/dist/object-space.js.map +1 -0
  310. package/dist/object.d.ts +908 -0
  311. package/dist/object.js +2238 -0
  312. package/dist/object.js.map +1 -0
  313. package/dist/open-uri.d.ts +180 -0
  314. package/dist/open-uri.js +402 -0
  315. package/dist/open-uri.js.map +1 -0
  316. package/dist/open3.d.ts +69 -0
  317. package/dist/open3.js +134 -0
  318. package/dist/open3.js.map +1 -0
  319. package/dist/openssl.d.ts +479 -0
  320. package/dist/openssl.js +1052 -0
  321. package/dist/openssl.js.map +1 -0
  322. package/dist/optparse.d.ts +130 -0
  323. package/dist/optparse.js +457 -0
  324. package/dist/optparse.js.map +1 -0
  325. package/dist/os-adapter.d.ts +20 -0
  326. package/dist/os-adapter.js +95 -0
  327. package/dist/os-adapter.js.map +1 -0
  328. package/dist/pathname.d.ts +71 -0
  329. package/dist/pathname.js +394 -0
  330. package/dist/pathname.js.map +1 -0
  331. package/dist/pp.d.ts +60 -0
  332. package/dist/pp.js +195 -0
  333. package/dist/pp.js.map +1 -0
  334. package/dist/pretty-print.d.ts +89 -0
  335. package/dist/pretty-print.js +232 -0
  336. package/dist/pretty-print.js.map +1 -0
  337. package/dist/process-adapter.d.ts +224 -0
  338. package/dist/process-adapter.js +878 -0
  339. package/dist/process-adapter.js.map +1 -0
  340. package/dist/process.d.ts +192 -0
  341. package/dist/process.js +403 -0
  342. package/dist/process.js.map +1 -0
  343. package/dist/psych/class-loader.d.ts +92 -0
  344. package/dist/psych/class-loader.js +139 -0
  345. package/dist/psych/class-loader.js.map +1 -0
  346. package/dist/psych/coder.d.ts +144 -0
  347. package/dist/psych/coder.js +176 -0
  348. package/dist/psych/coder.js.map +1 -0
  349. package/dist/psych/core-ext.d.ts +8 -0
  350. package/dist/psych/core-ext.js +10 -0
  351. package/dist/psych/core-ext.js.map +1 -0
  352. package/dist/psych/emitter.d.ts +116 -0
  353. package/dist/psych/emitter.js +1130 -0
  354. package/dist/psych/emitter.js.map +1 -0
  355. package/dist/psych/exception.d.ts +43 -0
  356. package/dist/psych/exception.js +54 -0
  357. package/dist/psych/exception.js.map +1 -0
  358. package/dist/psych/handler.d.ts +59 -0
  359. package/dist/psych/handler.js +95 -0
  360. package/dist/psych/handler.js.map +1 -0
  361. package/dist/psych/handlers/document-stream.d.ts +17 -0
  362. package/dist/psych/handlers/document-stream.js +26 -0
  363. package/dist/psych/handlers/document-stream.js.map +1 -0
  364. package/dist/psych/nodes/alias.d.ts +15 -0
  365. package/dist/psych/nodes/alias.js +22 -0
  366. package/dist/psych/nodes/alias.js.map +1 -0
  367. package/dist/psych/nodes/document.d.ts +23 -0
  368. package/dist/psych/nodes/document.js +35 -0
  369. package/dist/psych/nodes/document.js.map +1 -0
  370. package/dist/psych/nodes/mapping.d.ts +25 -0
  371. package/dist/psych/nodes/mapping.js +35 -0
  372. package/dist/psych/nodes/mapping.js.map +1 -0
  373. package/dist/psych/nodes/node.d.ts +59 -0
  374. package/dist/psych/nodes/node.js +79 -0
  375. package/dist/psych/nodes/node.js.map +1 -0
  376. package/dist/psych/nodes/scalar.d.ts +35 -0
  377. package/dist/psych/nodes/scalar.js +47 -0
  378. package/dist/psych/nodes/scalar.js.map +1 -0
  379. package/dist/psych/nodes/sequence.d.ts +25 -0
  380. package/dist/psych/nodes/sequence.js +35 -0
  381. package/dist/psych/nodes/sequence.js.map +1 -0
  382. package/dist/psych/nodes/stream.d.ts +23 -0
  383. package/dist/psych/nodes/stream.js +31 -0
  384. package/dist/psych/nodes/stream.js.map +1 -0
  385. package/dist/psych/omap.d.ts +9 -0
  386. package/dist/psych/omap.js +9 -0
  387. package/dist/psych/omap.js.map +1 -0
  388. package/dist/psych/parser.d.ts +41 -0
  389. package/dist/psych/parser.js +139 -0
  390. package/dist/psych/parser.js.map +1 -0
  391. package/dist/psych/scalar-scanner.d.ts +35 -0
  392. package/dist/psych/scalar-scanner.js +173 -0
  393. package/dist/psych/scalar-scanner.js.map +1 -0
  394. package/dist/psych/syntax-error.d.ts +23 -0
  395. package/dist/psych/syntax-error.js +35 -0
  396. package/dist/psych/syntax-error.js.map +1 -0
  397. package/dist/psych/tree-builder.d.ts +51 -0
  398. package/dist/psych/tree-builder.js +118 -0
  399. package/dist/psych/tree-builder.js.map +1 -0
  400. package/dist/psych/visitors/depth-first.d.ts +27 -0
  401. package/dist/psych/visitors/depth-first.js +37 -0
  402. package/dist/psych/visitors/depth-first.js.map +1 -0
  403. package/dist/psych/visitors/emitter.d.ts +32 -0
  404. package/dist/psych/visitors/emitter.js +63 -0
  405. package/dist/psych/visitors/emitter.js.map +1 -0
  406. package/dist/psych/visitors/to-ruby.d.ts +110 -0
  407. package/dist/psych/visitors/to-ruby.js +396 -0
  408. package/dist/psych/visitors/to-ruby.js.map +1 -0
  409. package/dist/psych/visitors/visitor.d.ts +11 -0
  410. package/dist/psych/visitors/visitor.js +17 -0
  411. package/dist/psych/visitors/visitor.js.map +1 -0
  412. package/dist/psych/visitors/yaml-tree.d.ts +182 -0
  413. package/dist/psych/visitors/yaml-tree.js +593 -0
  414. package/dist/psych/visitors/yaml-tree.js.map +1 -0
  415. package/dist/psych-adapter.d.ts +65 -0
  416. package/dist/psych-adapter.js +121 -0
  417. package/dist/psych-adapter.js.map +1 -0
  418. package/dist/psych-yaml.d.ts +2 -0
  419. package/dist/psych-yaml.js +5 -0
  420. package/dist/psych-yaml.js.map +1 -0
  421. package/dist/psych.d.ts +257 -0
  422. package/dist/psych.js +332 -0
  423. package/dist/psych.js.map +1 -0
  424. package/dist/queue.d.ts +129 -0
  425. package/dist/queue.js +215 -0
  426. package/dist/queue.js.map +1 -0
  427. package/dist/racc/parser.d.ts +70 -0
  428. package/dist/racc/parser.js +206 -0
  429. package/dist/racc/parser.js.map +1 -0
  430. package/dist/range-error.d.ts +15 -0
  431. package/dist/range-error.js +15 -0
  432. package/dist/range-error.js.map +1 -0
  433. package/dist/range.d.ts +166 -0
  434. package/dist/range.js +421 -0
  435. package/dist/range.js.map +1 -0
  436. package/dist/rational.d.ts +167 -0
  437. package/dist/rational.js +379 -0
  438. package/dist/rational.js.map +1 -0
  439. package/dist/rb-config.d.ts +33 -0
  440. package/dist/rb-config.js +53 -0
  441. package/dist/rb-config.js.map +1 -0
  442. package/dist/rb-equal.d.ts +66 -0
  443. package/dist/rb-equal.js +261 -0
  444. package/dist/rb-equal.js.map +1 -0
  445. package/dist/rb-hash.d.ts +26 -0
  446. package/dist/rb-hash.js +108 -0
  447. package/dist/rb-hash.js.map +1 -0
  448. package/dist/regexp.d.ts +82 -0
  449. package/dist/regexp.js +191 -0
  450. package/dist/regexp.js.map +1 -0
  451. package/dist/repl-adapter.d.ts +188 -0
  452. package/dist/repl-adapter.js +388 -0
  453. package/dist/repl-adapter.js.map +1 -0
  454. package/dist/resolv.d.ts +30 -0
  455. package/dist/resolv.js +48 -0
  456. package/dist/resolv.js.map +1 -0
  457. package/dist/ruby-empty.d.ts +28 -0
  458. package/dist/ruby-empty.js +40 -0
  459. package/dist/ruby-empty.js.map +1 -0
  460. package/dist/ruby-platform.d.ts +39 -0
  461. package/dist/ruby-platform.js +49 -0
  462. package/dist/ruby-platform.js.map +1 -0
  463. package/dist/runtime-error.d.ts +15 -0
  464. package/dist/runtime-error.js +16 -0
  465. package/dist/runtime-error.js.map +1 -0
  466. package/dist/scheduled-task.d.ts +73 -0
  467. package/dist/scheduled-task.js +150 -0
  468. package/dist/scheduled-task.js.map +1 -0
  469. package/dist/secure-random.d.ts +33 -0
  470. package/dist/secure-random.js +78 -0
  471. package/dist/secure-random.js.map +1 -0
  472. package/dist/set.d.ts +158 -0
  473. package/dist/set.js +352 -0
  474. package/dist/set.js.map +1 -0
  475. package/dist/shellwords.d.ts +27 -0
  476. package/dist/shellwords.js +53 -0
  477. package/dist/shellwords.js.map +1 -0
  478. package/dist/signal-exception.d.ts +21 -0
  479. package/dist/signal-exception.js +21 -0
  480. package/dist/signal-exception.js.map +1 -0
  481. package/dist/socket.d.ts +230 -0
  482. package/dist/socket.js +484 -0
  483. package/dist/socket.js.map +1 -0
  484. package/dist/standard-error.d.ts +18 -0
  485. package/dist/standard-error.js +23 -0
  486. package/dist/standard-error.js.map +1 -0
  487. package/dist/stop-iteration.d.ts +10 -0
  488. package/dist/stop-iteration.js +10 -0
  489. package/dist/stop-iteration.js.map +1 -0
  490. package/dist/string/b.d.ts +19 -0
  491. package/dist/string/b.js +28 -0
  492. package/dist/string/b.js.map +1 -0
  493. package/dist/string/byte-methods.d.ts +57 -0
  494. package/dist/string/byte-methods.js +266 -0
  495. package/dist/string/byte-methods.js.map +1 -0
  496. package/dist/string/bytes.d.ts +35 -0
  497. package/dist/string/bytes.js +123 -0
  498. package/dist/string/bytes.js.map +1 -0
  499. package/dist/string/case-mapping.d.ts +57 -0
  500. package/dist/string/case-mapping.js +192 -0
  501. package/dist/string/case-mapping.js.map +1 -0
  502. package/dist/string/chomp.d.ts +15 -0
  503. package/dist/string/chomp.js +32 -0
  504. package/dist/string/chomp.js.map +1 -0
  505. package/dist/string/convert.d.ts +55 -0
  506. package/dist/string/convert.js +316 -0
  507. package/dist/string/convert.js.map +1 -0
  508. package/dist/string/delete.d.ts +14 -0
  509. package/dist/string/delete.js +17 -0
  510. package/dist/string/delete.js.map +1 -0
  511. package/dist/string/each.d.ts +108 -0
  512. package/dist/string/each.js +305 -0
  513. package/dist/string/each.js.map +1 -0
  514. package/dist/string/encode.d.ts +37 -0
  515. package/dist/string/encode.js +268 -0
  516. package/dist/string/encode.js.map +1 -0
  517. package/dist/string/force-encoding.d.ts +72 -0
  518. package/dist/string/force-encoding.js +147 -0
  519. package/dist/string/force-encoding.js.map +1 -0
  520. package/dist/string/inspect.d.ts +17 -0
  521. package/dist/string/inspect.js +81 -0
  522. package/dist/string/inspect.js.map +1 -0
  523. package/dist/string/method-table.d.ts +174 -0
  524. package/dist/string/method-table.js +805 -0
  525. package/dist/string/method-table.js.map +1 -0
  526. package/dist/string/scrub.d.ts +12 -0
  527. package/dist/string/scrub.js +33 -0
  528. package/dist/string/scrub.js.map +1 -0
  529. package/dist/string/slice.d.ts +26 -0
  530. package/dist/string/slice.js +73 -0
  531. package/dist/string/slice.js.map +1 -0
  532. package/dist/string/split.d.ts +11 -0
  533. package/dist/string/split.js +44 -0
  534. package/dist/string/split.js.map +1 -0
  535. package/dist/string/sub.d.ts +114 -0
  536. package/dist/string/sub.js +371 -0
  537. package/dist/string/sub.js.map +1 -0
  538. package/dist/string/succ.d.ts +14 -0
  539. package/dist/string/succ.js +118 -0
  540. package/dist/string/succ.js.map +1 -0
  541. package/dist/string/support.d.ts +135 -0
  542. package/dist/string/support.js +283 -0
  543. package/dist/string/support.js.map +1 -0
  544. package/dist/string/tr.d.ts +46 -0
  545. package/dist/string/tr.js +156 -0
  546. package/dist/string/tr.js.map +1 -0
  547. package/dist/string-io.d.ts +166 -0
  548. package/dist/string-io.js +248 -0
  549. package/dist/string-io.js.map +1 -0
  550. package/dist/string-scanner.d.ts +133 -0
  551. package/dist/string-scanner.js +248 -0
  552. package/dist/string-scanner.js.map +1 -0
  553. package/dist/struct.d.ts +54 -0
  554. package/dist/struct.js +222 -0
  555. package/dist/struct.js.map +1 -0
  556. package/dist/symbol.d.ts +48 -0
  557. package/dist/symbol.js +107 -0
  558. package/dist/symbol.js.map +1 -0
  559. package/dist/tempfile.d.ts +173 -0
  560. package/dist/tempfile.js +290 -0
  561. package/dist/tempfile.js.map +1 -0
  562. package/dist/temporal-tag.d.ts +23 -0
  563. package/dist/temporal-tag.js +29 -0
  564. package/dist/temporal-tag.js.map +1 -0
  565. package/dist/thread-error.d.ts +13 -0
  566. package/dist/thread-error.js +13 -0
  567. package/dist/thread-error.js.map +1 -0
  568. package/dist/thread-pool-executor.d.ts +119 -0
  569. package/dist/thread-pool-executor.js +250 -0
  570. package/dist/thread-pool-executor.js.map +1 -0
  571. package/dist/thread.d.ts +211 -0
  572. package/dist/thread.js +495 -0
  573. package/dist/thread.js.map +1 -0
  574. package/dist/timeout.d.ts +29 -0
  575. package/dist/timeout.js +41 -0
  576. package/dist/timeout.js.map +1 -0
  577. package/dist/tse.d.ts +40 -0
  578. package/dist/tse.js +62 -0
  579. package/dist/tse.js.map +1 -0
  580. package/dist/type-error.d.ts +14 -0
  581. package/dist/type-error.js +15 -0
  582. package/dist/type-error.js.map +1 -0
  583. package/dist/undefined-conversion-error.d.ts +10 -0
  584. package/dist/undefined-conversion-error.js +10 -0
  585. package/dist/undefined-conversion-error.js.map +1 -0
  586. package/dist/uri/common.d.ts +209 -0
  587. package/dist/uri/common.js +369 -0
  588. package/dist/uri/common.js.map +1 -0
  589. package/dist/uri/generic.d.ts +283 -0
  590. package/dist/uri/generic.js +810 -0
  591. package/dist/uri/generic.js.map +1 -0
  592. package/dist/uri/http.d.ts +23 -0
  593. package/dist/uri/http.js +30 -0
  594. package/dist/uri/http.js.map +1 -0
  595. package/dist/uri/https.d.ts +13 -0
  596. package/dist/uri/https.js +15 -0
  597. package/dist/uri/https.js.map +1 -0
  598. package/dist/uri/rfc2396-parser.d.ts +70 -0
  599. package/dist/uri/rfc2396-parser.js +264 -0
  600. package/dist/uri/rfc2396-parser.js.map +1 -0
  601. package/dist/uri/rfc3986-parser.d.ts +46 -0
  602. package/dist/uri/rfc3986-parser.js +171 -0
  603. package/dist/uri/rfc3986-parser.js.map +1 -0
  604. package/dist/uri.d.ts +13 -0
  605. package/dist/uri.js +13 -0
  606. package/dist/uri.js.map +1 -0
  607. package/dist/variable.d.ts +183 -0
  608. package/dist/variable.js +463 -0
  609. package/dist/variable.js.map +1 -0
  610. package/dist/verbose.d.ts +21 -0
  611. package/dist/verbose.js +26 -0
  612. package/dist/verbose.js.map +1 -0
  613. package/dist/yaml.d.ts +9 -0
  614. package/dist/yaml.js +9 -0
  615. package/dist/yaml.js.map +1 -0
  616. package/dist/zlib-adapter.d.ts +117 -0
  617. package/dist/zlib-adapter.js +250 -0
  618. package/dist/zlib-adapter.js.map +1 -0
  619. package/dist/zlib.d.ts +248 -0
  620. package/dist/zlib.js +362 -0
  621. package/dist/zlib.js.map +1 -0
  622. package/package.json +82 -3
package/dist/object.js ADDED
@@ -0,0 +1,2238 @@
1
+ import { classModule } from "./class-module.js";
2
+ import { LocalJumpError } from "./local-jump-error.js";
3
+ import { classpaths, rbClassPath, isModuleObject } from "./classpath.js";
4
+ import { ARRAY_METHOD_TABLE, aryIncludes, each as aryEach } from "./array.js";
5
+ import { Enumerable } from "./enumerable.js";
6
+ import { hasKey, hashAref, hashAset, hashClear, hashDelete, fetch } from "./hash.js";
7
+ import { stringInspect } from "./string/inspect.js";
8
+ import { rbCheckStringType, rbErrorArity, stringValue } from "./string/support.js";
9
+ import { rbPlus } from "./numeric.js";
10
+ import { BINARY_METHOD_TABLE, STRING_METHOD_TABLE, rbStrSend } from "./string/method-table.js";
11
+ import { isSymbol, stringToSym, symbolToS } from "./symbol.js";
12
+ import { cmp, rbCmpint } from "./comparable.js";
13
+ import { rbEql, rbEqual } from "./rb-equal.js";
14
+ import { TypeError } from "./type-error.js";
15
+ import { NameError } from "./name-error.js";
16
+ import { FrozenError } from "./frozen-error.js";
17
+ import { temporalTag } from "./temporal-tag.js";
18
+ import { rbRegToS } from "./regexp.js";
19
+ import { NoMethodError } from "./no-method-error.js";
20
+ import { Hash } from "./hash.js";
21
+ import { toEnum } from "./enumerator.js";
22
+ import { methodCacheSerial, rbClearMethodCache } from "./method-cache.js";
23
+ /**
24
+ * Each method's `super` slot, which {@link rbSeatSuper} writes and
25
+ * `rbCallSuper` reads (MRI `vm_search_super_method`,
26
+ * `vendor/ruby/v3.3.11/vm_insnhelper.c:4680`).
27
+ *
28
+ * @internal
29
+ * @noRailsEquivalent PERMANENT
30
+ */
31
+ export const superSlots = new WeakMap();
32
+ /**
33
+ * A method's own copy of its {@link superSlots} slot (MRI
34
+ * `vm_search_super_method`, `vendor/ruby/v3.3.11/vm_insnhelper.c:4680`).
35
+ *
36
+ * @internal
37
+ * @noRailsEquivalent PERMANENT
38
+ * @perf 10ns — PERMANENT
39
+ */
40
+ export const _superSlot = Symbol("superSlot");
41
+ /**
42
+ * `method`'s entry in {@link superSlots}, made on first use under the `key`
43
+ * it is being installed as, the `original_id` MRI's `vm_search_super_method`
44
+ * (`vendor/ruby/v3.3.11/vm_insnhelper.c:4680`) searches by.
45
+ *
46
+ * @internal
47
+ * @noRailsEquivalent PERMANENT
48
+ */
49
+ export function superSlotFor(method, key) {
50
+ let entry = superSlots.get(method);
51
+ if (entry === undefined) {
52
+ superSlots.set(method, (entry = { slot: Symbol(`super:${key}`), key }));
53
+ if (Object.isExtensible(method))
54
+ Object.defineProperty(method, _superSlot, { value: entry.slot });
55
+ }
56
+ return entry;
57
+ }
58
+ /**
59
+ * `rb_obj_class` (`vendor/ruby/v3.3.11/object.c:265`), `Object#class`: the
60
+ * class object, read as `rb_class_of`
61
+ * (`vendor/ruby/v3.3.11/include/ruby/internal/globals.h:172`) reads it for the
62
+ * immediates Ruby answers a class for without a heap object, and otherwise
63
+ * the constructor, which a singleton class leaves naming the real class.
64
+ *
65
+ * @boundary: a JS `number` is the seat for both `Integer` and `Float`, so
66
+ * which one it is is read off the value; a `Uint8Array` is the binary
67
+ * `String` seat, and an instance of a `Uint8Array` subclass is an instance of
68
+ * that String subclass, whose ancestry `class_search_ancestor` continues
69
+ * into `String`'s at `Uint8Array.prototype`; a Temporal value carrying an instant
70
+ * is a Ruby `Time`, by the same reading `cmp` orders it with, and so are a JS
71
+ * `Date` and a `Temporal.PlainTime`. A function is a `Class` when its
72
+ * `prototype` is non-writable and a `Proc` otherwise. `Temporal.PlainDate` and
73
+ * `Temporal.PlainDateTime` are the seats of `Date` and `DateTime`, and a
74
+ * record whose prototype chain holds no class is a `Hash`, or a `Module` when
75
+ * `const_set` or `defineModule` marked it (`rb_obj_class`,
76
+ * `vendor/ruby/v3.3.11/object.c:296`). `-0` is a whole
77
+ * `number` and so an `Integer`, though Ruby has no negative Integer zero: JS
78
+ * integer arithmetic answers `-0` (`Math.round(-0.4)`, `0 * -1`) where Ruby
79
+ * answers `0`, so reading it as `-0.0` would turn those into Floats. The
80
+ * Float `-0.0` is the boxed `new Number(-0)`.
81
+ *
82
+ * @noRailsEquivalent PERMANENT
83
+ */
84
+ export function rbObjClass(obj) {
85
+ if (obj === null || obj === undefined)
86
+ return rbCNilClass;
87
+ if (typeof obj === "boolean")
88
+ return obj ? rbCTrueClass : rbCFalseClass;
89
+ if (typeof obj === "bigint")
90
+ return rbCInteger;
91
+ if (typeof obj === "number")
92
+ return Number.isInteger(obj) ? rbCInteger : rbCFloat;
93
+ if (obj instanceof Number)
94
+ return rbCFloat;
95
+ if (typeof obj === "string")
96
+ return rbCString;
97
+ if (obj instanceof String && obj.constructor === String)
98
+ return rbCString;
99
+ if (obj instanceof Uint8Array) {
100
+ const klass = obj.constructor;
101
+ const nodeBuffer = globalThis.Buffer;
102
+ return klass === Uint8Array || klass === nodeBuffer ? rbCString : klass;
103
+ }
104
+ if (typeof obj === "function") {
105
+ return Object.getOwnPropertyDescriptor(obj, "prototype")?.writable === false
106
+ ? rbCClass
107
+ : rbCProc;
108
+ }
109
+ if (temporalTag(obj) !== null &&
110
+ typeof obj.epochNanoseconds === "bigint") {
111
+ return reopened(rbCTime);
112
+ }
113
+ const tag = temporalTag(obj);
114
+ if (tag === "Temporal.PlainDate")
115
+ return reopened(rbCDate);
116
+ if (tag === "Temporal.PlainDateTime")
117
+ return reopened(rbCDateTime);
118
+ if (tag === "Temporal.PlainTime")
119
+ return reopened(rbCTime);
120
+ if (isPlainHash(obj))
121
+ return isModuleObject(obj) ? Object.getPrototypeOf(rbCClass) : Hash;
122
+ const klass = obj.constructor;
123
+ if (klass === Date)
124
+ return reopened(rbCTime);
125
+ return typeof klass === "function" ? klass : Object;
126
+ }
127
+ /**
128
+ * The receiver phrase of `name_err_mesg_to_str`
129
+ * (`vendor/ruby/v3.3.11/error.c:2325-2390`), the `%3$s%4$s` of an
130
+ * `undefined method '…' for …` message: `nil`, `true` or `false` for those
131
+ * receivers, `module M` / `class C` for a module or class, and
132
+ * `an instance of C` otherwise.
133
+ *
134
+ * @noRailsEquivalent PERMANENT
135
+ */
136
+ export function nameErrMesgReceiver(obj) {
137
+ switch (obj) {
138
+ case null:
139
+ case undefined:
140
+ return "nil";
141
+ case true:
142
+ return "true";
143
+ case false:
144
+ return "false";
145
+ }
146
+ if ((typeof obj === "object" && obj !== null && isModuleObject(obj)) ||
147
+ (typeof obj === "function" && Object.hasOwn(obj, classModule))) {
148
+ return `module ${rbModToS(obj)}`;
149
+ }
150
+ if (rbObjClass(obj) === rbCClass)
151
+ return `class ${rbModToS(obj)}`;
152
+ return `an instance of ${rbObjClassname(obj)}`;
153
+ }
154
+ /**
155
+ * `rb_obj_classname` (`vendor/ruby/v3.3.11/variable.c:498`): the
156
+ * {@link rbModToS} of the class {@link rbObjClass} answers, which is how Ruby
157
+ * interpolates `obj.class`.
158
+ *
159
+ * @noRailsEquivalent PERMANENT
160
+ */
161
+ export function rbObjClassname(x) {
162
+ return rbModToS(rbObjClass(x));
163
+ }
164
+ /**
165
+ * `rb_set_class_path_string` (`vendor/ruby/v3.3.11/variable.c:407`), by which
166
+ * `declare_under` (`vendor/ruby/v3.3.11/vm_insnhelper.c:5375`) paths a class
167
+ * after the cbase it is declared in: `under`'s path, `::`, and `name`.
168
+ *
169
+ * @noRailsEquivalent PERMANENT
170
+ */
171
+ export function rbSetClassPathString(klass, under, name) {
172
+ const permanent = typeof under === "function"
173
+ ? (classpaths.get(under)?.permanent ?? Boolean(under.name))
174
+ : under.name != null;
175
+ const str = typeof under === "function"
176
+ ? rbModToS(under)
177
+ : (under.name ?? rbAnyToS(under));
178
+ classpaths.set(klass, { path: `${str}::${name}`, permanent });
179
+ }
180
+ /**
181
+ * Ruby's top-level `Object`, whose constant table is
182
+ * `RCLASS_CONST_TBL(rb_cObject)` (`vendor/ruby/v3.3.11/internal/class.h:95`). It
183
+ * lives with `rb_cObject` so `object.ts` reads it without importing
184
+ * `variable.ts`, whose load-time core-class seats need this module
185
+ * evaluated first. It has no prototype, so a name such as `constructor` is
186
+ * not a constant.
187
+ *
188
+ * @noRailsEquivalent PERMANENT
189
+ */
190
+ export const TopLevel = Object.create(null);
191
+ /**
192
+ * The one class object a core class has once a gem reopens it
193
+ * (`class Date extends rbCDate`, seated on `TopLevel`): MRI has one
194
+ * `cDate` (`vendor/ruby/v3.3.11/ext/date/date_core.c:9604`), so the seat and
195
+ * the class reopening it are the same class. A class nothing reopens is
196
+ * answered as it is.
197
+ *
198
+ * @noRailsEquivalent PERMANENT
199
+ */
200
+ export function reopened(klass) {
201
+ const path = classpaths.get(klass)?.path;
202
+ return path === undefined ? klass : (TopLevel[path] ?? klass);
203
+ }
204
+ /**
205
+ * `FL_SINGLETON` (`vendor/ruby/v3.3.11/include/ruby/internal/fl_type.h:58`), the
206
+ * flag marking a class as some object's singleton class.
207
+ *
208
+ * @noRailsEquivalent PERMANENT
209
+ */
210
+ export const FL_SINGLETON = Symbol.for("@blazetrails/ruby-compat:FL_SINGLETON");
211
+ /**
212
+ * `rb_obj_singleton_class` (`vendor/ruby/v3.3.11/object.c:288`), Ruby's
213
+ * `Kernel#singleton_class`, over `singleton_class_of` (`vendor/ruby/v3.3.11/class.c:2215`):
214
+ * the receiver's own class, created on first call and inserted between the
215
+ * object and its class. The JS seat is a subclass of `obj.constructor` that
216
+ * becomes the object's prototype. Its `prototype.constructor` stays the
217
+ * attached object's class, because `rb_obj_class` skips a singleton class
218
+ * (`vendor/ruby/v3.3.11/object.c:296`): `obj.constructor` keeps answering Ruby's
219
+ * `obj.class`. Ruby gives a class receiver a metaclass
220
+ * (`vendor/ruby/v3.3.11/class.c:2240`); a JS class has none apart from its own
221
+ * statics, so a class receiver is unsupported here and raises `TypeError`,
222
+ * a trails limitation rather than Ruby behavior.
223
+ *
224
+ * @noRailsEquivalent PERMANENT
225
+ */
226
+ export function rbObjSingletonClass(obj) {
227
+ if (typeof obj === "function")
228
+ throw new TypeError("can't define singleton");
229
+ const proto = Object.getPrototypeOf(obj);
230
+ if (proto !== null && Object.hasOwn(proto, FL_SINGLETON)) {
231
+ return proto[FL_SINGLETON];
232
+ }
233
+ const superclass = (proto === null ? rbObjClass(obj) : obj.constructor);
234
+ const klass = class extends superclass {
235
+ };
236
+ Object.defineProperty(klass, FL_SINGLETON, { value: obj });
237
+ Object.defineProperty(klass.prototype, FL_SINGLETON, { value: klass });
238
+ Object.defineProperty(klass, "toString", { value: () => rbModToS(klass) });
239
+ Object.defineProperty(klass.prototype, "constructor", {
240
+ value: superclass,
241
+ writable: true,
242
+ configurable: true,
243
+ });
244
+ Object.setPrototypeOf(klass.prototype, proto);
245
+ Object.setPrototypeOf(obj, klass.prototype);
246
+ return klass;
247
+ }
248
+ /**
249
+ * `rb_singleton_class` (`vendor/ruby/v3.3.11/class.c:2286`). An object
250
+ * receiver answers {@link rbObjSingletonClass}. A class receiver answers its
251
+ * metaclass (`make_metaclass`, `vendor/ruby/v3.3.11/class.c:757`): a JS class's
252
+ * singleton methods are its own statics, so the metaclass's method table, its
253
+ * `prototype`, is the class itself, and `prepend` onto it writes the statics.
254
+ *
255
+ * @noRailsEquivalent PERMANENT
256
+ */
257
+ export function rbSingletonClass(obj) {
258
+ if (typeof obj !== "function")
259
+ return rbObjSingletonClass(obj);
260
+ const cached = _metaclasses.get(obj);
261
+ if (cached)
262
+ return cached;
263
+ const metaclass = function () { };
264
+ metaclass.prototype = obj;
265
+ Object.defineProperty(metaclass, FL_SINGLETON, { value: obj });
266
+ const klass = metaclass;
267
+ _metaclasses.set(obj, klass);
268
+ return klass;
269
+ }
270
+ const _metaclasses = new WeakMap();
271
+ /**
272
+ * `rb_class_of` (`vendor/ruby/v3.3.11/include/ruby/internal/globals.h:172`):
273
+ * the singleton class when the object has one, where {@link rbObjClass}
274
+ * skips it, and the class {@link rbObjClass} answers otherwise.
275
+ *
276
+ * @noRailsEquivalent PERMANENT
277
+ */
278
+ export function rbClassOf(obj) {
279
+ if (typeof obj === "object" && obj !== null) {
280
+ const proto = Object.getPrototypeOf(obj);
281
+ if (proto !== null && Object.hasOwn(proto, FL_SINGLETON)) {
282
+ return proto[FL_SINGLETON];
283
+ }
284
+ }
285
+ return rbObjClass(obj);
286
+ }
287
+ /**
288
+ * `T_ICLASS` (`vendor/ruby/v3.3.11/include/ruby/internal/value_type.h:140`), the
289
+ * type of the hidden class an `include` or `extend` splices into an ancestry. A link
290
+ * carries the module it stands for under this key.
291
+ *
292
+ * @noRailsEquivalent PERMANENT
293
+ */
294
+ export const T_ICLASS = Symbol.for("@blazetrails/ruby-compat:T_ICLASS");
295
+ /**
296
+ * `rb_class_superclass` (`vendor/ruby/v3.3.11/object.c:2191`), `Class#superclass`:
297
+ * the next `T_CLASS` in the ancestry, so the iclass an `extend` put above the
298
+ * class is skipped, where `Object.getPrototypeOf` answers it.
299
+ *
300
+ * @noRailsEquivalent PERMANENT
301
+ */
302
+ export function rbClassSuperclass(klass) {
303
+ let superclass = Object.getPrototypeOf(klass);
304
+ while (superclass && Object.hasOwn(superclass, T_ICLASS)) {
305
+ superclass = Object.getPrototypeOf(superclass);
306
+ }
307
+ return superclass === Function.prototype ? null : superclass;
308
+ }
309
+ export { classpaths };
310
+ /** `rb_define_class` (`vendor/ruby/v3.3.11/class.c:972`) for a core class no JS constructor seats. */
311
+ function rbDefineClass(name, superclass = Object) {
312
+ const klass = class extends superclass {
313
+ };
314
+ classpaths.set(klass, { path: name, permanent: true });
315
+ return klass;
316
+ }
317
+ /**
318
+ * `rb_cBasicObject` (`vendor/ruby/v3.3.11/object.c:4200`). `Object.prototype`
319
+ * is the seat of `Object`, so this prototype has no parent.
320
+ * @noRailsEquivalent PERMANENT
321
+ */
322
+ export const rbCBasicObject = rbDefineClass("BasicObject");
323
+ Object.setPrototypeOf(rbCBasicObject.prototype, null);
324
+ /**
325
+ * `rb_cClass` (`vendor/ruby/v3.3.11/object.c:4203`), a `Module` once include.ts loads.
326
+ * @noRailsEquivalent PERMANENT
327
+ */
328
+ export const rbCClass = rbDefineClass("Class");
329
+ /**
330
+ * `rb_cNumeric` (`vendor/ruby/v3.3.11/numeric.c:6156`). `Rational`
331
+ * (`vendor/ruby/v3.3.11/rational.c:2759`), `Complex`
332
+ * (`vendor/ruby/v3.3.11/complex.c:2529`) and `BigDecimal`
333
+ * (`vendor/ruby/v3.3.11/ext/bigdecimal/bigdecimal.c:4407`) are seated beneath
334
+ * it at the foot of include.ts, not by `extends`: this module reaches
335
+ * rational.ts through string/method-table.ts and kernel-format.ts, so an
336
+ * `extends rbCNumeric` reads the binding before this module body has run
337
+ * whenever this module is entered first.
338
+ * @noRailsEquivalent PERMANENT
339
+ */
340
+ export const rbCNumeric = rbDefineClass("Numeric");
341
+ /** `Numeric#integer?` (`vendor/ruby/v3.3.11/numeric.rb:29`). */
342
+ Object.defineProperty(rbCNumeric.prototype, "isInteger", {
343
+ value: function isInteger() {
344
+ return false;
345
+ },
346
+ writable: true,
347
+ configurable: true,
348
+ });
349
+ /**
350
+ * `rb_cString` (`vendor/ruby/v3.3.11/string.c:12121`).
351
+ * @noRailsEquivalent PERMANENT
352
+ */
353
+ export const rbCString = rbDefineClass("String");
354
+ /**
355
+ * `rb_cSymbol` (`vendor/ruby/v3.3.11/string.c:12290`).
356
+ * @noRailsEquivalent PERMANENT
357
+ */
358
+ export const rbCSymbol = rbDefineClass("Symbol");
359
+ /**
360
+ * `rb_cTime` (`vendor/ruby/v3.3.11/time.c:5832`).
361
+ * @noRailsEquivalent PERMANENT
362
+ */
363
+ export const rbCTime = rbDefineClass("Time");
364
+ /**
365
+ * `cDate` (`vendor/ruby/v3.3.11/ext/date/date_core.c:9604`).
366
+ * @noRailsEquivalent PERMANENT
367
+ */
368
+ export const rbCDate = rbDefineClass("Date");
369
+ /**
370
+ * `cDateTime` (`vendor/ruby/v3.3.11/ext/date/date_core.c:9984`).
371
+ * @noRailsEquivalent PERMANENT
372
+ */
373
+ export const rbCDateTime = rbDefineClass("DateTime", rbCDate);
374
+ /**
375
+ * `rb_cNilClass` (`vendor/ruby/v3.3.11/object.c:4412`).
376
+ * @noRailsEquivalent PERMANENT
377
+ */
378
+ export const rbCNilClass = rbDefineClass("NilClass");
379
+ /**
380
+ * `rb_cTrueClass` (`vendor/ruby/v3.3.11/object.c:4498`).
381
+ * @noRailsEquivalent PERMANENT
382
+ */
383
+ export const rbCTrueClass = rbDefineClass("TrueClass");
384
+ /**
385
+ * `rb_cFalseClass` (`vendor/ruby/v3.3.11/object.c:4510`).
386
+ * @noRailsEquivalent PERMANENT
387
+ */
388
+ export const rbCFalseClass = rbDefineClass("FalseClass");
389
+ /**
390
+ * `rb_cInteger` (`vendor/ruby/v3.3.11/numeric.c:6190`).
391
+ * @noRailsEquivalent PERMANENT
392
+ */
393
+ export const rbCInteger = rbDefineClass("Integer", rbCNumeric);
394
+ /**
395
+ * `Integer#integer?` (`vendor/ruby/v3.3.11/numeric.rb:178`).
396
+ * @noRailsEquivalent PERMANENT
397
+ */
398
+ rbModDefineMethod(rbCInteger, "isInteger", () => true);
399
+ /**
400
+ * `rb_cFloat` (`vendor/ruby/v3.3.11/numeric.c:6259`).
401
+ * @noRailsEquivalent PERMANENT
402
+ */
403
+ export const rbCFloat = rbDefineClass("Float", rbCNumeric);
404
+ /**
405
+ * `rb_cArray` (`vendor/ruby/v3.3.11/array.c:8605`): the seat a reopened
406
+ * `class Array` defines its methods on, since a JS array's prototype is the
407
+ * global `Array.prototype`.
408
+ * @noRailsEquivalent PERMANENT
409
+ */
410
+ export const rbCArray = rbDefineClass("Array");
411
+ /**
412
+ * `rb_cProc` (`vendor/ruby/v3.3.11/proc.c:4290`).
413
+ * @noRailsEquivalent PERMANENT
414
+ */
415
+ export const rbCProc = rbDefineClass("Proc");
416
+ const SPECIAL_CONST_CLASSES = new Set([
417
+ rbCNilClass,
418
+ rbCTrueClass,
419
+ rbCFalseClass,
420
+ rbCInteger,
421
+ rbCFloat,
422
+ rbCString,
423
+ ]);
424
+ function classSeatMethodTable(recv) {
425
+ if (typeof recv === "function")
426
+ return null;
427
+ if (recv && typeof recv === "object" && !(recv instanceof Number || recv instanceof Uint8Array)) {
428
+ return null;
429
+ }
430
+ if (isSymbol(recv))
431
+ return rbCSymbol.prototype;
432
+ const klass = rbObjClass(recv);
433
+ return SPECIAL_CONST_CLASSES.has(klass) ? klass.prototype : null;
434
+ }
435
+ const HASH_CLASS_BODY = Symbol.for("@blazetrails/ruby-compat:HASH_CLASS_BODY");
436
+ function reopenedSeatMethod(recv, mid) {
437
+ if (Array.isArray(recv)) {
438
+ for (let o = rbCArray.prototype; o && o !== Object.prototype; o = Object.getPrototypeOf(o)) {
439
+ const desc = Object.getOwnPropertyDescriptor(o, mid);
440
+ if (typeof desc?.value === "function")
441
+ return desc.value;
442
+ }
443
+ }
444
+ else if (isPlainHash(recv)) {
445
+ const classBody = Hash.prototype[HASH_CLASS_BODY];
446
+ if (classBody?.has(mid) !== false)
447
+ return undefined;
448
+ const desc = Object.getOwnPropertyDescriptor(Hash.prototype, mid);
449
+ if (typeof desc?.value === "function")
450
+ return desc.value;
451
+ }
452
+ return undefined;
453
+ }
454
+ /**
455
+ * `rb_mod_singleton_p` (`vendor/ruby/v3.3.11/object.c:3050`), `Module#singleton_class?`.
456
+ *
457
+ * @noRailsEquivalent PERMANENT
458
+ */
459
+ export function rbModSingletonP(klass) {
460
+ return typeof klass === "function" && Object.hasOwn(klass, FL_SINGLETON);
461
+ }
462
+ /**
463
+ * `rb_class_attached_object` (`vendor/ruby/v3.3.11/class.c:1707-1714`),
464
+ * `Class#attached_object`.
465
+ *
466
+ * @noRailsEquivalent PERMANENT
467
+ */
468
+ export function rbClassAttachedObject(klass) {
469
+ if (!rbModSingletonP(klass)) {
470
+ throw new TypeError(`\`${rbModToS(klass)}' is not a singleton class`);
471
+ }
472
+ return klass[FL_SINGLETON];
473
+ }
474
+ /**
475
+ * `rb_mod_to_s` (`vendor/ruby/v3.3.11/object.c:1710-1742`), `Module#to_s` /
476
+ * `Module#inspect`: a singleton class renders `#<Class:` plus its attached
477
+ * object — `rb_inspect` for a class or module, `rb_any_to_s` otherwise — and
478
+ * `>`; any other class renders `rb_class_name`: its name, or for an anonymous
479
+ * class the `#<Class:0x…>` path `make_temporary_path`
480
+ * (`vendor/ruby/v3.3.11/variable.c:320-336`) gives it. Ruby's refinement arm
481
+ * has no JS seat.
482
+ *
483
+ * @noRailsEquivalent PERMANENT
484
+ */
485
+ export function rbModToS(klass) {
486
+ if (typeof klass !== "function") {
487
+ return classpaths.get(klass)?.path ?? `#<Module:${objAddress(klass)}>`;
488
+ }
489
+ if (rbModSingletonP(klass)) {
490
+ let s = "#<Class:";
491
+ const v = klass[FL_SINGLETON];
492
+ if (typeof v === "function") {
493
+ s += rbInspect(v);
494
+ }
495
+ else {
496
+ s += rbAnyToS(v);
497
+ }
498
+ s += ">";
499
+ return s;
500
+ }
501
+ return (classpaths.get(klass)?.path ??
502
+ (Object.hasOwn(klass, "toString") ? String(klass) : undefined) ??
503
+ rbModName(klass) ??
504
+ `#<Class:${objAddress(klass)}>`);
505
+ }
506
+ /**
507
+ * `rb_mod_name` (`vendor/ruby/v3.3.11/variable.c:122-127`), `Module#name`: the
508
+ * classpath a `const_set` or a module-eval seat gave the class, else the path
509
+ * its package's generated table holds (RFC 0205), else the name its
510
+ * definition gave it, or `nil` while it is anonymous.
511
+ *
512
+ * A class expression with no identifier is Ruby's `Class.new`, which JS names
513
+ * after the binding it is assigned to. Like Ruby, that names the class only
514
+ * when the binding is a constant name (`Foo = Class.new`), not a local
515
+ * (`klass = Class.new`).
516
+ *
517
+ * A minifier that mangles class names is out of scope, as it is for every
518
+ * reader of `name`. A bundle keeps its classes named by preserving names
519
+ * (esbuild `keepNames`) or by seating them.
520
+ *
521
+ * @noRailsEquivalent PERMANENT
522
+ */
523
+ export function rbModName(klass) {
524
+ const path = rbClassPath(klass);
525
+ if (path !== undefined)
526
+ return path;
527
+ const name = klass.name;
528
+ if (!name)
529
+ return null;
530
+ if (typeof klass !== "function" || /^[\p{Lu}\p{Lt}]/u.test(name))
531
+ return name;
532
+ const source = Function.prototype.toString.call(klass);
533
+ return /^class(?:\s|\/\*[\s\S]*?\*\/|\/\/.*)*(?:extends\b|\{)/.test(source) ? null : name;
534
+ }
535
+ /**
536
+ * The methods a package defines on `Object`, as `rb_define_method` on
537
+ * `rb_cObject` (`vendor/ruby/v3.3.11/class.c:2134`) does, keyed by the camelCased Ruby
538
+ * name, which {@link rbFSend} dispatches for a receiver whose own class
539
+ * defines none: ActiveSupport's `Object#in?`
540
+ * (`activesupport/lib/active_support/core_ext/object/inclusion.rb:15`) is
541
+ * reached by `value.public_send(:in?, range)` on an Integer.
542
+ *
543
+ * @noRailsEquivalent PERMANENT
544
+ */
545
+ export const OBJECT_METHOD_TABLE = Object.create(null);
546
+ /**
547
+ * `BasicObject#instance_exec` (`rb_obj_instance_exec`,
548
+ * `vendor/ruby/v3.3.11/vm_eval.c:2089`): yields `args` to the trailing block
549
+ * with `self` as the receiver.
550
+ */
551
+ OBJECT_METHOD_TABLE.instanceExec = (self, ...args) => {
552
+ const blk = args.at(-1);
553
+ if (typeof blk !== "function")
554
+ throw new LocalJumpError("no block given (yield)");
555
+ return blk.apply(self, args.slice(0, -1));
556
+ };
557
+ /**
558
+ * The methods a package defines on `Enumerable`, keyed by the camelCased Ruby
559
+ * name, which {@link rbFSend} dispatches and {@link basicObjRespondTo} answers
560
+ * for on the receivers `each` is bound for: a JS array, a `Set`, and a `Map`
561
+ * or plain hash, whose Ruby classes include `Enumerable`
562
+ * (`vendor/ruby/v3.3.11/array.c:8606`, `lib/set.rb:221`, `hash.c:7184`), and
563
+ * an object that defines `Symbol.iterator`, a class's
564
+ * `include Enumerable` (`enum.c:5061`).
565
+ * ActiveSupport's `Enumerable#maximum`
566
+ * (`activesupport/lib/active_support/core_ext/enumerable.rb:40`) is reached by
567
+ * `object.try(:maximum, :updated_at)` on an Array of records.
568
+ *
569
+ * @noRailsEquivalent PERMANENT
570
+ */
571
+ export const ENUMERABLE_METHOD_TABLE = Object.create(null);
572
+ function enumerableMethod(obj, mid) {
573
+ return Object.hasOwn(ENUMERABLE_METHOD_TABLE, mid) &&
574
+ (Array.isArray(obj) ||
575
+ obj instanceof Set ||
576
+ obj instanceof Map ||
577
+ isPlainHash(obj) ||
578
+ (typeof obj === "object" &&
579
+ obj !== null &&
580
+ typeof obj[Symbol.iterator] === "function"))
581
+ ? ENUMERABLE_METHOD_TABLE[mid]
582
+ : undefined;
583
+ }
584
+ /**
585
+ * `rb_include_module(rb_cArray, rb_mEnumerable)` (`vendor/ruby/v3.3.11/array.c:8606`):
586
+ * the ported `Enumerable` module, which {@link rbFSend} dispatches and
587
+ * {@link basicObjRespondTo} answers for on an Array that has no member or
588
+ * `ARRAY_METHOD_TABLE` entry of that name.
589
+ */
590
+ const enumerableModule = () => Enumerable.prototype;
591
+ /**
592
+ * `rb_obj_is_proc` (`vendor/ruby/v3.3.11/proc.c:120`): a function that is not
593
+ * a class, which is what a block or a lambda is.
594
+ *
595
+ * @noRailsEquivalent PERMANENT
596
+ */
597
+ export function rbObjIsProc(proc) {
598
+ return typeof proc === "function" && rbObjClass(proc) === rbCProc;
599
+ }
600
+ /**
601
+ * Ruby's `callable.call(*args)`: `rb_proc_call` (`vendor/ruby/v3.3.11/proc.c:990`)
602
+ * applies a proc to the arguments, where JS `Function.prototype.call` would
603
+ * take the first as `this`; any other receiver answers its own `call`, and one
604
+ * with no `call` member is sent `call`, so it reaches `method_missing` or
605
+ * raises `NoMethodError` as {@link rbFSend} does.
606
+ *
607
+ * @noRailsEquivalent PERMANENT
608
+ */
609
+ export function rbProcCall(callable, ...args) {
610
+ if (rbObjIsProc(callable))
611
+ return callable(...args);
612
+ const call = callable?.call;
613
+ if (typeof call === "function")
614
+ return call.apply(callable, args);
615
+ return sendInternal(args.length + 1, ["call", ...args], callable);
616
+ }
617
+ /**
618
+ * The methods a package defines on `Class`, as `rb_define_method` on
619
+ * `rb_cClass` (`vendor/ruby/v3.3.11/class.c:2134`) does, keyed by the camelCased Ruby
620
+ * name, which {@link basicObjRespondTo} answers for a class receiver:
621
+ * ActiveSupport's `Class#class_attribute`
622
+ * (`activesupport/lib/active_support/core_ext/class/attribute.rb:86`) is what
623
+ * `respond_to?(:class_attribute)` asks of a class and not of a module.
624
+ *
625
+ * @noRailsEquivalent PERMANENT
626
+ */
627
+ export const CLASS_METHOD_TABLE = Object.create(null);
628
+ /**
629
+ * The methods bound on a Temporal seat, keyed by its `Symbol.toStringTag` and
630
+ * then by the camelCased Ruby name, which {@link rbFSend} dispatches and
631
+ * {@link basicObjRespondTo} answers for: a Temporal value's prototype carries
632
+ * none of them. `to_date` is Ruby's own, for Date and DateTime
633
+ * (`date_to_date` and `datetime_to_date`,
634
+ * `vendor/ruby/v3.3.11/ext/date/date_core.c:10054,10058`). A package that
635
+ * reopens one of those classes, as ActiveSupport's `core_ext/date_time` does,
636
+ * assigns an entry, as it does on `STRING_METHOD_TABLE`. A JS `Date`, which
637
+ * spells a Ruby Time at the boundary and has no such tag, is keyed `"Date"`:
638
+ * the date package seats `Time#utc?`, `#getutc` and `#getlocal`
639
+ * (`vendor/ruby/v3.3.11/time.c:4340,4425,4374`) there and on
640
+ * `Temporal.Instant`. An instance of {@link rbCDate} (the date package's
641
+ * `Date` and its subclasses) is keyed `"rbCDate"`, for the private methods
642
+ * `Date` defines (`hour` and the rest, `date_core.c:9773-9777`): they answer
643
+ * `send` but not a JS `name in object`, and a subclass's own member, such as
644
+ * `DateTime#hour`, is found first.
645
+ *
646
+ * @noRailsEquivalent PERMANENT
647
+ */
648
+ export const TEMPORAL_METHOD_TABLE = {
649
+ "Temporal.PlainDate": { toDate: (self) => self },
650
+ "Temporal.PlainDateTime": { toDate: (self) => self.toPlainDate() },
651
+ "Temporal.ZonedDateTime": { toDate: (self) => self.toPlainDate() },
652
+ rbCDate: {},
653
+ };
654
+ function temporalMethod(obj, mid) {
655
+ if (obj instanceof rbCDate) {
656
+ const table = TEMPORAL_METHOD_TABLE.rbCDate;
657
+ return !(mid in obj) && Object.hasOwn(table, mid)
658
+ ? table[mid]
659
+ : undefined;
660
+ }
661
+ const table = obj == null
662
+ ? undefined
663
+ : TEMPORAL_METHOD_TABLE[temporalTag(obj) ?? (obj instanceof Date ? "Date" : "")];
664
+ return table !== undefined && Object.hasOwn(table, mid)
665
+ ? table[mid]
666
+ : undefined;
667
+ }
668
+ /**
669
+ * `basic_obj_respond_to` (`vendor/ruby/v3.3.11/vm_method.c:2864`) — the default
670
+ * `Object#respond_to?`, which answers whether the receiver's class defines the
671
+ * method. A JS object answers a name whether it carries a method or a
672
+ * property, so the prototype-chain lookup is the whole `method_boundp` here,
673
+ * and an own `undefined` value is its `2` (undefined method) case. An unbound
674
+ * name falls through to the receiver's `respond_to_missing?`
675
+ * (`basic_obj_respond_to_missing`, `vm_method.c:2850-2861`).
676
+ * Like `callable_method_entry` there, the entry is found by descriptor lookup,
677
+ * never by a property read a `methodMissingPrototype` `get` trap would answer.
678
+ * `isEmpty` is bound for the core receivers `ruby-empty.ts`'s `isEmpty` answers
679
+ * `empty?` for (`array.c:2686`, `hash.c:3023`, `string.c:2243`), whose JS
680
+ * values carry no such member. `isInclude` is bound for the same receivers and
681
+ * `Set`, which define `include?` (`array.c:8679`, `hash.c:7255`,
682
+ * `string.c:12215`, `lib/set.rb:393`), and `toSym` for every JS string
683
+ * (`string.c:12212`), which spells both a Ruby String and a Ruby Symbol
684
+ * (`":name"`); Symbol answers `to_sym` too (`symbol.rb:8`). `toAry` is bound for a JS array
685
+ * (`array.c:8619`), whose prototype carries no such member. `each` is bound
686
+ * for a JS array, a `Set`, and a `Map` or plain hash (`array.c:8642`,
687
+ * `lib/set.rb:499`, `hash.c:7219`), and `eachPair` for a `Map` or plain hash
688
+ * (`hash.c:7218`). `isInfinite` and
689
+ * `isFinite` are bound for a JS number and bigint, which spell Float
690
+ * (`numeric.c:6376-6377`) and Integer (`numeric.rb:39-48`). `toYaml` is bound for
691
+ * every receiver: Psych defines `to_yaml` on `Object` (`ext/psych/lib/psych/core_ext.rb:12-14`),
692
+ * and trails ports it as the free `toYaml` in `psych/core-ext.ts`. A Temporal seat answers for the methods
693
+ * {@link TEMPORAL_METHOD_TABLE} binds on it.
694
+ *
695
+ * A class receiver (a non-writable `prototype`, which a plain function, the
696
+ * JS spelling of a `Proc`, does not have) answers `Module#respond_to?`: its static data fields hold
697
+ * what Ruby keeps in class-level ivars, not methods, and the lookup stops
698
+ * short of `Function.prototype`, whose `call` / `apply` / `bind` no Ruby
699
+ * `Module` defines. A plain function's own `length` and `name` are its JS
700
+ * arity and function name, which no Ruby `Proc` defines.
701
+ *
702
+ * A writer `name=` is answered by a JS accessor's setter or by a `setName`
703
+ * method, the conventions table's two writer spellings and the entries
704
+ * {@link rbFSend} dispatches it to. An underscore-prefixed writer
705
+ * (`_reflections=`) is a `class_attribute` storage slot and has no `set*`
706
+ * spelling.
707
+ *
708
+ * `method_boundp` (`vm_method.c:1788-1818`) answers `0` for a PRIVATE entry,
709
+ * and under `BOUND_RESPONDS` a PROTECTED one, when `pub` is set. A JS entry
710
+ * carries no visibility, so there is no `pub` to pass (see CLAUDE.md, "Method
711
+ * visibility is compile-time only").
712
+ *
713
+ * @noRailsEquivalent PERMANENT — Ruby core `basic_obj_respond_to`
714
+ * (`vendor/ruby/v3.3.11/vm_method.c:2864`).
715
+ */
716
+ export function basicObjRespondTo(obj, mid) {
717
+ if (mid === "toYaml")
718
+ return true;
719
+ const bound = _methodBound(obj, mid);
720
+ if (bound !== null)
721
+ return bound;
722
+ const respondToMissing = _chainEntry(obj, "respondToMissing");
723
+ if (typeof respondToMissing !== "function")
724
+ return false;
725
+ const ret = respondToMissing.call(obj, mid);
726
+ return ret != null && ret !== false;
727
+ }
728
+ /** @perf 3.7x — PERMANENT */
729
+ function _methodBound(obj, mid) {
730
+ if (typeof obj !== "object" || obj === null)
731
+ return methodBoundp(obj, mid);
732
+ const proto = Object.getPrototypeOf(obj);
733
+ const attr = mid.endsWith("=") ? mid.slice(0, -1) : undefined;
734
+ const writer = writerSpelling(attr);
735
+ if (proto === null ||
736
+ Object.hasOwn(obj, mid) ||
737
+ Object.hasOwn(obj, Symbol.toStringTag) ||
738
+ Object.hasOwn(obj, Symbol.iterator) ||
739
+ (attr !== undefined && Object.hasOwn(obj, attr)) ||
740
+ (writer !== undefined && Object.hasOwn(obj, writer))) {
741
+ return methodBoundp(obj, mid);
742
+ }
743
+ let entries = _boundEntries.get(proto);
744
+ if (entries === undefined || entries.serial !== methodCacheSerial) {
745
+ entries = { serial: methodCacheSerial, bound: new Map() };
746
+ _boundEntries.set(proto, entries);
747
+ }
748
+ let bound = entries.bound.get(mid);
749
+ if (bound === undefined)
750
+ entries.bound.set(mid, (bound = methodBoundp(obj, mid)));
751
+ return bound;
752
+ }
753
+ /** @perf 3.7x — PERMANENT */
754
+ const _boundEntries = new WeakMap();
755
+ /**
756
+ * `method_boundp` (`vendor/ruby/v3.3.11/vm_method.c:1788-1818`): whether the
757
+ * receiver's method entry for `mid` is bound, unbound (`false`, an undef
758
+ * entry) or absent (`null`).
759
+ *
760
+ * @noRailsEquivalent PERMANENT — Ruby core `method_boundp`.
761
+ */
762
+ function methodBoundp(obj, mid) {
763
+ const core = obj === null || obj === undefined
764
+ ? false
765
+ : typeof obj !== "object"
766
+ ? typeof obj !== "function"
767
+ : Array.isArray(obj) ||
768
+ obj instanceof Map ||
769
+ obj instanceof Set ||
770
+ obj instanceof Uint8Array ||
771
+ obj instanceof Date ||
772
+ obj instanceof rbCDate ||
773
+ temporalTag(obj) !== null ||
774
+ isPlainHash(obj);
775
+ if (obj instanceof String &&
776
+ mid === "actsLikeString" &&
777
+ Object.hasOwn(STRING_METHOD_TABLE, mid)) {
778
+ return true;
779
+ }
780
+ if (core) {
781
+ if (typeof obj === "string" && (mid === "toStr" || mid === "toSym"))
782
+ return true;
783
+ if (Array.isArray(obj) && mid === "toAry")
784
+ return true;
785
+ if ((typeof obj === "number" || typeof obj === "bigint") &&
786
+ (mid === "isInfinite" || mid === "isFinite")) {
787
+ return true;
788
+ }
789
+ if (typeof obj === "string" && Object.hasOwn(STRING_METHOD_TABLE, mid))
790
+ return true;
791
+ if (obj instanceof Uint8Array && Object.hasOwn(BINARY_METHOD_TABLE, mid))
792
+ return true;
793
+ if (Array.isArray(obj) && Object.hasOwn(ARRAY_METHOD_TABLE, mid))
794
+ return true;
795
+ if (Array.isArray(obj) && Object.hasOwn(enumerableModule(), mid))
796
+ return true;
797
+ if (temporalMethod(obj, mid) !== undefined)
798
+ return true;
799
+ if (enumerableMethod(obj, mid) !== undefined)
800
+ return true;
801
+ if (mid === "each" &&
802
+ (Array.isArray(obj) || obj instanceof Set || obj instanceof Map || isPlainHash(obj))) {
803
+ return true;
804
+ }
805
+ if (mid === "eachPair" && (obj instanceof Map || isPlainHash(obj)))
806
+ return true;
807
+ if (mid === "toHash" && (obj instanceof Map || isPlainHash(obj)))
808
+ return true;
809
+ if ((mid === "store" ||
810
+ mid === "set" ||
811
+ mid === "fetch" ||
812
+ mid === "delete" ||
813
+ mid === "clear") &&
814
+ (obj instanceof Map || isPlainHash(obj))) {
815
+ return true;
816
+ }
817
+ if (mid === "get" &&
818
+ (typeof obj === "string" || Array.isArray(obj) || obj instanceof Map || isPlainHash(obj))) {
819
+ return true;
820
+ }
821
+ if ((mid === "isEmpty" || mid === "isInclude") &&
822
+ (typeof obj === "string" ||
823
+ Array.isArray(obj) ||
824
+ obj instanceof Set ||
825
+ obj instanceof Map ||
826
+ isPlainHash(obj))) {
827
+ return true;
828
+ }
829
+ }
830
+ else if (enumerableMethod(obj, mid) !== undefined) {
831
+ return true;
832
+ }
833
+ const klass = typeof obj === "function" &&
834
+ Object.getOwnPropertyDescriptor(obj, "prototype")?.writable === false;
835
+ if (typeof obj === "function" && !klass && (mid === "length" || mid === "name"))
836
+ return false;
837
+ const attr = mid.endsWith("=") ? mid.slice(0, -1) : undefined;
838
+ const writer = writerSpelling(attr);
839
+ for (let o = Object(obj); o && !(klass && o === Function.prototype); o = Object.getPrototypeOf(o)) {
840
+ if (o === Uint8Array.prototype || o === Object.getPrototypeOf(Uint8Array.prototype))
841
+ continue;
842
+ const entry = Object.hasOwn(o, mid) ? Object.getOwnPropertyDescriptor(o, mid) : undefined;
843
+ if (UNDEF_HALVES.has(entry?.get))
844
+ return false;
845
+ if (entry && !isAbsentHalf(entry.get)) {
846
+ if (!("value" in entry))
847
+ return true;
848
+ return klass ? typeof entry.value === "function" : entry.value !== undefined;
849
+ }
850
+ const setter = attr === undefined ? undefined : Object.getOwnPropertyDescriptor(o, attr)?.set;
851
+ if (setter !== undefined && !isAbsentHalf(setter))
852
+ return true;
853
+ if (writer !== undefined &&
854
+ typeof Object.getOwnPropertyDescriptor(o, writer)?.value === "function") {
855
+ return true;
856
+ }
857
+ }
858
+ if (klass && Object.hasOwn(CLASS_METHOD_TABLE, mid))
859
+ return true;
860
+ for (let o = classSeatMethodTable(obj); o && o !== Object.prototype; o = Object.getPrototypeOf(o)) {
861
+ if (typeof Object.getOwnPropertyDescriptor(o, mid)?.value === "function")
862
+ return true;
863
+ }
864
+ return reopenedSeatMethod(obj, mid) !== undefined ? true : null;
865
+ }
866
+ /** @perf 3.7x — PERMANENT */
867
+ function _chainEntry(obj, name) {
868
+ const proto = typeof obj === "object" && obj !== null && !Object.hasOwn(obj, name)
869
+ ? Object.getPrototypeOf(obj)
870
+ : null;
871
+ let entries = proto === null ? undefined : _chainEntries.get(proto);
872
+ if (proto !== null && (entries === undefined || entries.serial !== methodCacheSerial)) {
873
+ entries = { serial: methodCacheSerial, values: new Map() };
874
+ _chainEntries.set(proto, entries);
875
+ }
876
+ if (entries?.values.has(name))
877
+ return entries.values.get(name);
878
+ let value;
879
+ for (let o = Object(obj); o; o = Object.getPrototypeOf(o)) {
880
+ if (Object.hasOwn(o, name)) {
881
+ value = Object.getOwnPropertyDescriptor(o, name)?.value;
882
+ break;
883
+ }
884
+ }
885
+ entries?.values.set(name, value);
886
+ return value;
887
+ }
888
+ /** @perf 3.7x — PERMANENT */
889
+ const _chainEntries = new WeakMap();
890
+ /**
891
+ * `Object#respond_to_missing?` (`obj_respond_to_missing`,
892
+ * `vendor/ruby/v3.3.11/vm_method.c:3009`), the default a class's own
893
+ * `respond_to_missing?` reaches through `super`: it answers false for every
894
+ * name.
895
+ *
896
+ * @noRailsEquivalent PERMANENT — Ruby core `obj_respond_to_missing`
897
+ * (`vendor/ruby/v3.3.11/vm_method.c:3009`).
898
+ */
899
+ export function objRespondToMissing(_obj, _mid, _priv) {
900
+ return false;
901
+ }
902
+ const writerSpellings = new Map();
903
+ /**
904
+ * The `setName` method that answers a Ruby writer `name=` (`rb_id_attrset`,
905
+ * `vendor/ruby/v3.3.11/vm_method.c:1895`) when it is not a JS accessor's
906
+ * setter, as {@link rbFSend} and {@link rbObjRespondTo} look it up.
907
+ *
908
+ * @noRailsEquivalent PERMANENT
909
+ */
910
+ export function writerSpelling(attr) {
911
+ if (attr === undefined || attr.startsWith("_"))
912
+ return undefined;
913
+ let writer = writerSpellings.get(attr);
914
+ if (writer === undefined)
915
+ writerSpellings.set(attr, (writer = camelized(`set_${attr}`)));
916
+ return writer;
917
+ }
918
+ /**
919
+ * The `snake_case` to `camelCase` spelling of a Ruby ID `rb_f_send`
920
+ * (`vendor/ruby/v3.3.11/vm_eval.c:1330`) would dispatch.
921
+ *
922
+ * @noRailsEquivalent PERMANENT
923
+ */
924
+ export function camelized(name) {
925
+ return name.replace(/_([a-zA-Z\d])/g, (_, c) => c.toUpperCase());
926
+ }
927
+ /**
928
+ * Thor's `name.tr("-", "_")` reversed (`rb_str_tr`,
929
+ * `vendor/ruby/v3.3.11/string.c:8226`) for a CLI name: RFC 0171 decision 6.
930
+ *
931
+ * @noRailsEquivalent PERMANENT
932
+ */
933
+ export function kebabCase(name) {
934
+ if (name.startsWith("_"))
935
+ return name;
936
+ return name
937
+ .replace(/([a-z\d])([A-Z])/g, "$1-$2")
938
+ .replace(/([A-Z])([A-Z][a-z])/g, "$1-$2")
939
+ .replace(/[-_]+/g, "-")
940
+ .toLowerCase();
941
+ }
942
+ function checkDefinition(mod, mid, inherit = true) {
943
+ const attr = mid.endsWith("=") ? mid.slice(0, -1) : undefined;
944
+ const writer = writerSpelling(attr);
945
+ for (let o = mod.prototype; o && o !== Object.prototype; o = inherit ? Object.getPrototypeOf(o) : null) {
946
+ const me = Object.getOwnPropertyDescriptor(o, mid);
947
+ if (UNDEF_HALVES.has(me?.get))
948
+ return false;
949
+ if (me && !isAbsentHalf(me.get))
950
+ return typeof me.value === "function" || me.get !== undefined;
951
+ const setter = attr === undefined ? undefined : Object.getOwnPropertyDescriptor(o, attr)?.set;
952
+ if (setter !== undefined && !isAbsentHalf(setter))
953
+ return true;
954
+ if (writer !== undefined &&
955
+ typeof Object.getOwnPropertyDescriptor(o, writer)?.value === "function") {
956
+ return true;
957
+ }
958
+ }
959
+ return false;
960
+ }
961
+ const moduleIncludesKey = Symbol.for("@blazetrails/ruby-compat:moduleIncludes");
962
+ /**
963
+ * `Module#method_defined?` (`rb_mod_method_defined`,
964
+ * `vendor/ruby/v3.3.11/vm_method.c:2055`). A JS entry carries no visibility, so
965
+ * every defined entry answers. A writer `name=` is
966
+ * answered by a JS accessor's setter or a `setName` method, the entries
967
+ * {@link rbFSend} dispatches to. A false `inherit` answers for `mod`'s
968
+ * own method table only (`check_definition_visibility`, `vm_method.c:2000-2013`).
969
+ * A `Module` instance keeps its method table on a private carrier and answers
970
+ * through its own `isMethodDefined`, for that table only whatever `inherit` is:
971
+ * a ruby-compat `Module` copies an included module's methods into its includer
972
+ * and records no ancestor to walk. A plain-object module answers for its own
973
+ * enumerable members, its instance methods, and with `inherit` for the
974
+ * modules it recorded including.
975
+ *
976
+ * @noRailsEquivalent PERMANENT
977
+ */
978
+ export function rbModMethodDefined(mod, mid, inherit = true) {
979
+ if ("prototype" in mod)
980
+ return checkDefinition(mod, mid, inherit);
981
+ if ("isMethodDefined" in mod)
982
+ return mod.isMethodDefined(mid);
983
+ const me = Object.getOwnPropertyDescriptor(mod, mid);
984
+ if (me?.enumerable)
985
+ return typeof me.value === "function" || me.get !== undefined;
986
+ if (!inherit)
987
+ return false;
988
+ const included = mod[moduleIncludesKey];
989
+ return [...(included ?? [])].some((m) => rbModMethodDefined(m, mid));
990
+ }
991
+ /**
992
+ * Seats on `target`, in `descriptors`, the `key` method `method` is about to
993
+ * shadow, for {@link rbCallSuper}. A function keeps the key it was first
994
+ * installed under, as MRI's `super` searches by the method's `original_id`
995
+ * (`vendor/ruby/v3.3.11/vm_insnhelper.c:4680`, `vm_search_super_method`).
996
+ * An accessor's `get` and `set` are seated one `half` at a time, as Ruby's
997
+ * `name` and `name=` are two methods.
998
+ *
999
+ * @noRailsEquivalent PERMANENT
1000
+ */
1001
+ export function rbSeatSuper(target, key, method, descriptors, half = "value") {
1002
+ if (typeof method !== "function")
1003
+ return;
1004
+ let shadowed;
1005
+ for (let link = target; link; link = Object.getPrototypeOf(link)) {
1006
+ const desc = Object.getOwnPropertyDescriptor(link, key);
1007
+ if (desc && (half === "value" || desc[half] !== undefined)) {
1008
+ shadowed = desc[half];
1009
+ break;
1010
+ }
1011
+ }
1012
+ if (typeof shadowed !== "function" || shadowed === method)
1013
+ return;
1014
+ const entry = superSlotFor(method, key);
1015
+ if (Object.hasOwn(descriptors, entry.slot))
1016
+ return;
1017
+ descriptors[entry.slot] = { value: shadowed, configurable: true };
1018
+ entry.seats = (entry.seats ?? 0) + 1;
1019
+ }
1020
+ /**
1021
+ * `Module#define_method` on a class receiver (`rb_mod_define_method`,
1022
+ * `vendor/ruby/v3.3.11/proc.c:2325`): binds `body` as `mod`'s instance method
1023
+ * `mid`. `body` is the block, or the method `define_method(symbol, method)`
1024
+ * takes, whose JS carrier is a property descriptor (see
1025
+ * `Module#instanceMethod`), so a zero-argument reader can be defined as the
1026
+ * accessor it ports to. A JS class has no metaclass apart from its own
1027
+ * statics (CLAUDE.md, "`singleton_class` is a per-object subclass"), so a
1028
+ * class's `singleton_class.define_method` passes `{ prototype: klass }`.
1029
+ *
1030
+ * It replaces `mod`'s own `mid`, and its `super` reaches the next `mid` in
1031
+ * the ancestry ({@link rbCallSuper}).
1032
+ *
1033
+ * @noRailsEquivalent PERMANENT
1034
+ */
1035
+ export function rbModDefineMethod(mod, mid, body) {
1036
+ const descriptors = {
1037
+ [mid]: typeof body === "function"
1038
+ ? { value: body, writable: true, configurable: true }
1039
+ : { configurable: true, ...body },
1040
+ };
1041
+ rbSeatSuper(Object.getPrototypeOf(mod.prototype), mid, typeof body === "function" ? body : body.value, descriptors);
1042
+ Object.defineProperties(mod.prototype, descriptors);
1043
+ rbClearMethodCache();
1044
+ return mid;
1045
+ }
1046
+ const ABSENT_HALVES = new WeakSet();
1047
+ const UNDEF_HALVES = new WeakSet();
1048
+ /**
1049
+ * Whether `half` is the getter or setter {@link defineAccessorHalf} seats for
1050
+ * a method the table does not define. Ruby keeps `x` and `x=` as two method
1051
+ * entries (`rb_add_method`, `vendor/ruby/v3.3.11/vm_method.c:1146`), so a table
1052
+ * with only one of them leaves the other to the next table in the ancestry;
1053
+ * every method lookup reads such a half as no entry and keeps walking.
1054
+ *
1055
+ * @noRailsEquivalent PERMANENT
1056
+ */
1057
+ export function isAbsentHalf(half) {
1058
+ return typeof half === "function" && ABSENT_HALVES.has(half);
1059
+ }
1060
+ function nextHalf(start, id, write) {
1061
+ for (let o = start; o; o = Object.getPrototypeOf(o)) {
1062
+ const entry = Object.getOwnPropertyDescriptor(o, id);
1063
+ if (entry === undefined)
1064
+ continue;
1065
+ if ("value" in entry)
1066
+ return entry;
1067
+ const half = write ? entry.set : entry.get;
1068
+ if (half !== undefined && !isAbsentHalf(half))
1069
+ return entry;
1070
+ }
1071
+ return undefined;
1072
+ }
1073
+ function absentHalf(id, write) {
1074
+ const owner = (recv) => {
1075
+ for (let o = recv; o; o = Object.getPrototypeOf(o)) {
1076
+ const entry = Object.getOwnPropertyDescriptor(o, id);
1077
+ if ((write ? entry?.set : entry?.get) === half)
1078
+ return o;
1079
+ }
1080
+ return null;
1081
+ };
1082
+ const half = write
1083
+ ? function (value) {
1084
+ const from = owner(this);
1085
+ const entry = nextHalf(from && Object.getPrototypeOf(from), id, true);
1086
+ if (!entry?.set) {
1087
+ throw new globalThis.TypeError(`Cannot set property ${id} of ${String(this)} which has only a getter`);
1088
+ }
1089
+ entry.set.call(this, value);
1090
+ }
1091
+ : function () {
1092
+ const from = owner(this);
1093
+ const entry = nextHalf(from && Object.getPrototypeOf(from), id, false);
1094
+ if (entry === undefined)
1095
+ return undefined;
1096
+ return "value" in entry ? entry.value : entry.get.call(this);
1097
+ };
1098
+ ABSENT_HALVES.add(half);
1099
+ return half;
1100
+ }
1101
+ /**
1102
+ * Seats one half of the accessor `name` on `target`, the JS spelling of adding
1103
+ * the method entry `name` or `name=` to a method table (`rb_add_method`,
1104
+ * `vendor/ruby/v3.3.11/vm_method.c:1146`). A JS accessor is one descriptor, so
1105
+ * the half not given keeps `target`'s own, and where `target` has none it
1106
+ * defers to the next table up the prototype chain, as Ruby's method search
1107
+ * does for an entry the table lacks. `enumerable` is set on a plain-object
1108
+ * module, whose enumerable members are the instance methods `include()` copies
1109
+ * (CLAUDE.md, "A Ruby module is a JS object or a JS class").
1110
+ *
1111
+ * @noRailsEquivalent PERMANENT
1112
+ */
1113
+ export function defineAccessorHalf(target, name, half) {
1114
+ const existing = Object.getOwnPropertyDescriptor(target, name);
1115
+ Object.defineProperty(target, name, {
1116
+ configurable: true,
1117
+ enumerable: existing?.enumerable ?? half.enumerable ?? false,
1118
+ get: half.get ?? existing?.get ?? absentHalf(name, false),
1119
+ set: half.set ?? existing?.set ?? absentHalf(name, true),
1120
+ });
1121
+ rbClearMethodCache();
1122
+ }
1123
+ /**
1124
+ * `Module#undef_method` (`rb_mod_undef_method`,
1125
+ * `vendor/ruby/v3.3.11/vm_method.c:1973`). An undefined name raises `NameError`.
1126
+ * `name` and `name=` are one JS descriptor, so `name=` is undefined by a `"name="`
1127
+ * entry, which every lookup reads first, and `name` by a reader half that stops
1128
+ * the search and keeps the writer.
1129
+ *
1130
+ * @noRailsEquivalent PERMANENT
1131
+ */
1132
+ export function rbModUndefMethod(klass, ...names) {
1133
+ const proto = klass.prototype;
1134
+ for (const name of names) {
1135
+ if (!checkDefinition(klass, name)) {
1136
+ throw new NameError(`undefined method '${name}' for class '${rbModName(klass)}'`, name);
1137
+ }
1138
+ UNDEF_METHOD_TABLES.add(proto);
1139
+ if (name.endsWith("=")) {
1140
+ Object.defineProperty(proto, name, { value: undefined, writable: true, configurable: true });
1141
+ continue;
1142
+ }
1143
+ let set;
1144
+ for (let o = proto; o; o = Object.getPrototypeOf(o)) {
1145
+ const half = Object.getOwnPropertyDescriptor(o, name)?.set;
1146
+ if (half !== undefined && !isAbsentHalf(half)) {
1147
+ set = half;
1148
+ break;
1149
+ }
1150
+ }
1151
+ if (set !== undefined) {
1152
+ const get = () => undefined;
1153
+ UNDEF_HALVES.add(get);
1154
+ Object.defineProperty(proto, name, { configurable: true, get, set });
1155
+ }
1156
+ else {
1157
+ Object.defineProperty(proto, name, { value: undefined, writable: true, configurable: true });
1158
+ }
1159
+ }
1160
+ rbClearMethodCache();
1161
+ return klass;
1162
+ }
1163
+ /**
1164
+ * `rb_attr` (`vendor/ruby/v3.3.11/vm_method.c:1863`). The half not being
1165
+ * defined is left to the next table ({@link defineAccessorHalf}); the ivar
1166
+ * lives in the `_`-prefixed field ({@link rbDeclareIvar}).
1167
+ */
1168
+ function rbAttr(klass, id, read, write) {
1169
+ const attriv = `_${id}`;
1170
+ rbDeclareIvar(klass, `@${id.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)}`, attriv);
1171
+ defineAccessorHalf(klass.prototype, id, {
1172
+ enumerable: klass.prototype.constructor?.prototype !== klass.prototype,
1173
+ ...(read
1174
+ ? {
1175
+ get() {
1176
+ return this[attriv] ?? null;
1177
+ },
1178
+ }
1179
+ : {}),
1180
+ ...(write
1181
+ ? {
1182
+ set(val) {
1183
+ this[attriv] = val;
1184
+ },
1185
+ }
1186
+ : {}),
1187
+ });
1188
+ }
1189
+ /**
1190
+ * `Module#attr_reader` (`rb_mod_attr_reader`, `vendor/ruby/v3.3.11/object.c:2279`).
1191
+ *
1192
+ * @noRailsEquivalent PERMANENT
1193
+ */
1194
+ export function rbModAttrReader(klass, ...argv) {
1195
+ for (const id of argv) {
1196
+ rbAttr(klass, id, true, false);
1197
+ }
1198
+ }
1199
+ /**
1200
+ * `Module#attr_writer` (`rb_mod_attr_writer`, `vendor/ruby/v3.3.11/object.c:2335`).
1201
+ *
1202
+ * @noRailsEquivalent PERMANENT
1203
+ */
1204
+ export function rbModAttrWriter(klass, ...argv) {
1205
+ for (const id of argv) {
1206
+ rbAttr(klass, id, false, true);
1207
+ }
1208
+ }
1209
+ /**
1210
+ * Ruby's `obj.to_sym` send: `String#to_sym` (`rb_str_intern`,
1211
+ * `vendor/ruby/v3.3.11/symbol.c:862`, bound at `vendor/ruby/v3.3.11/string.c:12212`)
1212
+ * and `Symbol#to_sym` (`vendor/ruby/v3.3.11/symbol.rb:8`). A JS string spells
1213
+ * both receivers and answers the Symbol's colon spelling (`":name"`); no other
1214
+ * core receiver defines `to_sym`, so the send dispatches to a receiver's own
1215
+ * `toSym` and otherwise raises `NoMethodError`. It is
1216
+ * the send, where {@link stringToSym} is `rb_str_intern` on a known String,
1217
+ * as `toI` is to `rbStrToI`.
1218
+ *
1219
+ * @noRailsEquivalent PERMANENT
1220
+ */
1221
+ export function toSym(obj) {
1222
+ if (typeof obj === "string")
1223
+ return stringToSym(obj);
1224
+ if (obj == null)
1225
+ throw new NoMethodError("undefined method 'to_sym' for nil", "to_sym");
1226
+ const own = obj.toSym;
1227
+ if (typeof own === "function")
1228
+ return own.call(obj);
1229
+ throw new NoMethodError(`undefined method 'to_sym' for an instance of ${rbObjClassname(obj)}`, "to_sym", [], false, { receiver: obj });
1230
+ }
1231
+ /** @noRailsEquivalent PERMANENT — Ruby core `rb_str_to_s` (`vendor/ruby/v3.3.11/string.c:6648`). */
1232
+ export function toS(obj) {
1233
+ if (isSymbol(obj))
1234
+ return symbolToS(obj);
1235
+ return rbObjAsString(obj);
1236
+ }
1237
+ /**
1238
+ * `Kernel#send` (`rb_f_send`, `vendor/ruby/v3.3.11/vm_eval.c:1330`): calls the nearest
1239
+ * entry for `mid` whatever its visibility. A zero-argument reader ported as a
1240
+ * JS accessor or a field answers through its getter or its value, as the Ruby
1241
+ * reader it ports would. `infinite?` is dispatched for a JS number and bigint,
1242
+ * whose prototypes carry no such member: `Float#infinite?`
1243
+ * (`rb_flo_is_infinite_p`, `vendor/ruby/v3.3.11/numeric.c:1992`) answers `1` /
1244
+ * `-1` for an infinity and `nil` otherwise, as `Integer#infinite?`
1245
+ * (`vendor/ruby/v3.3.11/numeric.rb:48`) always does. `odd?` and `even?` are
1246
+ * dispatched for an Integer alone (`rb_int_odd_p` / `rb_int_even_p`,
1247
+ * `vendor/ruby/v3.3.11/numeric.c:3564,3588`): a Float defines neither. A
1248
+ * predicate sent by its Ruby name (`:odd?`, the value Rails' `NUMBER_CHECKS`
1249
+ * holds) reaches those two arms and `OBJECT_METHOD_TABLE` by its `is`-prefixed
1250
+ * TS spelling; every other lookup, `method_missing` included, sees the name as
1251
+ * sent. An operator is sent by its
1252
+ * Ruby name (`">"`), which has no TS method spelling. `==` is {@link rbEqual},
1253
+ * which sends the receiver's own `==`, and `!=` its negation
1254
+ * (`rb_obj_not_equal`, `vendor/ruby/v3.3.11/object.c:248`). The four ordering
1255
+ * operators answer for the receivers that define them in Ruby: between two
1256
+ * numbers they are `Integer`'s and `Float`'s own (`rb_int_gt`,
1257
+ * `vendor/ruby/v3.3.11/numeric.c:4743`, and `rb_float_gt`, `:1753`), false for
1258
+ * a NaN operand and never raising; a number against
1259
+ * anything else, and any other `Comparable` receiver (a String, a Time or
1260
+ * Date, or an object defining `<=>`), go through `cmpint`
1261
+ * (`vendor/ruby/v3.3.11/compar.c:105-147`) and raise `ArgumentError` for a pair
1262
+ * `<=>` cannot place. Any other receiver, `nil` included, has no such method
1263
+ * and raises `NoMethodError`. `include?` is dispatched for the core receivers
1264
+ * {@link basicObjRespondTo} binds it for, when no entry of their own answers
1265
+ * (`vendor/ruby/v3.3.11/string.c:12215`, `array.c:8679`, `hash.c:7255`,
1266
+ * `lib/set.rb:393`). A Set or Hash looks a member up by `eql?`, so an object a
1267
+ * JS `has` misses by identity is compared with `rb_eql` against each key.
1268
+ *
1269
+ * @noRailsEquivalent PERMANENT — Ruby core `Kernel#send` (`vendor/ruby/v3.3.11/vm_eval.c:1330`).
1270
+ */
1271
+ export function rbFSend(recv, mid, ...args) {
1272
+ if (args.length === 1 && typeof mid === "string" && typeof recv === "object" && recv !== null) {
1273
+ const write = _writerFor(recv, mid);
1274
+ if (write !== null)
1275
+ return write.call(recv, args[0]);
1276
+ }
1277
+ if (typeof mid === "string" && typeof recv === "object" && recv !== null) {
1278
+ const method = _methodFor(recv, mid);
1279
+ if (method !== null)
1280
+ return method.apply(recv, args);
1281
+ }
1282
+ return sendInternal(args.length, [mid, ...args], recv);
1283
+ }
1284
+ /**
1285
+ * `conversion_mismatch` (`vendor/ruby/v3.3.11/object.c:3132`): the `TypeError`
1286
+ * a conversion method raises for answering the wrong type.
1287
+ *
1288
+ * @noRailsEquivalent PERMANENT
1289
+ */
1290
+ export function conversionMismatch(val, tname, method, result) {
1291
+ const cname = rbObjClassname(val);
1292
+ throw new TypeError(`can't convert ${cname} to ${tname} (${cname}#${method} gives ${rbObjClassname(result)})`);
1293
+ }
1294
+ const RELOPS = new Map([
1295
+ [">", (c) => c > 0],
1296
+ [">=", (c) => c >= 0],
1297
+ ["<", (c) => c < 0],
1298
+ ["<=", (c) => c <= 0],
1299
+ ]);
1300
+ function isNumeric(value) {
1301
+ return typeof value === "number" || typeof value === "bigint";
1302
+ }
1303
+ function isComparable(recv) {
1304
+ if (typeof recv === "string")
1305
+ return true;
1306
+ if (typeof recv !== "object" || recv === null)
1307
+ return false;
1308
+ if (recv instanceof Date || recv instanceof Number || temporalTag(recv) !== null)
1309
+ return true;
1310
+ const { compareTo, cmp } = recv;
1311
+ return typeof compareTo === "function" || typeof cmp === "function";
1312
+ }
1313
+ /**
1314
+ * The method tables `Module#undef_method` writes its entries into: a data
1315
+ * property holding `undefined` on one of them is `VM_METHOD_TYPE_UNDEF`
1316
+ * (`vendor/ruby/v3.3.11/vm_method.c:1973` `rb_mod_undef_method`), where the
1317
+ * lookup stops and `send` goes to `method_missing`.
1318
+ *
1319
+ * @noRailsEquivalent PERMANENT
1320
+ */
1321
+ export const UNDEF_METHOD_TABLES = new WeakSet();
1322
+ function sendInternal(argc, argv, recv) {
1323
+ const [vid, ...args] = argv;
1324
+ const name = rbCheckStringType(vid);
1325
+ if (name === null)
1326
+ throw new TypeError(`${rbInspect(vid)} is not a symbol nor a string`);
1327
+ const mid = isSymbol(name) ? symbolToS(name) : name;
1328
+ const predicate = mid.endsWith("?") ? camelized(`is_${mid.slice(0, -1)}`) : mid;
1329
+ if (argc === 1) {
1330
+ const other = args[0];
1331
+ if (mid === "==")
1332
+ return rbEqual(recv, other);
1333
+ if (mid === "!=")
1334
+ return !rbEqual(recv, other);
1335
+ if (mid === "+" && (isNumeric(recv) || typeof recv === "string" || Array.isArray(recv))) {
1336
+ return rbPlus(recv, other);
1337
+ }
1338
+ const relop = RELOPS.get(mid);
1339
+ if (relop !== undefined && isNumeric(recv) && isNumeric(other)) {
1340
+ return relop(recv < other ? -1 : recv > other ? 1 : recv == other ? 0 : NaN);
1341
+ }
1342
+ if (relop !== undefined && (isNumeric(recv) || isComparable(recv))) {
1343
+ return relop(rbCmpint(cmp(recv, other), recv, other));
1344
+ }
1345
+ }
1346
+ if ((typeof recv === "number" || typeof recv === "bigint") && mid === "isInfinite") {
1347
+ return recv === Infinity ? 1 : recv === -Infinity ? -1 : null;
1348
+ }
1349
+ if ((typeof recv === "number" || typeof recv === "bigint") && mid === "isFinite") {
1350
+ return typeof recv === "bigint" || Number.isFinite(recv);
1351
+ }
1352
+ if ((typeof recv === "bigint" || Number.isInteger(recv)) &&
1353
+ (predicate === "isOdd" || predicate === "isEven")) {
1354
+ return (BigInt(recv) % 2n !== 0n) === (predicate === "isOdd");
1355
+ }
1356
+ const bound = temporalMethod(recv, mid);
1357
+ if (bound !== undefined)
1358
+ return bound(recv, ...args);
1359
+ if (typeof recv === "string" && Object.hasOwn(STRING_METHOD_TABLE, mid)) {
1360
+ return rbStrSend(recv, mid, ...args)[0];
1361
+ }
1362
+ if (recv instanceof String &&
1363
+ mid === "actsLikeString" &&
1364
+ Object.hasOwn(STRING_METHOD_TABLE, mid)) {
1365
+ return rbStrSend(recv.valueOf(), mid, ...args)[0];
1366
+ }
1367
+ if (recv instanceof Uint8Array && Object.hasOwn(BINARY_METHOD_TABLE, mid)) {
1368
+ return rbStrSend(recv, mid, ...args)[0];
1369
+ }
1370
+ if (mid === "call" && rbObjIsProc(recv))
1371
+ return rbProcCall(recv, ...args);
1372
+ const obj = Object(recv);
1373
+ const attr = mid.endsWith("=") ? mid.slice(0, -1) : undefined;
1374
+ const writer = writerSpelling(attr);
1375
+ for (let o = obj; o; o = Object.getPrototypeOf(o)) {
1376
+ const desc = Object.getOwnPropertyDescriptor(o, mid);
1377
+ if (typeof desc?.value === "function")
1378
+ return desc.value.apply(recv, args);
1379
+ if (UNDEF_METHOD_TABLES.has(o) && desc && "value" in desc && desc.value === undefined)
1380
+ break;
1381
+ if (UNDEF_HALVES.has(desc?.get))
1382
+ break;
1383
+ if (desc && argc === 0 && !isAbsentHalf(desc.get)) {
1384
+ return desc.get ? desc.get.call(recv) : desc.value;
1385
+ }
1386
+ if (desc?.get && !isAbsentHalf(desc.get))
1387
+ rbErrorArity(argc, 0, 0);
1388
+ const setter = attr === undefined ? undefined : Object.getOwnPropertyDescriptor(o, attr)?.set;
1389
+ if (setter && !isAbsentHalf(setter))
1390
+ return setter.call(recv, args[0]);
1391
+ const set = writer === undefined ? undefined : Object.getOwnPropertyDescriptor(o, writer);
1392
+ if (typeof set?.value === "function")
1393
+ return set.value.apply(recv, args);
1394
+ }
1395
+ for (let o = classSeatMethodTable(recv); o && o !== Object.prototype; o = Object.getPrototypeOf(o)) {
1396
+ const desc = Object.getOwnPropertyDescriptor(o, mid);
1397
+ if (typeof desc?.value === "function")
1398
+ return desc.value.apply(recv, args);
1399
+ }
1400
+ if (mid === "isInclude") {
1401
+ if (typeof recv === "string")
1402
+ return recv.includes(stringValue(args[0]));
1403
+ if (Array.isArray(recv))
1404
+ return aryIncludes(recv, args[0]);
1405
+ if (recv instanceof Set || recv instanceof Map) {
1406
+ if (recv.has(args[0]) || args[0] === null || typeof args[0] !== "object") {
1407
+ return recv.has(args[0]);
1408
+ }
1409
+ return [...recv.keys()].some((key) => rbEql(key, args[0]));
1410
+ }
1411
+ if (isPlainHash(recv))
1412
+ return hasKey(recv, args[0]);
1413
+ if (recv == null)
1414
+ throw new NoMethodError("undefined method 'include?' for nil", "include?");
1415
+ }
1416
+ if (mid === "each" &&
1417
+ args[0] == null &&
1418
+ (Array.isArray(recv) || recv instanceof Set || recv instanceof Map || isPlainHash(recv))) {
1419
+ return toEnum(recv, "each");
1420
+ }
1421
+ if (mid === "each" && typeof args[0] === "function") {
1422
+ const block = args[0];
1423
+ if (Array.isArray(recv) || recv instanceof Set || recv instanceof Map || isPlainHash(recv)) {
1424
+ return aryEach(recv, block);
1425
+ }
1426
+ }
1427
+ if (mid === "toHash" && (recv instanceof Map || isPlainHash(recv)))
1428
+ return recv;
1429
+ if (recv instanceof Map || isPlainHash(recv)) {
1430
+ const hash = recv;
1431
+ if (mid === "get")
1432
+ return hashAref(hash, args[0]);
1433
+ if (mid === "store" || mid === "set")
1434
+ return hashAset(hash, args[0], args[1]);
1435
+ if (mid === "fetch")
1436
+ return fetch(hash, ...args);
1437
+ if (mid === "delete")
1438
+ return hashDelete(hash, ...args);
1439
+ if (mid === "clear")
1440
+ return hashClear(hash);
1441
+ }
1442
+ if (Array.isArray(recv) && Object.hasOwn(ARRAY_METHOD_TABLE, mid)) {
1443
+ return ARRAY_METHOD_TABLE[mid](recv, ...args);
1444
+ }
1445
+ if (Array.isArray(recv) && Object.hasOwn(enumerableModule(), mid)) {
1446
+ const each = (block) => recv.forEach((i) => block(i));
1447
+ return enumerableModule()[mid].call({ each }, ...args);
1448
+ }
1449
+ const enumerable = enumerableMethod(recv, mid);
1450
+ if (enumerable !== undefined)
1451
+ return enumerable(recv, ...args);
1452
+ if (Object.hasOwn(OBJECT_METHOD_TABLE, predicate)) {
1453
+ return OBJECT_METHOD_TABLE[predicate](recv, ...args);
1454
+ }
1455
+ const seated = reopenedSeatMethod(recv, mid);
1456
+ if (seated !== undefined)
1457
+ return seated.apply(recv, args);
1458
+ if (typeof obj.methodMissing === "function") {
1459
+ return obj.methodMissing.call(recv, mid, ...args);
1460
+ }
1461
+ const d = recv == null
1462
+ ? "nil"
1463
+ : recv === true
1464
+ ? "true"
1465
+ : recv === false
1466
+ ? "false"
1467
+ : `an instance of ${rbObjClassname(recv)}`;
1468
+ throw new NoMethodError(`undefined method '${mid}' for ${d}`, mid, args, false, {
1469
+ receiver: recv,
1470
+ });
1471
+ }
1472
+ /** @perf 100ns — PERMANENT */
1473
+ function _writerFor(recv, mid) {
1474
+ let entry = _writerEntries.get(mid);
1475
+ if (entry === undefined) {
1476
+ const n = mid.length;
1477
+ const attr = mid.slice(0, -1);
1478
+ entry =
1479
+ n < 2 || mid.charCodeAt(n - 1) !== 61 || !/\w/.test(mid[n - 2])
1480
+ ? null
1481
+ : { mid, attr, writer: writerSpelling(attr), proto: null, serial: -1, write: null };
1482
+ _writerEntries.set(mid, entry);
1483
+ }
1484
+ if (entry === null)
1485
+ return null;
1486
+ const proto = Object.getPrototypeOf(recv);
1487
+ if (proto === null)
1488
+ return null;
1489
+ if (entry.proto !== proto || entry.serial !== methodCacheSerial) {
1490
+ entry.proto = proto;
1491
+ entry.serial = methodCacheSerial;
1492
+ entry.write = null;
1493
+ if (!(proto instanceof Date || proto === Date.prototype || temporalTag(proto) !== null)) {
1494
+ for (let o = proto; o; o = Object.getPrototypeOf(o)) {
1495
+ const desc = Object.getOwnPropertyDescriptor(o, entry.mid);
1496
+ if (typeof desc?.value === "function")
1497
+ entry.write = desc.value;
1498
+ if (desc)
1499
+ break;
1500
+ const setter = Object.getOwnPropertyDescriptor(o, entry.attr)?.set;
1501
+ if (setter && !isAbsentHalf(setter)) {
1502
+ entry.write = setter;
1503
+ break;
1504
+ }
1505
+ const set = entry.writer === undefined ? undefined : Object.getOwnPropertyDescriptor(o, entry.writer);
1506
+ if (typeof set?.value === "function") {
1507
+ entry.write = set.value;
1508
+ break;
1509
+ }
1510
+ }
1511
+ }
1512
+ }
1513
+ if (entry.write === null ||
1514
+ Object.hasOwn(recv, entry.mid) ||
1515
+ Object.hasOwn(recv, entry.attr) ||
1516
+ (entry.writer !== undefined && Object.hasOwn(recv, entry.writer))) {
1517
+ return null;
1518
+ }
1519
+ return entry.write;
1520
+ }
1521
+ /** @perf 240ns — PERMANENT */
1522
+ function _methodFor(recv, mid) {
1523
+ const proto = Object.getPrototypeOf(recv);
1524
+ if (proto === null)
1525
+ return null;
1526
+ let entries = _methodEntries.get(proto);
1527
+ if (entries === undefined || entries.serial !== methodCacheSerial) {
1528
+ entries = { serial: methodCacheSerial, methods: new Map() };
1529
+ _methodEntries.set(proto, entries);
1530
+ }
1531
+ let method = entries.methods.get(mid);
1532
+ if (method === undefined) {
1533
+ if (mid === "==" ||
1534
+ mid === "!=" ||
1535
+ mid === "+" ||
1536
+ RELOPS.has(mid) ||
1537
+ mid.endsWith("=") ||
1538
+ recv instanceof Date ||
1539
+ recv instanceof Uint8Array ||
1540
+ recv instanceof rbCDate ||
1541
+ temporalTag(recv) !== null) {
1542
+ return null;
1543
+ }
1544
+ for (let o = proto; o; o = Object.getPrototypeOf(o)) {
1545
+ const desc = Object.getOwnPropertyDescriptor(o, mid);
1546
+ if (desc === undefined)
1547
+ continue;
1548
+ if (typeof desc.value !== "function")
1549
+ return null;
1550
+ method = desc.value;
1551
+ break;
1552
+ }
1553
+ if (method === undefined)
1554
+ return null;
1555
+ entries.methods.set(mid, method);
1556
+ }
1557
+ return recv[mid] === method && !Object.hasOwn(recv, mid)
1558
+ ? method
1559
+ : null;
1560
+ }
1561
+ /** @perf 240ns — PERMANENT */
1562
+ const _methodEntries = new WeakMap();
1563
+ /** @perf 100ns — PERMANENT */
1564
+ const _writerEntries = new Map();
1565
+ /**
1566
+ * `rb_check_funcall` (`vendor/ruby/v3.3.11/vm_eval.c:687`): the call when the
1567
+ * receiver responds to `mid`, else `undefined`, MRI's `Qundef`.
1568
+ *
1569
+ * @noRailsEquivalent PERMANENT
1570
+ */
1571
+ export function rbCheckFuncall(recv, mid, ...args) {
1572
+ if (!rbObjRespondTo(recv, mid))
1573
+ return undefined;
1574
+ return sendInternal(args.length, [mid, ...args], recv);
1575
+ }
1576
+ /**
1577
+ * `rb_obj_respond_to` (`vendor/ruby/v3.3.11/vm_method.c:2934`) — the SEND of
1578
+ * `respond_to?`, which `vm_respond_to` (`vm_method.c:2882`) routes through an
1579
+ * overridden `respond_to?` when the receiver's class defines one (as
1580
+ * `ActiveModel::AttributeMethods` does) — with no private-methods argument,
1581
+ * since a JS entry carries no visibility (`vm_method.c:2896-2905`) — and otherwise
1582
+ * falls back to {@link basicObjRespondTo} (`vm_method.c:2945`). Like
1583
+ * `method_entry_get` there, `respond_to?` is found by descriptor lookup, never
1584
+ * by a property read a `method_missing` Proxy's `get` trap would answer. An
1585
+ * overridden `respond_to?` is spelled `isRespondTo`, never `respondTo`, which
1586
+ * is a Rails method of its own (`MimeResponds#respond_to`).
1587
+ *
1588
+ * @noRailsEquivalent PERMANENT — Ruby core `rb_obj_respond_to`
1589
+ * (`vendor/ruby/v3.3.11/vm_method.c:2934`).
1590
+ */
1591
+ export function rbObjRespondTo(obj, mid) {
1592
+ const isRespondTo = _chainEntry(obj, "isRespondTo");
1593
+ if (typeof isRespondTo === "function") {
1594
+ const result = isRespondTo.call(obj, mid);
1595
+ return result != null && result !== false;
1596
+ }
1597
+ return basicObjRespondTo(obj, mid);
1598
+ }
1599
+ /**
1600
+ * `rb_builtin_class_name` (`vendor/ruby/v3.3.11/error.c:1216`), which the conversion
1601
+ * errors name their operand by: `builtin_class_name` (`error.c:1189`) answers
1602
+ * the LOWERCASE `"nil"` / `"true"` / `"false"` for those three immediates —
1603
+ * `Float(nil)` is `can't convert nil into Float`, not `NilClass` — and
1604
+ * everything else falls through to {@link rbObjClassname}.
1605
+ *
1606
+ * @noRailsEquivalent PERMANENT — Ruby core `rb_builtin_class_name` (`vendor/ruby/v3.3.11/error.c:1216`).
1607
+ */
1608
+ export function rbBuiltinClassName(x) {
1609
+ if (x === null || x === undefined)
1610
+ return "nil";
1611
+ if (x === true)
1612
+ return "true";
1613
+ if (x === false)
1614
+ return "false";
1615
+ return rbObjClassname(x);
1616
+ }
1617
+ /**
1618
+ * `rb_inspect` (`vendor/ruby/v3.3.11/object.c:704`) over the core classes a JS value
1619
+ * can be: `nil`, `true` / `false`, Integer and Float, Symbol, String (an
1620
+ * ASCII-8BIT one is a `Uint8Array`, its high bytes `\xHH`), Array and Hash.
1621
+ * Anything else falls through to the receiver's own `inspect`.
1622
+ *
1623
+ * The default arm is `to_s`, not Ruby's `#<Foo:0x… @a=1>` (`rb_obj_inspect`,
1624
+ * `vendor/ruby/v3.3.11/object.c:764`): reproducing that needs an object id JS does not
1625
+ * expose. Callers hand this plain data structures only, so the arm is unreached
1626
+ * today — a caller that does pass a class instance gets its `to_s`.
1627
+ *
1628
+ * @noRailsEquivalent PERMANENT — Ruby core `rb_inspect` (`vendor/ruby/v3.3.11/object.c:704`).
1629
+ */
1630
+ export function rbInspect(value) {
1631
+ return inspectValue(value, new Set());
1632
+ }
1633
+ /**
1634
+ * Node's `util.inspect` (`console.log`, an assertion diff, a spy matcher)
1635
+ * renders an object by walking its fields, where Ruby's `p`
1636
+ * (`rb_p`, `vendor/ruby/v3.3.11/io.c:9023`) prints `rb_inspect(obj)`. This
1637
+ * defines the `nodejs.util.inspect.custom` hook on `klass` as its own
1638
+ * `inspect`, so a class that ports `inspect` is printed by it.
1639
+ *
1640
+ * @noRailsEquivalent PERMANENT
1641
+ */
1642
+ export function rbDefineInspectCustom(klass) {
1643
+ Object.defineProperty(klass.prototype, Symbol.for("nodejs.util.inspect.custom"), {
1644
+ value() {
1645
+ return this.inspect();
1646
+ },
1647
+ writable: true,
1648
+ configurable: true,
1649
+ });
1650
+ }
1651
+ /**
1652
+ * `rb_obj_inspect` (`vendor/ruby/v3.3.11/object.c:783-795`), Ruby's `Kernel#inspect`:
1653
+ * `#<Class:0x… @ivar=value, …>`, or `rb_any_to_s` when there are no ivars.
1654
+ * A trails field `fooBar` / `_fooBar` is Ruby's `@foo_bar`. JS exposes no
1655
+ * object address, so each object is assigned a stable one on first inspection.
1656
+ *
1657
+ * @noRailsEquivalent PERMANENT
1658
+ */
1659
+ export function rbObjInspect(obj) {
1660
+ const ivars = Object.keys(obj);
1661
+ if (ivars.length === 0)
1662
+ return rbAnyToS(obj);
1663
+ const str = rbAnyToS(obj).slice(0, -1);
1664
+ if (objInspectRecursing.has(obj))
1665
+ return `${str} ...>`;
1666
+ objInspectRecursing.add(obj);
1667
+ try {
1668
+ return `${str} ${ivars
1669
+ .map((name) => `@${name
1670
+ .replace(/^_/, "")
1671
+ .replace(/([a-z\d])([A-Z])/g, "$1_$2")
1672
+ .toLowerCase()}=${rbInspect(obj[name])}`)
1673
+ .join(", ")}>`;
1674
+ }
1675
+ finally {
1676
+ objInspectRecursing.delete(obj);
1677
+ }
1678
+ }
1679
+ /**
1680
+ * `rb_any_to_s` (`vendor/ruby/v3.3.11/object.c:693-701`), `Kernel#to_s`:
1681
+ * `#<Class:0x…>`. JS exposes no object address, so each object is assigned a
1682
+ * stable one on first use. A JS function is Ruby's `Proc`, whose `to_s`
1683
+ * (`proc_to_s`, `vendor/ruby/v3.3.11/proc.c:1595`) opens the same way.
1684
+ *
1685
+ * @noRailsEquivalent PERMANENT
1686
+ */
1687
+ export function rbAnyToS(obj) {
1688
+ const cname = typeof obj === "function"
1689
+ ? "Proc"
1690
+ : rbModToS(obj.constructor);
1691
+ return `#<${cname}:${objAddress(obj)}>`;
1692
+ }
1693
+ function objAddress(obj) {
1694
+ let address = objAddresses.get(obj);
1695
+ if (address === undefined) {
1696
+ address = nextObjAddress += 8;
1697
+ objAddresses.set(obj, address);
1698
+ }
1699
+ return `0x${address.toString(16).padStart(16, "0")}`;
1700
+ }
1701
+ /** @noRailsEquivalent PERMANENT — Ruby core `rb_obj_id` (`vendor/ruby/v3.3.11/gc.c:4975`). */
1702
+ export function rbObjId(obj) {
1703
+ if (typeof obj === "number" && !Number.isInteger(obj)) {
1704
+ flonumBits.setFloat64(0, obj);
1705
+ const v = flonumBits.getBigUint64(0);
1706
+ const bits = Number((v >> 60n) & 0x7n);
1707
+ if (v !== 0x3000000000000000n && ((bits - 3) & ~0x01) === 0) {
1708
+ const rotated = BigInt.asUintN(64, (v << 3n) | (v >> 61n));
1709
+ return fixId(BigInt.asIntN(64, (rotated & ~0x01n) | 0x02n));
1710
+ }
1711
+ }
1712
+ else if (typeof obj === "number" || typeof obj === "bigint") {
1713
+ const n = BigInt(obj);
1714
+ if (n >= FIXNUM_MIN && n <= FIXNUM_MAX)
1715
+ return fixId(2n * n + 1n);
1716
+ }
1717
+ else if (obj === null || obj === undefined) {
1718
+ return 4;
1719
+ }
1720
+ else if (obj === true) {
1721
+ return 20;
1722
+ }
1723
+ else if (obj === false) {
1724
+ return 0;
1725
+ }
1726
+ else if (typeof obj === "object" || typeof obj === "function") {
1727
+ let id = objIds.get(obj);
1728
+ if (id === undefined) {
1729
+ id = nextObjectId;
1730
+ nextObjectId += OBJ_ID_INCREMENT;
1731
+ objIds.set(obj, id);
1732
+ }
1733
+ return id;
1734
+ }
1735
+ const id = nextObjectId;
1736
+ nextObjectId += OBJ_ID_INCREMENT;
1737
+ return id;
1738
+ }
1739
+ function fixId(id) {
1740
+ const n = Number(id);
1741
+ return Number.isSafeInteger(n) ? n : id;
1742
+ }
1743
+ const FIXNUM_MAX = (1n << 62n) - 1n;
1744
+ const FIXNUM_MIN = -(1n << 62n);
1745
+ const flonumBits = new DataView(new ArrayBuffer(8));
1746
+ const OBJ_ID_INCREMENT = 20;
1747
+ const OBJ_ID_INITIAL = OBJ_ID_INCREMENT * 2;
1748
+ const objIds = new WeakMap();
1749
+ let nextObjectId = OBJ_ID_INITIAL;
1750
+ const objInspectRecursing = new Set();
1751
+ const objAddresses = new WeakMap();
1752
+ let nextObjAddress = 0x7f0000000000;
1753
+ /**
1754
+ * The dispatch under the `rb_exec_recursive` stack its collection arms are
1755
+ * wrapped in (`vendor/ruby/v3.3.11/hash.c:3487`, `vendor/ruby/v3.3.11/array.c:2918`).
1756
+ * `recursing` is that stack, which `rb_exec_recursive` keeps per-thread.
1757
+ */
1758
+ function inspectValue(value, recursing) {
1759
+ if (value == null)
1760
+ return "nil";
1761
+ if (typeof value === "boolean")
1762
+ return value ? "true" : "false";
1763
+ if (typeof value === "number" || value instanceof Number)
1764
+ return floToS(value);
1765
+ if (typeof value === "bigint")
1766
+ return String(value);
1767
+ if (isSymbol(value))
1768
+ return symInspect(value);
1769
+ if (typeof value === "string")
1770
+ return stringInspect(value);
1771
+ if (value instanceof Uint8Array) {
1772
+ const binaryInspect = (ascii) => stringInspect(ascii)
1773
+ .slice(1, -1)
1774
+ .replace(/(?<!\\)((?:\\\\)*)\\u00([0-7][0-9A-F])/g, "$1\\x$2");
1775
+ let ascii = "";
1776
+ let result = "";
1777
+ for (const byte of value) {
1778
+ if (byte < 0x80) {
1779
+ ascii += String.fromCharCode(byte);
1780
+ continue;
1781
+ }
1782
+ result += binaryInspect(ascii) + `\\x${byte.toString(16).toUpperCase()}`;
1783
+ ascii = "";
1784
+ }
1785
+ return `"${result}${binaryInspect(ascii)}"`;
1786
+ }
1787
+ if (Array.isArray(value))
1788
+ return inspectAry(value, recursing);
1789
+ if (isPlainHash(value) && classpaths.has(value)) {
1790
+ return rbModToS(value);
1791
+ }
1792
+ if (isPlainHash(value) || value instanceof Map)
1793
+ return inspectHash(value, recursing);
1794
+ if (value instanceof RegExp)
1795
+ return regDesc(value);
1796
+ if (value instanceof Set)
1797
+ return setInspect(value, recursing);
1798
+ const own = value.inspect;
1799
+ if (typeof own === "function")
1800
+ return String(own.call(value));
1801
+ if (value instanceof Error)
1802
+ return excInspect(value);
1803
+ if (typeof value === "function" &&
1804
+ Object.getOwnPropertyDescriptor(value, "prototype")?.writable === false) {
1805
+ return rbModToS(value);
1806
+ }
1807
+ if (typeof value === "function")
1808
+ return rbAnyToS(value);
1809
+ if (value instanceof Date || temporalTag(value) !== null) {
1810
+ const str = rbObjAsString(value);
1811
+ if (typeof str === "string")
1812
+ return str;
1813
+ }
1814
+ if (typeof value === "object" && !(value instanceof Uint8Array))
1815
+ return rbObjInspect(value);
1816
+ return String(value);
1817
+ }
1818
+ /** `Set#inspect` (`vendor/ruby/v3.3.11/lib/set.rb:811-823`). */
1819
+ function setInspect(set, recursing) {
1820
+ if (recursing.has(set))
1821
+ return `#<${rbObjClassname(set)}: {...}>`;
1822
+ recursing.add(set);
1823
+ try {
1824
+ return `#<${rbObjClassname(set)}: {${inspectAry([...set], recursing).slice(1, -1)}}>`;
1825
+ }
1826
+ finally {
1827
+ recursing.delete(set);
1828
+ }
1829
+ }
1830
+ /** `exc_inspect` (`vendor/ruby/v3.3.11/error.c:1677-1703`), `Exception#inspect`. */
1831
+ function excInspect(exc) {
1832
+ const klass = rbObjClassname(exc);
1833
+ const str = exc.message;
1834
+ if (str.length === 0)
1835
+ return klass;
1836
+ if (str.includes("\n"))
1837
+ return `#<${klass}:${stringInspect(str)}>`;
1838
+ return `#<${klass}: ${str}>`;
1839
+ }
1840
+ function symInspect(sym) {
1841
+ const name = sym.slice(1);
1842
+ return strSymnameP(name) ? sym : `:${stringInspect(name)}`;
1843
+ }
1844
+ const SYM_OPERATOR = /^(?:\[\]=?|<=>|<<|<=|<|>>|>=|>|=~|===?|\*\*?|[+-]@?|[|^&/%~`]|!=|!~|!)$/;
1845
+ const SYM_SPECIAL_GLOBAL = /^\$(?:[~*$?!@/\\;,.=:<>"&`'+0]|\d+|-[\p{L}\p{N}_])$/u;
1846
+ const SYM_PREFIXED_IDENT = /^(?:@@?|\$)[\p{L}_\P{ASCII}][\p{L}\p{N}_\P{ASCII}]*$/u;
1847
+ const SYM_IDENT = /^[\p{L}_\P{ASCII}][\p{L}\p{N}_\P{ASCII}]*[?!=]?$/u;
1848
+ const SYM_UNPRINTABLE = /[\p{Cc}\p{Cn}\p{Cs}\p{Zl}\p{Zp}]/u;
1849
+ function strSymnameP(name) {
1850
+ if (SYM_UNPRINTABLE.test(name))
1851
+ return false;
1852
+ return (SYM_OPERATOR.test(name) ||
1853
+ SYM_SPECIAL_GLOBAL.test(name) ||
1854
+ SYM_PREFIXED_IDENT.test(name) ||
1855
+ SYM_IDENT.test(name));
1856
+ }
1857
+ /**
1858
+ * `rb_reg_desc` (`vendor/ruby/v3.3.11/re.c:456-481`): the source between
1859
+ * slashes, then `option_to_str` (`re.c:322-330`) in its `m`, `i`, `x` order.
1860
+ * Ruby's multiline option is JS's `dotAll` flag, and JS has no extended flag.
1861
+ */
1862
+ function regDesc(re) {
1863
+ let opts = "";
1864
+ if (re.dotAll)
1865
+ opts += "m";
1866
+ if (re.ignoreCase)
1867
+ opts += "i";
1868
+ return `/${re.source}/${opts}`;
1869
+ }
1870
+ /**
1871
+ * `inspect_hash` (`vendor/ruby/v3.3.11/hash.c:3459`) under the `rb_exec_recursive`
1872
+ * (`hash.c:3487`) its caller wraps it in: a hash already on the recursion
1873
+ * stack renders as `"{...}"` rather than recursing forever.
1874
+ *
1875
+ * It sits beside {@link rbInspect} rather than in `hash.ts` because the
1876
+ * recursion stack is threaded through it and {@link inspectAry} alike, and a
1877
+ * value graph alternates between the two.
1878
+ */
1879
+ function inspectHash(hash, recursing) {
1880
+ if (recursing.has(hash))
1881
+ return "{...}";
1882
+ const pairs = hash instanceof Map ? [...hash.entries()] : Object.keys(hash).map((key) => [key, hash[key]]);
1883
+ if (pairs.length === 0)
1884
+ return "{}";
1885
+ recursing.add(hash);
1886
+ try {
1887
+ return `{${pairs
1888
+ .map(([key, value]) => `${inspectValue(key, recursing)}=>${inspectValue(value, recursing)}`)
1889
+ .join(", ")}}`;
1890
+ }
1891
+ finally {
1892
+ recursing.delete(hash);
1893
+ }
1894
+ }
1895
+ /**
1896
+ * `inspect_ary` (`vendor/ruby/v3.3.11/array.c:2888`) under the `rb_exec_recursive`
1897
+ * `rb_ary_inspect` (`array.c:2918`) wraps it in — the Array twin of
1898
+ * {@link inspectHash}, down to the `"[...]"` recursive slot.
1899
+ */
1900
+ function inspectAry(ary, recursing) {
1901
+ if (recursing.has(ary))
1902
+ return "[...]";
1903
+ recursing.add(ary);
1904
+ try {
1905
+ return `[${ary.map((element) => inspectValue(element, recursing)).join(", ")}]`;
1906
+ }
1907
+ finally {
1908
+ recursing.delete(ary);
1909
+ }
1910
+ }
1911
+ /**
1912
+ * `RB_TYPE_P(obj, T_HASH)` (`vendor/ruby/v3.3.11/include/ruby/internal/value_type.h:122`)
1913
+ * for the object-literal half of a trails Hash: an object whose prototype
1914
+ * chain reaches `Object.prototype` through no class.
1915
+ *
1916
+ * @noRailsEquivalent PERMANENT
1917
+ */
1918
+ export function isPlainHash(value) {
1919
+ if (typeof value !== "object" || value === null)
1920
+ return false;
1921
+ for (let proto = Object.getPrototypeOf(value); proto !== null; proto = Object.getPrototypeOf(proto)) {
1922
+ if (proto === Object.prototype)
1923
+ return true;
1924
+ const klass = Object.getOwnPropertyDescriptor(proto, "constructor")?.value;
1925
+ if (typeof klass === "function" && klass.prototype === proto)
1926
+ return false;
1927
+ }
1928
+ return true;
1929
+ }
1930
+ /**
1931
+ * `RTEST` (`vendor/ruby/v3.3.11/include/ruby/internal/special_consts.h:138` `RB_TEST`):
1932
+ * false only for `nil` and `false`, where a JS truthiness test is also false
1933
+ * for `0`, `""` and `NaN`.
1934
+ *
1935
+ * @noRailsEquivalent PERMANENT
1936
+ */
1937
+ export function rtest(obj) {
1938
+ return obj !== null && obj !== undefined && obj !== false;
1939
+ }
1940
+ /**
1941
+ * Ruby's `obj.nil?` send: `NilClass#nil?` is `rb_true`
1942
+ * (`vendor/ruby/v3.3.11/object.c:4425`) and `Kernel#nil?` is `rb_false`
1943
+ * (`object.c:4371`), which a class may override
1944
+ * (`ActiveRecord::Relation::QueryAttribute#nil?`). JS has no method on `null`
1945
+ * or `undefined`, the two spellings of Ruby's `nil`, so the send is a
1946
+ * function; an override is spelled `isNil`.
1947
+ *
1948
+ * @noRailsEquivalent PERMANENT
1949
+ */
1950
+ export function isNil(obj) {
1951
+ if (obj === null || obj === undefined)
1952
+ return true;
1953
+ if (rbObjRespondTo(obj, "isNil"))
1954
+ return obj.isNil();
1955
+ return false;
1956
+ }
1957
+ /** @noRailsEquivalent PERMANENT — Ruby core `rb_obj_as_string` (`vendor/ruby/v3.3.11/string.c:1653`). */
1958
+ export function rbObjAsString(value) {
1959
+ if (value == null)
1960
+ return "";
1961
+ if (typeof value === "string")
1962
+ return value;
1963
+ if (value instanceof Uint8Array)
1964
+ return value;
1965
+ if (Array.isArray(value))
1966
+ return rbInspect(value);
1967
+ if (isPlainHash(value) || value instanceof Map || value instanceof Set)
1968
+ return rbInspect(value);
1969
+ if (typeof value === "number" || value instanceof Number)
1970
+ return floToS(value);
1971
+ if (value instanceof RegExp)
1972
+ return rbRegToS(value);
1973
+ if (rbObjRespondTo(value, "toS")) {
1974
+ const str = value.toS();
1975
+ if (str instanceof Uint8Array)
1976
+ return str;
1977
+ if (typeof str === "string")
1978
+ return str;
1979
+ return str instanceof rbCString ? String(str) : rbAnyToS(value);
1980
+ }
1981
+ if (typeof value === "function" &&
1982
+ Object.getOwnPropertyDescriptor(value, "prototype")?.writable === false) {
1983
+ if (value.toString !== Function.prototype.toString) {
1984
+ const str = value.toString();
1985
+ if (typeof str === "string")
1986
+ return str;
1987
+ }
1988
+ return rbModToS(value);
1989
+ }
1990
+ if (typeof value === "object") {
1991
+ if (value.toString === Object.prototype.toString)
1992
+ return rbAnyToS(value);
1993
+ const str = value.toString();
1994
+ if (typeof str === "string" || str instanceof Uint8Array)
1995
+ return str;
1996
+ return rbAnyToS(value);
1997
+ }
1998
+ return String(value);
1999
+ }
2000
+ /**
2001
+ * `flo_to_s` (`vendor/ruby/v3.3.11/numeric.c:1059`), `Float#to_s`: always a decimal
2002
+ * point, and the exponent form outside `1e-4 ... 1e16`.
2003
+ *
2004
+ * JS has one `number` where Ruby has Integer and Float, and `1.0 === 1`, so the
2005
+ * seat cannot be recovered from the value. A whole-valued `number` is read as
2006
+ * an Integer and renders without a point: it is what nearly every caller hands
2007
+ * over (ids, counts, sizes), and a `bigint` is not what those seats hold in
2008
+ * trails. `-0` is the one whole value no Integer can be, so it stays a Float.
2009
+ * A seat that must stay a Float whatever its value arrives boxed — `new Number(1)`,
2010
+ * JS's own object wrapper — and takes the Float reading before that one.
2011
+ */
2012
+ function floToS(flo) {
2013
+ if (typeof flo === "number" && Number.isInteger(flo) && !Object.is(flo, -0))
2014
+ return String(flo);
2015
+ const value = flo.valueOf();
2016
+ if (!Number.isFinite(value)) {
2017
+ return Number.isNaN(value) ? "NaN" : value > 0 ? "Infinity" : "-Infinity";
2018
+ }
2019
+ const [mant, e] = Math.abs(value).toExponential().split("e");
2020
+ let buf = mant.replace(".", "");
2021
+ if (value === 0)
2022
+ buf = "0";
2023
+ const digs = buf.length;
2024
+ const decpt = value === 0 ? 1 : Number(e) + 1;
2025
+ const s = value < 0 || Object.is(value, -0) ? "-" : "";
2026
+ if (decpt > 0) {
2027
+ if (decpt < digs)
2028
+ return `${s}${buf.slice(0, decpt)}.${buf.slice(decpt)}`;
2029
+ if (decpt <= 15)
2030
+ return `${s}${buf}${"0".repeat(decpt - digs)}.0`;
2031
+ }
2032
+ else if (decpt > -4) {
2033
+ return `${s}0.${"0".repeat(-decpt)}${buf}`;
2034
+ }
2035
+ return `${s}${buf[0]}.${digs > 1 ? buf.slice(1) : "0"}e${decpt - 1 < 0 ? "-" : "+"}${String(Math.abs(decpt - 1)).padStart(2, "0")}`;
2036
+ }
2037
+ const ivarFields = new WeakMap();
2038
+ /**
2039
+ * The ivar-table entry `rb_ivar_set` (`vendor/ruby/v3.3.11/variable.c:1923`) writes
2040
+ * for `iv`, located on `klass`'s instances: the JS field holding it, where that
2041
+ * is not the field-name rule's spelling. An ivar behind a same-named reader
2042
+ * lives in the `_`-prefixed field. {@link rbObjIvarGet}, {@link rbObjIvarSet}
2043
+ * and {@link rbObjInstanceVariables} read the declaration, which subclasses
2044
+ * inherit.
2045
+ *
2046
+ * @noRailsEquivalent PERMANENT — Ruby core ivar table (`vendor/ruby/v3.3.11/variable.c:1923`).
2047
+ */
2048
+ export function rbDeclareIvar(klass, iv, field) {
2049
+ let table = ivarFields.get(klass.prototype);
2050
+ if (!table)
2051
+ ivarFields.set(klass.prototype, (table = new Map()));
2052
+ table.set(iv, field);
2053
+ }
2054
+ function ivarField(obj, id) {
2055
+ for (let o = obj; o; o = Object.getPrototypeOf(o)) {
2056
+ const field = ivarFields.get(o)?.get(id);
2057
+ if (field !== undefined)
2058
+ return field;
2059
+ }
2060
+ let field = _defaultIvarFields.get(id);
2061
+ if (field === undefined) {
2062
+ field = id.slice(1).replace(/(?<=[A-Za-z\d])_([a-z])/g, (_, c) => c.toUpperCase());
2063
+ if (_defaultIvarFields.size >= 1024)
2064
+ _defaultIvarFields.clear();
2065
+ _defaultIvarFields.set(id, field);
2066
+ }
2067
+ return field;
2068
+ }
2069
+ /** @perf 633ns — PERMANENT */
2070
+ const _defaultIvarFields = new Map();
2071
+ /** @perf 44ns — PERMANENT */
2072
+ const _validIvarNames = new Set();
2073
+ function fieldIvar(obj, field) {
2074
+ for (let o = obj; o; o = Object.getPrototypeOf(o)) {
2075
+ for (const [iv, f] of ivarFields.get(o) ?? [])
2076
+ if (f === field)
2077
+ return iv;
2078
+ }
2079
+ const iv = `@${field.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)}`;
2080
+ return ivarField(obj, iv) === field ? iv : `@${field}`;
2081
+ }
2082
+ function idForVar(obj, iv) {
2083
+ if (isSymbol(iv))
2084
+ iv = symbolToS(iv);
2085
+ if (_validIvarNames.has(iv))
2086
+ return iv;
2087
+ if (!/^@[A-Za-z_\u0080-\u{10FFFF}][A-Za-z0-9_\u0080-\u{10FFFF}]*$/u.test(iv)) {
2088
+ throw new NameError(`\`${iv}' is not allowed as an instance variable name`, iv, {
2089
+ receiver: obj,
2090
+ });
2091
+ }
2092
+ if (_validIvarNames.size >= 1024)
2093
+ _validIvarNames.clear();
2094
+ _validIvarNames.add(iv);
2095
+ return iv;
2096
+ }
2097
+ /**
2098
+ * `Kernel#instance_variables` (`rb_obj_instance_variables`,
2099
+ * `vendor/ruby/v3.3.11/variable.c:2259`): the ivar names of `obj`'s own
2100
+ * enumerable fields, each spelled by its {@link rbDeclareIvar} declaration or
2101
+ * the field-name rule (`fooBar` is `@foo_bar`).
2102
+ *
2103
+ * @noRailsEquivalent PERMANENT — Ruby core `Kernel#instance_variables`
2104
+ * (`vendor/ruby/v3.3.11/variable.c:2259`).
2105
+ */
2106
+ export function rbObjInstanceVariables(obj) {
2107
+ return Object.keys(obj).map((field) => fieldIvar(obj, field));
2108
+ }
2109
+ /**
2110
+ * `Kernel#instance_variable_get` (`rb_obj_ivar_get`, `vendor/ruby/v3.3.11/object.c:2880`):
2111
+ * the value of ivar `iv`, or `nil` when `obj` has no own field for it
2112
+ * (`rb_ivar_get`, `vendor/ruby/v3.3.11/variable.c:1405`), never an inherited
2113
+ * method or accessor. A name that is not an ivar name (`rb_is_instance_name`,
2114
+ * where a non-ASCII character is an identifier character) raises `NameError`.
2115
+ *
2116
+ * @noRailsEquivalent PERMANENT — Ruby core `Kernel#instance_variable_get`
2117
+ * (`vendor/ruby/v3.3.11/object.c:2880`).
2118
+ */
2119
+ export function rbObjIvarGet(obj, iv) {
2120
+ const id = idForVar(obj, iv);
2121
+ const field = ivarField(obj, id);
2122
+ return Object.hasOwn(obj, field) ? obj[field] : null;
2123
+ }
2124
+ /**
2125
+ * `Kernel#instance_variable_defined?` (`rb_obj_ivar_defined`, `vendor/ruby/v3.3.11/object.c:2942`):
2126
+ * whether `obj` has an own field for ivar `iv`, a `nil`-valued one included.
2127
+ *
2128
+ * @noRailsEquivalent PERMANENT — Ruby core `Kernel#instance_variable_defined?`
2129
+ * (`vendor/ruby/v3.3.11/object.c:2942`).
2130
+ */
2131
+ export function rbObjIvarDefined(obj, iv) {
2132
+ const id = idForVar(obj, iv);
2133
+ return Object.hasOwn(obj, ivarField(obj, id));
2134
+ }
2135
+ /**
2136
+ * `Kernel#instance_variable_set` (`rb_obj_ivar_set_m`, `vendor/ruby/v3.3.11/object.c:2914`):
2137
+ * sets ivar `iv` as an own field of `obj`, never through a setter, as
2138
+ * `rb_ivar_set` (`vendor/ruby/v3.3.11/variable.c:1923`) writes the ivar table
2139
+ * directly after `rb_check_frozen`. `iv` is a Symbol (`":@foo"`) or a String,
2140
+ * as `id_for_var`'s `rb_check_id` (`vendor/ruby/v3.3.11/object.c:2225`) takes either.
2141
+ *
2142
+ * @noRailsEquivalent PERMANENT — Ruby core `Kernel#instance_variable_set`
2143
+ * (`vendor/ruby/v3.3.11/object.c:2914`).
2144
+ */
2145
+ export function rbObjIvarSet(obj, iv, val) {
2146
+ const id = idForVar(obj, iv);
2147
+ if (Object.isFrozen(obj)) {
2148
+ throw new FrozenError(`can't modify frozen ${rbObjClassname(obj)}: ${rbInspect(obj)}`, {
2149
+ receiver: obj,
2150
+ });
2151
+ }
2152
+ Object.defineProperty(obj, ivarField(obj, id), {
2153
+ value: val,
2154
+ writable: true,
2155
+ enumerable: true,
2156
+ configurable: true,
2157
+ });
2158
+ return val;
2159
+ }
2160
+ /**
2161
+ * A T_OBJECT of class `Object` (`struct RObject`,
2162
+ * `vendor/ruby/v3.3.11/include/ruby/internal/core/robject.h:83`). A plain JS
2163
+ * object reads as a Hash, so `rb_obj_alloc(rb_cObject)` is one of these where
2164
+ * a compat dumper builds it (`range_dumper`, `vendor/ruby/v3.3.11/range.c:2180`).
2165
+ *
2166
+ * @noRailsEquivalent PERMANENT
2167
+ */
2168
+ export class RObject {
2169
+ }
2170
+ const hiddenIvars = new WeakMap();
2171
+ /**
2172
+ * `rb_ivar_set` (`vendor/ruby/v3.3.11/variable.c:1923`). An `@` name is the
2173
+ * object's own field; any other ID is a hidden ivar (`id_excl`, `id_beg`,
2174
+ * `id_end`), which `instance_variables` never lists.
2175
+ *
2176
+ * @noRailsEquivalent PERMANENT
2177
+ */
2178
+ export function rbIvarSet(obj, id, val) {
2179
+ if (id[0] === "@")
2180
+ return rbObjIvarSet(obj, id, val);
2181
+ if (Object.isFrozen(obj)) {
2182
+ throw new FrozenError(`can't modify frozen ${rbObjClassname(obj)}: ${rbInspect(obj)}`, {
2183
+ receiver: obj,
2184
+ });
2185
+ }
2186
+ let ivars = hiddenIvars.get(obj);
2187
+ if (ivars === undefined)
2188
+ hiddenIvars.set(obj, (ivars = new Map()));
2189
+ ivars.set(id, val);
2190
+ return val;
2191
+ }
2192
+ /**
2193
+ * `rb_ivar_get` (`vendor/ruby/v3.3.11/variable.c:1405`), reading a hidden ivar
2194
+ * {@link rbIvarSet} wrote as well as an `@` one.
2195
+ *
2196
+ * @noRailsEquivalent PERMANENT
2197
+ */
2198
+ export function rbIvarGet(obj, id) {
2199
+ if (id[0] === "@")
2200
+ return rbObjIvarGet(obj, id);
2201
+ const ivars = hiddenIvars.get(obj);
2202
+ return ivars !== undefined && ivars.has(id) ? ivars.get(id) : null;
2203
+ }
2204
+ /**
2205
+ * `rb_ivar_foreach` (`vendor/ruby/v3.3.11/variable.c:2182`): every ivar of
2206
+ * `obj`, the hidden ones included.
2207
+ *
2208
+ * @noRailsEquivalent PERMANENT
2209
+ */
2210
+ export function rbIvarForeach(obj, func) {
2211
+ for (const id of rbObjInstanceVariables(obj))
2212
+ func(id, rbObjIvarGet(obj, id));
2213
+ hiddenIvars.get(obj)?.forEach((val, id) => func(id, val));
2214
+ }
2215
+ /**
2216
+ * `Kernel#remove_instance_variable` (`rb_obj_remove_instance_variable`,
2217
+ * `vendor/ruby/v3.3.11/variable.c:2314`): deletes `obj`'s own field for ivar
2218
+ * `iv` and answers its value, raising `NameError` when it is not defined.
2219
+ *
2220
+ * @noRailsEquivalent PERMANENT — Ruby core `Kernel#remove_instance_variable`
2221
+ * (`vendor/ruby/v3.3.11/variable.c:2314`).
2222
+ */
2223
+ export function rbObjRemoveInstanceVariable(obj, iv) {
2224
+ const id = idForVar(obj, iv);
2225
+ if (Object.isFrozen(obj)) {
2226
+ throw new FrozenError(`can't modify frozen ${rbObjClassname(obj)}: ${rbInspect(obj)}`, {
2227
+ receiver: obj,
2228
+ });
2229
+ }
2230
+ const field = ivarField(obj, id);
2231
+ if (Object.hasOwn(obj, field)) {
2232
+ const val = obj[field];
2233
+ delete obj[field];
2234
+ return val;
2235
+ }
2236
+ throw new NameError(`instance variable ${iv} not defined`, iv, { receiver: obj });
2237
+ }
2238
+ //# sourceMappingURL=object.js.map