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