js-on-sx: call/apply substitute global for null/undefined this (non-strict)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
This commit is contained in:
@@ -333,20 +333,25 @@
|
||||
(cond
|
||||
((= key "call")
|
||||
(let
|
||||
((this-arg (if (< (len args) 1) :js-undefined (nth args 0)))
|
||||
((raw-this (if (< (len args) 1) :js-undefined (nth args 0)))
|
||||
(rest
|
||||
(if
|
||||
(< (len args) 1)
|
||||
(list)
|
||||
(js-list-slice args 1 (len args)))))
|
||||
(js-call-with-this this-arg recv rest)))
|
||||
(let
|
||||
((this-arg
|
||||
(if (or (js-undefined? raw-this) (= raw-this nil)) js-global-this raw-this)))
|
||||
(js-call-with-this this-arg recv rest))))
|
||||
((= key "apply")
|
||||
(let
|
||||
((this-arg (if (< (len args) 1) :js-undefined (nth args 0)))
|
||||
((raw-this (if (< (len args) 1) :js-undefined (nth args 0)))
|
||||
(arr
|
||||
(if (< (len args) 2) (list) (nth args 1))))
|
||||
(let
|
||||
((rest (cond ((= arr nil) (list)) ((js-undefined? arr) (list)) ((list? arr) arr) (else (js-iterable-to-list arr)))))
|
||||
((rest (cond ((= arr nil) (list)) ((js-undefined? arr) (list)) ((list? arr) arr) (else (js-iterable-to-list arr))))
|
||||
(this-arg
|
||||
(if (or (js-undefined? raw-this) (= raw-this nil)) js-global-this raw-this)))
|
||||
(js-call-with-this this-arg recv rest))))
|
||||
((= key "bind")
|
||||
(let
|
||||
|
||||
@@ -158,6 +158,8 @@ Each item: implement → tests → update progress. Mark `[x]` when tests green.
|
||||
|
||||
Append-only record of completed iterations. Loop writes one line per iteration: date, what was done, test count delta.
|
||||
|
||||
- 2026-05-09 — **`Function.prototype.call` / `apply` substitute global as `this` when caller passes null/undefined.** Per non-strict ES, `f.apply(null)` and `f.call(undefined)` should bind `this` to the global object inside `f`. We were passing `null`/`undefined` straight through to `js-call-with-this`, so `this.field = "green"` (the test pattern) silently failed because the function's `this` was still undefined and `this.field` did nothing. Updated both clauses in `js-invoke-function-method` to swap in `js-global-this` when the caller's `this`-arg is null or `:js-undefined`. Result: built-ins/Function/prototype 4/30 → 11/30 (+7), apply 0+ → 12/30, call 0+ → 7/30. Object 30/30 holds. conformance.sh: 148/148.
|
||||
|
||||
- 2026-05-09 — **`js-global` exposes more built-in constructors and helpers.** Was missing `Function` (so `typeof this.Function === "undefined"`), the seven Error subclasses, the URI helpers, `eval`, `Promise`, and stubs for `Symbol` / `AggregateError` / `SuppressedError`. Added all of them. Did NOT add `globalThis` as a self-reference — that creates a cycle which makes `inspect` (used by `js-ctor-id`) hang on every error path that tries to format a constructor identity. Result: built-ins/global 19/29 → 22/27. Object 30/30, property-accessors 14/21 unchanged. conformance.sh: 148/148.
|
||||
|
||||
- 2026-05-09 — **Top-level expression statements support the comma operator.** Was using `jp-parse-assignment` for the expression in `jp-parse-stmt`'s fallback branch, so `false, true;` raised "Unexpected token: punct ','". Switched to `jp-parse-comma-seq`, which already returns either a plain assignment (no comma seen) or a `js-comma` AST. Per spec, ExpressionStatement → Expression, and Expression includes the comma operator. Result: language/expressions/comma 1/5 → 3/5, language/statements 22/30 → 23/30. Object/Array/Map unchanged. conformance.sh: 148/148.
|
||||
|
||||
Reference in New Issue
Block a user