Add default builtin shims for legacy globals#330
Conversation
- Move atob, btoa, parseInt, parseFloat, and Date into shims - Register shim names in Goccia.shims and add coverage tests
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
💤 Files with no reviewable changes (2)
📝 WalkthroughWalkthroughThis PR migrates native Changes
Sequence Diagram(s)sequenceDiagram
participant Engine
participant Backend
participant Shims
participant Interpreter
participant Parser
participant Scope as Global Scope
Engine->>Backend: RegisterBuiltIns()
Backend->>Shims: RegisterDefaultShimNames(FShims)
Note over Shims: Populates string list with<br/>shim names
Backend->>Interpreter: Create interpreter instance
Backend->>Shims: ExecuteShims()
loop For each default shim (0..DefaultShimCount-1)
Shims->>Shims: DefaultShim(Index)
Shims->>Parser: Lex & parse Shim.Source
Parser->>Shims: Return parsed program
Shims->>Scope: Create child module scope<br/>(skModule)
Shims->>Interpreter: Evaluate program in<br/>module scope
Interpreter->>Scope: Execute statements
Scope->>Shims: Return exported value<br/>(Shim.Name)
Shims->>Scope: Define lexical binding<br/>(Shim.Name = value)
end
Note over Engine,Scope: Shims now available as<br/>global constants
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Benchmark Results364 benchmarks Interpreted: 🟢 89 improved · 🔴 74 regressed · 201 unchanged · avg -2.8% arraybuffer.js — Interp: 🟢 3, 11 unch. · avg +0.2% · Bytecode: 🟢 1, 🔴 7, 6 unch. · avg -3.0%
arrays.js — Interp: 🟢 4, 🔴 3, 12 unch. · avg +0.9% · Bytecode: 🔴 19 · avg -7.8%
async-await.js — Interp: 🟢 1, 5 unch. · avg +0.9% · Bytecode: 🔴 6 · avg -7.9%
base64.js — Interp: 🔴 10 · avg -98.2% · Bytecode: 🔴 10 · avg -98.5%
classes.js — Interp: 🟢 2, 29 unch. · avg +0.3% · Bytecode: 🟢 2, 🔴 11, 18 unch. · avg -2.7%
closures.js — Interp: 🟢 2, 🔴 2, 7 unch. · avg +0.9% · Bytecode: 🔴 11 · avg -8.6%
collections.js — Interp: 🟢 9, 3 unch. · avg +1.9% · Bytecode: 🔴 12 · avg -7.2%
destructuring.js — Interp: 🟢 5, 17 unch. · avg +2.3% · Bytecode: 🔴 19, 3 unch. · avg -6.0%
fibonacci.js — Interp: 🔴 1, 7 unch. · avg -0.2% · Bytecode: 🔴 6, 2 unch. · avg -9.9%
float16array.js — Interp: 🟢 8, 🔴 2, 22 unch. · avg +0.9% · Bytecode: 🟢 5, 🔴 20, 7 unch. · avg -7.4%
for-of.js — Interp: 🟢 1, 6 unch. · avg +1.1% · Bytecode: 🟢 1, 🔴 4, 2 unch. · avg -3.4%
helpers/bench-module.js — Interp: 0 · Bytecode: 0
iterators.js — Interp: 🔴 32, 10 unch. · avg -3.8% · Bytecode: 🟢 3, 🔴 20, 19 unch. · avg -3.3%
json.js — Interp: 🟢 5, 15 unch. · avg +1.9% · Bytecode: 🔴 13, 7 unch. · avg -5.0%
jsx.jsx — Interp: 🟢 1, 🔴 1, 19 unch. · avg -0.4% · Bytecode: 🔴 20, 1 unch. · avg -8.0%
modules.js — Interp: 🟢 2, 7 unch. · avg +0.6% · Bytecode: 🔴 7, 2 unch. · avg -10.2%
numbers.js — Interp: 🟢 9, 2 unch. · avg +5.1% · Bytecode: 🔴 8, 3 unch. · avg -5.8%
objects.js — Interp: 🔴 1, 6 unch. · avg -1.6% · Bytecode: 🟢 1, 🔴 3, 3 unch. · avg -1.9%
promises.js — Interp: 🟢 2, 🔴 5, 5 unch. · avg -1.7% · Bytecode: 🔴 12 · avg -8.6%
regexp.js — Interp: 🟢 6, 5 unch. · avg +2.7% · Bytecode: 🔴 9, 2 unch. · avg -5.5%
strings.js — Interp: 🟢 2, 🔴 14, 3 unch. · avg -27.1% · Bytecode: 🟢 4, 🔴 9, 6 unch. · avg -2.1%
typed-arrays.js — Interp: 🟢 20, 2 unch. · avg +4.8% · Bytecode: 🟢 5, 🔴 14, 3 unch. · avg -2.8%
uint8array-encoding.js — Interp: 🟢 7, 🔴 3, 8 unch. · avg +16.4% · Bytecode: 🟢 3, 🔴 12, 3 unch. · avg -1.9%
Measured on ubuntu-latest x64. Benchmark ranges compare cached main-branch min/max ops/sec with the PR run; overlapping ranges are treated as unchanged noise. Percentage deltas are secondary context. |
Suite Timing
Measured on ubuntu-latest x64. |
Summary
Goccia.Shims) that provides backwards-compatible legacy globals on top of modern native APIsexport constmodule evaluated during engine bootstrap; exported values are bound into the global scope viaDefineLexicalBindingGoccia.shimsfor introspectionatob/btoaimplementation (~200 LOC) in favor of GocciaScript shims backed byUint8Array.fromBase64/toBase64parseInt/parseFloatshims delegating toNumber.parseInt/Number.parseFloatDateshim class backed byTemporal.Instant,Temporal.ZonedDateTime, andTemporal.PlainDateTimeShim registry
btoaUint8Array.prototype.toBase64atobUint8Array.fromBase64parseIntNumber.parseIntparseFloatNumber.parseFloatDateTemporal.*Adding a new shim is one record entry in
DEFAULT_SHIMS.Test plan
atob/btoatests pass (28 assertions)parseInt/parseFloatidentity tests passDateconstructor and method tests pass (40 assertions)Goccia.shimsintrospection test updated🤖 Generated with Claude Code