Was unconditionally throwing "Function constructor not supported".
Now js-function-ctor joins param strings with commas, wraps the
body in (function(<params>){<body>}), and runs it through js-eval.
Now Function('a', 'b', 'return a + b')(3,4) === 7.
built-ins/Function: 0/14 → 4/14. conformance.sh: 148/148.
Three related fixes:
1. Every JS function body binds arguments to (cons p1 ... __extra_args__),
so arguments[k] and arguments.length work as expected.
2. Array.from(iter, mapFn) invokes mapFn through js-call-with-this
with the index as second arg (was (map-fn x), missing index and
inheriting outer this).
3. thisArg defaults to js-global-this when omitted (per non-strict ES).
conformance.sh: 148/148.
Was always emitting comma-joined via js-list-join, so user
mutations of Array.prototype.toString had no effect on String(arr)
/ "" + arr. Now look up the override via js-dict-get-walk and call
it on the list as this; fall back to (js-list-join v ",") when the
override doesn't return a string.
String fail count: 11 → 9. conformance.sh: 148/148.
Per ES non-strict script semantics, top-level this is the global
object (window/global/globalThis). Was throwing "Undefined symbol:
this". Two-part fix:
1. js-global-this runtime variable set to js-global after globals
are defined; js-this falls back to it when no this is active.
2. js-eval wraps transpiled body in (let ((this (js-this))) ...)
so JS this resolves to bound this, or top-level to global.
Fixes String(this), this.Object === Object, etc.
built-ins/Object: 46/50 → 47/50. conformance.sh: 148/148.
Per ES, ToPrimitive only accepts strings/numbers/booleans/null
/undefined as primitives — objects AND functions trigger the next
step. Was treating function returns from toString/valueOf as
primitives (recursing to extract a string), so toString returning
a function didn't fall through to valueOf. Widened the dict-only
check to (or (= type "dict") (js-function? result)) in both
js-to-string and js-to-number ToPrimitive paths.
built-ins/String: 85/99 → 86/99. conformance.sh: 148/148.
Two hardcoded paths returned the native marker regardless of user
override: js-invoke-function-method and the lambda branch of
js-to-string. Both now look up Function.prototype.toString via
js-dict-get-walk and invoke it on the function, falling back to
the native marker only if no override exists.
built-ins/String: 84/99 → 85/99. conformance.sh: 148/148.
Per ES, Boolean.prototype is a Boolean wrapper around false,
Number.prototype wraps 0, String.prototype wraps "". So
Boolean.prototype == false (loose-eq unwraps), and
Object.prototype.toString.call(Number.prototype) ===
"[object Number]". Set __js_*_value__ on each in post-init.
built-ins/Boolean: 23/27 → 24/27, String: 80/99 → 84/99.
conformance.sh: 148/148.
Mirrors the earlier js-to-string fix. Number(obj) must throw
if ToPrimitive cannot extract a primitive (both valueOf and
toString return objects). Was returning NaN silently. Replaced
the inner (js-nan-value) fallback with (raise (js-new-call
TypeError ...)).
built-ins/Number: 45/50 → 46/50. conformance.sh: 148/148.
Per ES, every native prototype's [[Prototype]] is Object.prototype
(and Function.prototype.[[Prototype]] is too). Was missing those
links, so Object.prototype.isPrototypeOf(Boolean.prototype)
returned false (the explicit isPrototypeOf walks __proto__, not
the recent fallback). Added 5 dict-set! lines to the post-init.
built-ins/Boolean: 22/27 → 23/27, built-ins/Number: 44/50 → 45/50.
conformance.sh: 148/148.