js-on-sx: top-level this resolves to the global object
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 15s

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.
This commit is contained in:
2026-05-08 13:55:12 +00:00
parent 4ab79f5758
commit 0b4f5e1df9
5 changed files with 53 additions and 27 deletions

View File

@@ -75,7 +75,9 @@
(if
(dict-has? __js_this_cell__ "this")
(get __js_this_cell__ "this")
:js-undefined)))
js-global-this)))
(define js-global-this :js-undefined)
(define js-this-set! (fn (v) (dict-set! __js_this_cell__ "this" v)))
@@ -4674,3 +4676,5 @@
(dict-set! (get Boolean "prototype") "__js_boolean_value__" false))
(define js-global {:undefined js-undefined :JSON JSON :parseInt parseInt :Object Object :isNaN js-global-is-nan :Infinity inf :NaN 0 :String String :Boolean Boolean :Array Array :Math Math :parseFloat parseFloat :Number Number :console console :isFinite js-global-is-finite})
(set! js-global-this js-global)