Skip to content

Support this in script functions - #12

Merged
NetWin merged 5 commits into
incrementfrom
feat/this
Oct 20, 2026
Merged

NetWin merged 5 commits into
incrementfrom
feat/this

Conversation

@NetWin

@NetWin NetWin commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Script functions get JavaScript's strict-mode this. Constructors and prototypes stay unsupported.

What changed

  • this is the object of a method call, undefined for a plain call and at the top level, and whatever call,
    apply and bind pass. Arrows take it from the enclosing function.
  • Array callbacks, Array.from and the forEach of Map and Set take a thisArg.
  • A JSON reviver and replacer get the holder as this. A reviver no longer receives the holder as a third argument.
  • Commit scopes name the area changed instead of the package.

A function that is not an arrow gets strict-mode this: the object of a
method call, undefined for a plain call, and the receiver call, apply
and bind pass, never boxed. An arrow sees the this of the function it is
written in. At the top level this is undefined, since there is no global
object.

Host functions and intrinsics still receive no this. Constructors and
prototypes stay unsupported.
every, filter, find, findIndex, findLast, findLastIndex, flatMap,
forEach, map, some, Array.from and the forEach of Map and Set call their
callback with the thisArg as this. Every other built-in callback keeps
undefined.
A reviver no longer receives the holder as a third argument; it is this
instead, as in JavaScript. Use this where a reviver read the third
argument.
A function replacer is called with the object holding the key as this,
and with a fresh object around the value at the top level, as in
JavaScript.
Copilot AI lite review requested due to automatic review settings October 20, 2026 20:04
@github-actions

Copy link
Copy Markdown

馃搵 Release Preview

Changelog

0.4.0 (2026-10-20)

馃殌 Features

  • builtins: pass thisArg to array, Map and Set callbacks (80e5ccb)
  • evaluator: support this in script functions (f90237d)
  • json: give a JSON replacer its holder as this (d1c1e20)
  • json: give a JSON reviver its holder as this (7ed2e5f)

馃摉 Documentation

  • contributing: update conventional commit instructions (8cc9c43)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃數 Needs a closer look

The broad evaluator, builtin, sandbox, and parity changes warrant final human review.

No open issues 馃帀

What changed in this PR

Adds strict-mode this support for Maple script functions, callbacks, and JSON hooks while preserving sandbox isolation.

Changes:

  • Tracks receivers through scopes, methods, arrows, and function calls.
  • Adds thisArg support across array, Map, and Set callbacks.
  • Updates JSON behavior, parity coverage, documentation, and contributor guidance.
File Summary
packages/鈥媘aple/鈥媠rc/鈥媏valuator/鈥媠cope.ts Tracks lexical receivers.
packages/鈥媘aple/鈥媠rc/鈥媏valuator/鈥媠cope.spec.ts Tests receiver scope behavior.
packages/鈥媘aple/鈥媠rc/鈥媏valuator/鈥媐unctions.spec.ts Tests function receiver semantics.
packages/鈥媘aple/鈥媠rc/鈥媏valuator/鈥媏valuator.ts Propagates receivers during evaluation and calls.
packages/鈥媘aple/鈥媠rc/鈥媏scapes.spec.ts Tests receiver sandbox isolation.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媠et/鈥媠et.spec.ts Tests Set callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媠et/鈥媘ethods/鈥媐or-each.ts Supports Set thisArg.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媘ap/鈥媘ethods/鈥媐or-each.ts Supports Map thisArg.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媘ap/鈥媘ap.spec.ts Tests Map callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媕son/鈥媠tatics/鈥媠tringify.ts Supplies replacer holders as this.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媕son/鈥媠tatics/鈥媝arse.ts Supplies reviver holders as this.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媕son/鈥媕son.spec.ts Tests JSON receiver behavior.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媢tils/鈥媋rray-callback.ts Supports callback receiver handling.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媠tatics/鈥媐rom.ts Supports Array.from thisArg.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媠ome.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媘ap.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媐or-each.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媐lat-map.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媐ind.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媐ind-last.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媐ind-last-index.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媐ind-index.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媐ilter.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媘ethods/鈥媏very.ts Passes array callback receivers.
packages/鈥媘aple/鈥媠rc/鈥媌uiltins/鈥媋rray/鈥媋rray.spec.ts Tests array callback receivers.
packages/鈥媘aple/鈥媎ocs/鈥媠ecurity.md Documents receiver isolation.
packages/鈥媘aple/鈥媎ocs/鈥媗anguage.md Documents script-function this.
packages/鈥媘aple/鈥媎ocs/鈥媏xtending.md Documents host and intrinsic receiver behavior.
packages/鈥媘aple/鈥媎ocs/鈥媎ivergences.md Updates documented divergences.
packages/鈥媘aple/鈥媎ocs/鈥媌uiltins.md Documents callback thisArg support.
packages/鈥媘aple-parity/鈥媠rc/鈥媎ivergences.spec.ts Tests intentional engine divergences.
packages/鈥媘aple-parity/鈥媠rc/鈥媍ases/鈥媐unctions.spec.ts Adds parity coverage for this.
packages/鈥媘aple-parity/鈥婻EADME.md Updates parity documentation.
CONTRIBUTING.md Updates commit-scope guidance.
AGENTS.md Updates repository conventions.

Review effort: Lite

@NetWin
NetWin marked this pull request as ready for review October 20, 2026 20:12
@NetWin
NetWin merged commit 0804400 into increment Oct 20, 2026
8 checks passed
@NetWin
NetWin deleted the feat/this branch October 20, 2026 20:13
@NetWin NetWin mentioned this pull request Oct 21, 2026
@github-actions

Copy link
Copy Markdown

馃帀 This PR is included in version 0.4.0 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants