Guidance on implementing atomic global and eval declaration instantiation (issue 4628)

31 views
Skip to first unread message

Temiloluwa

unread,
Oct 20, 2026, 3:52:10 AMOct 20
to v8-dev

Hi V8 Devs

I investigated the six Test262 failures currently grouped under the issue id 4628


These tests verify that global or eval declaration instantiation validates the relevant declarations before creating their bindings. For example, when eval code contains a declaration before an invalid function NaN() {}, V8 throws for NaN but leaves the preceding binding installed.


This is inconsistent with ECMA 262’s GlobalDeclarationInstantiation and EvalDeclarationInstantiation. Both perform the relevant CanDeclareGlobalFunction and CanDeclareGlobalVar checks before creating the corresponding bindings. 



ECMA-262 separates declaration processing into two stages. First, it checks whether all relevant function and variable declarations are permitted. Only after those checks succeed does it create their bindings. Therefore, if a later declaration conflicts with an existing global binding, none of the earlier declarations from the same script or eval should be installed.


V8 currently processes some global declarations one at a time in Runtime_DeclareGlobals. For each declaration, DeclareGlobal checks that single declaration and immediately creates its global property. As a result, V8 can create an earlier binding before discovering that a later declaration is invalid. Sloppy direct eval has a separate implementation with individual DeclareEvalVar and DeclareEvalFunction runtime calls, but it exhibits the same ordering problem.


ECMA 262 requires validation must precede instantiation, and failed validation must not leave earlier bindings installed. Implementing that behavior appears to require separating validation from instantiation in both V8 paths.


The implementation detail I am uncertain about is global-object interceptors. DeclareGlobal intentionally handles interceptors and test/unittests/parser/decls-unittest.cc verifies their observable query and set behavior. A straightforward implementation that validates all declarations and then repeats the property lookups during instantiation could invoke a stateful interceptor twice.


For the internal V8 design, is it recommended retaining the results of the validation lookups and reusing them during instantiation to avoid repeated interceptor calls? or is there an existing V8 architecture or approach that should be used. 


Reply all
Reply to author
Forward
0 new messages