fix(hir): brand-check typed Number/Boolean prototype .call (#4100)#4124
Merged
Conversation
#4112 fixed the reflective (as-any / computed-key) form of Number/Boolean/Symbol/BigInt prototype brand checks, but a residual remained for the statically-typed member-access form: Number.prototype.valueOf.call({}) // returned "[object Object]" Boolean.prototype.toString.call({}) // instead of throwing TypeError The typed `.call`/`.apply` was folded by try_builtin_prototype_method_apply_call into `x.<method>()`, routing through the lenient codegen fast-path / Object.prototype fallback and bypassing the installed brand-check thunk. Guard the fold (and the const-extracted-local fold in as_builtin_proto_method_ref) for Number.prototype's valueOf/toString/toLocaleString and Boolean.prototype's valueOf/toString so they stay reflective and hit the thunk — mirroring the existing Function.prototype.toString guard (#4101). toFixed/toExponential/toPrecision are deliberately NOT guarded: the fold is the correct path for them (their reflective dispatch over-throws on a valid receiver), and only the brand-checked methods are affected. Symbol/BigInt have no codegen fold path, so they need no guard. Verified byte-identical to node --experimental-strip-types in both auto-optimize and PERRY_NO_AUTO_OPTIMIZE modes.
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.
#4100 residual — typed
.callon Number/Boolean prototype methods#4112 fixed the reflective (
as any/ computed-key) form of theNumber/Boolean/Symbol/BigInt prototype brand checks, but a residual remained
for the statically-typed member-access form, verified on
main:Root cause
try_builtin_prototype_method_apply_call(HIR) folds a typed<recv>.<method>.call(x)intox.<method>(). That routes through the lenientcodegen fast-path /
Object.prototypefallback and never reaches thebrand-check thunk installed by #4112. The
as any/ computed-key forms aren'tfolded, so they already throw correctly.
Fix
Guard the fold (and the const-extracted-local fold in
as_builtin_proto_method_ref) soNumber.prototype'svalueOf/toString/toLocaleStringandBoolean.prototype'svalueOf/toStringstay reflective and hit the thunk — mirroring the existingFunction.prototype.toStringguard (#4101).toFixed/toExponential/toPrecisionare deliberately not guarded: thefold is the correct path for them (their reflective dispatch over-throws on a
valid receiver), and only the brand-checked methods are affected. Symbol/BigInt
have no codegen fold path, so they need no guard.
Verification
test-files/test_gap_4100_primitive_proto_brand_check.tsextended with thetyped-
.call/.apply, extracted-local, valid-receiver, and toFixed/toExponentialno-regression cases.
node --experimental-strip-typesin both auto-optimize andPERRY_NO_AUTO_OPTIMIZEmodes..callfolds unchanged;cargo test -p perry-hirgreen.Closes #4100.