Sprint 7: Script Execution Architecture — with() + eval() statt new Function() #58

Closed
opened 2026-06-18 13:11:37 +00:00 by Artur · 0 comments
Owner

Sprint 7: Script Execution Architecture (with + eval)

Issue: #57
Epic: Phase 2 Production Engine
Aufwand: ~6h
Abhängigkeit: Sprint 6 (#56) — Module-Pfad muss vorher stabil sein

Problem

new Function("_win", varDecls + code) ist die Wurzel von 3 kritischen Bugs:

  • Private Fields (#) brechen weil [[HomeObject]]-Binding verloren geht
  • const/let redeclaration weil strict mode verbietet
  • this nicht immer korrekt auf Window

Lösung

Ersetze new Function() durch with(proxyWin) { eval(code) }.

// Alt:
const fn = new Function("_win", "\"use strict\";\n" + code);
fn.call(win, win);

// Neu:
const evalCode = `with(window) { ${code} }`;
const result = (0, eval)(evalCode);  // indirekter eval → global scope

Vorteile:

  • Private Fields (#) bleiben intakt (kein IIFE-Scope-Break)
  • const/let funktionieren korrekt (sloppy mode)
  • this ist korrekt window
  • Kein varDecls String mehr nötig
  • Alle Window-Properties automatisch sichtbar (via with)

Aber: with() hat Performance-Impact → vor/nach benchmarken.

Betroffene Dateien

Datei Änderung
src/js/execution-realm.ts execute(): with+eval statt new Function()
src/js/script-loader.ts executeRaw() Fallback-Pfad
src/runtime-isolation.ts SpecProxy has-Trap prüfen
src/tolerant-proxy.ts has-Trap für alle Properties
src/js/unified-execution-layer.ts Finalisieren als einziger Entrypoint
src/interaction/evaluate.ts Delegiert an UEL.evaluate()
src/js/script-loader.ts buildVarDecls() entfernen

Akzeptanzkriterien

  • with(proxyWin) { eval(code) } — alle Window-Properties sichtbar
  • Private Fields (#) funktionieren in Scripts
  • const x = 1; const x = 1 — kein Error
  • this === proxyWindow in Scripts
  • define === undefined, module === undefined
  • evaluate.ts delegiert an UEL.evaluate()
  • buildVarDecls() entfernt (nicht mehr verwendet)
  • Performance: nicht messbar langsamer als vorher (<5%)
  • Bestehende Tests: 0 Regressionen
## Sprint 7: Script Execution Architecture (with + eval) **Issue:** #57 **Epic:** Phase 2 Production Engine **Aufwand:** ~6h **Abhängigkeit:** Sprint 6 (#56) — Module-Pfad muss vorher stabil sein ### Problem `new Function("_win", varDecls + code)` ist die Wurzel von 3 kritischen Bugs: - **Private Fields (#)** brechen weil `[[HomeObject]]`-Binding verloren geht - **`const`/`let` redeclaration** weil strict mode verbietet - **`this`** nicht immer korrekt auf Window ### Lösung Ersetze `new Function()` durch `with(proxyWin) { eval(code) }`. ```javascript // Alt: const fn = new Function("_win", "\"use strict\";\n" + code); fn.call(win, win); // Neu: const evalCode = `with(window) { ${code} }`; const result = (0, eval)(evalCode); // indirekter eval → global scope ``` **Vorteile:** - Private Fields (`#`) bleiben intakt (kein IIFE-Scope-Break) - `const`/`let` funktionieren korrekt (sloppy mode) - `this` ist korrekt `window` - Kein `varDecls` String mehr nötig - Alle Window-Properties automatisch sichtbar (via `with`) **Aber:** `with()` hat Performance-Impact → vor/nach benchmarken. ### Betroffene Dateien | Datei | Änderung | |-------|----------| | `src/js/execution-realm.ts` | `execute()`: `with`+`eval` statt `new Function()` | | `src/js/script-loader.ts` | `executeRaw()` Fallback-Pfad | | `src/runtime-isolation.ts` | SpecProxy `has`-Trap prüfen | | `src/tolerant-proxy.ts` | `has`-Trap für alle Properties | | `src/js/unified-execution-layer.ts` | Finalisieren als einziger Entrypoint | | `src/interaction/evaluate.ts` | Delegiert an UEL.evaluate() | | `src/js/script-loader.ts` | `buildVarDecls()` entfernen | ### Akzeptanzkriterien - [ ] `with(proxyWin) { eval(code) }` — alle Window-Properties sichtbar - [ ] Private Fields (#) funktionieren in Scripts - [ ] `const x = 1; const x = 1` — kein Error - [ ] `this === proxyWindow` in Scripts - [ ] `define === undefined`, `module === undefined` - [ ] evaluate.ts delegiert an UEL.evaluate() - [ ] `buildVarDecls()` entfernt (nicht mehr verwendet) - [ ] Performance: nicht messbar langsamer als vorher (<5%) - [ ] Bestehende Tests: 0 Regressionen
Artur closed this issue 2026-06-18 13:36:22 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
glow-all/true-headless-browser#58
No description provided.