Commit f8c259c
* fix(hir): #5579 — publish module-top global eval's top-level var/function as configurable global bindings
EvalDeclarationInstantiation: a sloppy *global* (direct or indirect) eval whose
body declares a top-level `var` or `function` must create a configurable own
binding on the global object (CreateGlobalVarBinding / CreateGlobalFunctionBinding)
that survives after the eval returns. Perry folds an eval body into a
scope-capturing arrow IIFE, which trapped top-level `var`/`function` as
arrow-locals, so `eval('var x; …')` / `eval('function f(){}')` never published
`x`/`f` to globalThis (test262 reason: "x/f should be an own property"). #5636
already handled *nested* block functions; this extends the same hoist to the eval
body's own top level.
- global_eval_hoist: a top-level `function` is renamed to a hidden binding and
published with its value at instantiation via `void (f = <hidden>)` (the `void`
keeps the declaration's empty completion value); a top-level `var x = init`
becomes a create-if-absent global slot plus `void (x = init)`. A non-simple
(destructuring) declarator bails the rewrite.
- const_fold_fn: a declaration-bearing *indirect* eval body at module-top global
with nothing to hoist now still folds to the completion IIFE (running its side
effects + yielding the completion value) instead of deferring to the runtime
eval thunk, which returns `undefined` without executing the body. Guarded by
`eval_body_iife_foldable`, which keeps a class-declaring body on the runtime
thunk (Perry would otherwise leak the class to module scope —
language/eval-code/indirect/lex-env-distinct-cls).
test262 language/eval-code + annexB/language/eval-code: 753 → 764 passing
(parity 93.2% → 94.6%), zero regressions. Fixes var-env-{var,func}-init-global-new
(direct+indirect), var-env-func-init-multi (direct+indirect),
var-env-func-init-global-update-non-configurable, and the
non-definable-function-with-{function,variable} negatives.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(hir): #5579 — CreateGlobalFunctionBinding for eval'd top-level functions (descriptor-correct global publish)
Follow-up to the top-level var/function eval publishing: a top-level function in
a sloppy global eval is now published with the spec's CreateGlobalFunctionBinding
descriptor rules instead of a bare `void (f = <hidden>)` assignment. An absent or
configurable global binding is (re)defined as a writable, enumerable, configurable
data property; a non-configurable one keeps its attributes and only takes the new
value. This makes the published descriptor correct when the eval redefines an
existing *configurable* global whose attributes differ (e.g. a non-enumerable,
non-writable `f`).
`apply_global_eval_hoist` now also bails (→ unmodified fold) when the eval body
rebinds `Object` at function scope, since the publish reads `Object.defineProperty`
/ `Object.getOwnPropertyDescriptor`.
test262 language/eval-code + annexB/language/eval-code: 764 → 766 passing
(parity 94.6% → 94.8%), zero regressions. Fixes
var-env-func-init-global-update-configurable (direct + indirect).
(The non-definable-global-{function,generator} negatives remain: Perry does not
model `NaN`/`undefined` as non-configurable own properties of globalThis, so the
illegal redefinition does not throw — a separate globalThis-modeling gap.)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Ralph <ralph@skelpo.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9fb1940 commit f8c259c
2 files changed
Lines changed: 422 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
778 | 778 | | |
779 | 779 | | |
780 | 780 | | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
791 | 806 | | |
792 | 807 | | |
793 | 808 | | |
| |||
854 | 869 | | |
855 | 870 | | |
856 | 871 | | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
857 | 926 | | |
858 | 927 | | |
859 | 928 | | |
| |||
1593 | 1662 | | |
1594 | 1663 | | |
1595 | 1664 | | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
0 commit comments