Skip to content

JS engine: eval, with and the Function constructors (7.7 to 7.9) - #306

Open
atiernan wants to merge 7 commits into
mainfrom
claude/js-eval-with
Open

atiernan wants to merge 7 commits into
mainfrom
claude/js-eval-with

Conversation

@atiernan

@atiernan atiernan commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Phase 7, items 7.7 to 7.9: the dynamic-code parts of the engine. eval (direct and indirect), with, delete of a variable, and the Function, GeneratorFunction, AsyncFunction and AsyncGeneratorFunction constructors now run.

It was cut from claude/js-generators-async (#304, now merged), and main is merged in.

Commits of this PR

  1. Spec first (clazel-js-vm/src/ops.rs): DirectEval's text now says what its handler does with the compiled eval code. No op is added: the ops for with, delete and direct eval were already in the spec, with their proofs and certified mutations; only the handler op's prose changed (the EvalDeclarationInstantiation steps the handler does, the parameter scope of the record). PerformEval, EvalDeclarationInstantiation, the global environment's operations and CreateDynamicFunction were read at the pinned ECMA-262 commit, so those citations have no †.
  2. clazel-js-syntax: exec::parse_eval, a Script with its caller's early errors (PerformEval steps 11.e to 11.h and 12, and private names of the classes around the call).
  3. clazel-js-vm: the interpreter runs WithHas/WithGet/WithSet/WithDelete, DeleteGlobal, DirectEval/DirectEvalSpread; compile::compile_eval (scope analysis puts the caller's recorded scopes around the eval code; completion values; the EvalDeclarationInstantiation split between compiler, handler and the code's prologue); compile::compile_dynamic_function; Vm::perform_eval and Vm::create_dynamic_function. Its differences from the standard are listed at the top of src/eval.rs and in compile.rs's header.
  4. clazel-js-builtins: global eval is %eval%; the four constructors call CreateDynamicFunction instead of throwing NotYet.
  5. Test262: vendored built-ins/eval, language/eval-code, language/statements/with and built-ins/Function from the pinned commit (all but one CR-only file the table's reader cannot read; SOURCE.md says so).

Test262 (conformance_builtins)

Directory pass expected failure fail
built-ins/eval 10 0 0
language/eval-code 342 5 (4 module, 1 negative) 0
language/statements/with 156 25 (16 negative parse tests, Proxy, proxyTrapsHelper) 0
built-ins/Function 379 129 0
built-ins/GeneratorFunction 19 4 0
built-ins/AsyncFunction 16 2 0
built-ins/AsyncGeneratorFunction 20 3 0

Whole suite: 3,984 pass, 4,576 expected failures, 0 failures of 8,560. The four tests that were expected failures because eval was missing now pass, and their entries are gone. The new expected failures in built-ins/Function are each listed with the reason: %Function.prototype% is an ordinary object (not callable, no caller/arguments accessors, no toString), a difference the built-ins already listed.

Not done

  • The mapped arguments object (CreateMappedArgumentsObject) is still unmapped: it needs an exotic object in the heap's property paths, not a small step from this work. Its two expected failures stay.
  • No new op, so no new Kani harness or certified mutation; the handler is Tier 0 code, as the crate is.

Verification

cargo xtask verify --changed: see the comment below for its last line once it finishes. CI's full verification has not run yet; the proof jobs need a reviewer's approval.

🤖 Generated with Claude Code

atiernan and others added 6 commits November 25, 2026 02:46
…l do it

The op's text now says what the handler does with the compiled eval code:
the EvalDeclarationInstantiation checks and var bindings (§19.2.1.3 steps 3,
10, 12, 13 and 18) before the code runs, and the code's prologue
instantiating the functions (step 17) into varEnv. Step numbers of PerformEval
(§19.2.1.1) checked against the pinned ECMA-262 text; no op is added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PerformEval (ECMA-262 §19.2.1.1) parses eval code as a Script, then makes
new.target, super.x, super() and arguments early errors where the caller
does not allow them (steps 11.e to 11.h) and strict where the caller is
(step 12); EvalDeclarationInstantiation checks private names against the
caller's classes (steps 4 to 7). exec::parse_eval runs the same parser and
checks with early::check_in and an EvalContext; check and parse are the
default context. Not part of the spec's early errors, so only tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The interpreter runs the ops the compiler already emitted for with and
direct eval: WithHas, WithGet, WithSet and WithDelete (the Object
Environment Record, §9.1.1.2), DeleteGlobal (§9.1.1.4.7), and DirectEval
and DirectEvalSpread (§13.3.6.1 step 6), whose handler is PerformEval
(§19.2.1.1). Vm::perform_eval is the indirect eval for %eval% (a new
Intrinsic), and Vm::create_dynamic_function is CreateDynamicFunction
(§20.2.1.1.1) for the Function constructors.

The host compile path is compile::compile_eval: scope analysis puts the
record's scopes of the caller around the eval code (scope::analyze_eval), so
its names resolve as a nested function's do, and its this, new.target and
super through the caller's bindings. The main function returns the
completion value (§6.2.4.4 UpdateEmpty, per statement). The work of
EvalDeclarationInstantiation (§19.2.1.3) is split as the op's text says:
the compiler finds step 3.d's conflicts and lists the declarations, the
handler checks and makes the varEnv bindings, the code's prologue stores
the functions. A call in parameter expressions records the function's scope
as a parameter scope (§10.2.11 step 20). compile_dynamic_function compiles
the function of the source text CreateDynamicFunction built, which is
parsed once and checked to be exactly that one declaration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The global eval is %eval% (§19.2.1), calling the VM's PerformEval; Function,
GeneratorFunction, AsyncFunction and AsyncGeneratorFunction (§20.2.1.1,
§27.3.1.1, §27.7.1.1, §27.4.1.1) call the VM's CreateDynamicFunction instead
of throwing NotYet. tests/dynamic_code.rs runs direct and indirect eval,
with, delete of a variable and the four constructors through the built-ins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the pinned commit: test/built-ins/eval, test/language/eval-code,
test/language/statements/with and test/built-ins/Function, but one file
whose lines end in CR alone, which the table's frontmatter reader does not
read (SOURCE.md says so). The table is regenerated: 8,560 tests.

conformance_builtins runs them: the four tests that were expected failures
because eval was missing now run and pass; the Function tests that fail for
the listed differences of %Function.prototype% (an ordinary object, without
the caller and arguments accessors, without toString) are expected failures
with those reasons; and the directories of code compiled at run time are
counted each on its own. conformance_interp, which installs no built-ins,
keeps its eval entries with their reason reworded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and classes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@atiernan
atiernan deployed to full-verification November 25, 2026 04:23 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
full-verification — ce14f8d2 Deployed Nov 25, 2026 by atiernan via Approve the proofs #828
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant