js-on-sx: Function.prototype.call/apply/bind

Adds js-invoke-function-method dispatched from js-invoke-method when the
receiver is a JS function (lambda/function/component/callable-dict) and the
method name is one of call/apply/bind/toString/name/length.

call and apply bind this around a single call; bind returns a closure with
prepended args. toString returns the native-code placeholder.

6 unit tests, 450/452 total (Array.prototype.push.call with arrayLike still
fails — tracked as the 455x 'Not callable array-like' scoreboard item which
needs array methods to treat dict-with-length as a list).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 06:27:18 +00:00
parent 1774a900aa
commit 92c1fc72a5
2 changed files with 120 additions and 47 deletions

View File

@@ -1147,6 +1147,20 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 3301)
(eval "(js-eval \"var o = {a:1, b:2}; delete o.a; o.b\")")
;; ── Phase 11.fnmethod: Function.prototype.call/apply/bind ─────
(epoch 3400)
(eval "(js-eval \"function greet3(n) { return 'hi ' + n; } greet3.call(null, 'ada')\")")
(epoch 3401)
(eval "(js-eval \"function greet4(n) { return 'hi ' + n; } greet4.apply(null, ['bob'])\")")
(epoch 3402)
(eval "(js-eval \"function sum3(a,b,c) { return a+b+c; } var bnd2 = sum3.bind(null, 1, 2); bnd2(3)\")")
(epoch 3403)
(eval "(js-eval \"var obj2 = {x: 42}; function getX() { return this.x; } getX.call(obj2)\")")
(epoch 3404)
(eval "(js-eval \"function id(x) { return x; } id.apply(null, [7])\")")
(epoch 3405)
(eval "(js-eval \"var arr2 = [1,2]; Array.prototype.push.call(arr2, 10, 20); arr2.length\")")
EPOCHS
@@ -1770,6 +1784,14 @@ check 3201 "obj multi rename" '3'
check 3300 "delete obj.x" 'true'
check 3301 "delete obj.a keeps b" '2'
# ── Phase 11.fnmethod: call/apply/bind ────────────────────────
check 3400 "fn.call basic" '"hi ada"'
check 3401 "fn.apply basic" '"hi bob"'
check 3402 "fn.bind partial" '6'
check 3403 "fn.call this-binding" '42'
check 3404 "fn.apply arg-unpack" '7'
check 3405 "Array.prototype.push.call arr" '4'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "$PASS/$TOTAL JS-on-SX tests passed"