js-on-sx: built-in .length returns spec-defined values
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
String.fromCharCode.length, Math.max.length, Array.from.length were returning 0 because their SX lambdas use &rest args with no required params — but spec assigns each a specific length. Added js-builtin-fn-length mapping JS name to spec length (12 entries). js-fn-length consults the table first and falls back to counting real params. built-ins/String: 79/99 → 80/99, built-ins/Array: 20/45 → 21/45. conformance.sh: 148/148.
This commit is contained in:
@@ -113,13 +113,35 @@
|
||||
(let
|
||||
((t (type-of f)))
|
||||
(cond
|
||||
((= t "lambda") (js-count-real-params (lambda-params f)))
|
||||
((= t "lambda")
|
||||
(let
|
||||
((mapped (js-builtin-fn-length (js-unmap-fn-name (js-extract-fn-name f)))))
|
||||
(if (>= mapped 0) mapped (js-count-real-params (lambda-params f)))))
|
||||
((= t "function") 0)
|
||||
((= t "component") 0)
|
||||
((and (= t "dict") (contains? (keys f) "__callable__"))
|
||||
(js-fn-length (get f "__callable__")))
|
||||
(else 0)))))
|
||||
|
||||
(define
|
||||
js-builtin-fn-length
|
||||
(fn
|
||||
(name)
|
||||
(cond
|
||||
((= name "fromCharCode") 1)
|
||||
((= name "fromCodePoint") 1)
|
||||
((= name "raw") 1)
|
||||
((= name "of") 0)
|
||||
((= name "from") 1)
|
||||
((= name "isArray") 1)
|
||||
((= name "max") 2)
|
||||
((= name "min") 2)
|
||||
((= name "hypot") 2)
|
||||
((= name "atan2") 2)
|
||||
((= name "imul") 2)
|
||||
((= name "pow") 2)
|
||||
(else -1))))
|
||||
|
||||
(define
|
||||
js-extract-fn-name
|
||||
(fn
|
||||
|
||||
Reference in New Issue
Block a user