Fix ShadowRealm.prototype.evaluate rejecting super and new.target in nested code#2573
Merged
Merged
Conversation
…nested code ShadowScriptValidator visited the entire AST and threw for any `super` node, so evaluate() rejected legal scripts such as classes whose methods use super. Per PerformShadowRealmEval, the Contains static semantics must not descend into nested function bodies or class element values - only top-level SuperProperty/SuperCall/NewTarget are forbidden, and the required exception type is SyntaxError, not TypeError. The validator now mirrors Contains: it skips function declarations and expressions (covering object and class method bodies), class field and accessor values and static blocks, while still descending into arrow functions (transparent for super/new.target), class heritage expressions, decorators and computed property names. It also implements the previously missing NewTarget check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 6, 2026
This was referenced Jul 13, 2026
This was referenced Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ShadowRealm.prototype.evaluate(and the .NETShadowRealm.Evaluateoverloads) rejected any script containingsuper, no matter where it appeared.ShadowScriptValidatorwalked the whole AST with an unrestricted visitor, so perfectly legal code was refused:This made ShadowRealm unusable for any real-world bundle that defines classes (surfaced in the #2569 discussion, where evaluating a page bundle "would stop on
evaluateas the code containssuper").Spec
PerformShadowRealmEval steps:
where Contains does not descend into nested function bodies or class element values (those have their own home object, making
superlegal there). It only descends into arrow functions (transparent forsuper/new.target), class heritage expressions and computed property names. The exception type isSyntaxError, not theTypeErrorpreviously thrown.Fix
ShadowScriptValidatornow mirrors the Contains semantics:FunctionDeclaration/FunctionExpressionsubtrees (this also covers object-literal and class method/getter/setter bodies, whose values are function expressions)staticblocks, while still visiting decorators and computed property namessuper/new.targetsmuggled through an arrow is caughtSyntaxError(caller realm) instead ofTypeErrorNewTargetcheckTests
Jint.Tests.PublicInterface/ShadowRealmTestscases:superin derived-class methods/constructors/getters, static methods, field initializers, static blocks and object-literal methods (string andPrepared<Script>paths), plus negative top-levelsuper/super()/new.targetcases assertingSyntaxError--filter ShadowRealm: 124/124 passingJint.TestsandJint.Tests.PublicInterfacesuites green (one pre-existing, unrelated wall-clock flake inTimeSystemTests.CanUseTimeProvideron net472 that also fails on unmodified main)🤖 Generated with Claude Code