fix(codegen): typeof of native-module methods is "function" (#1343) - #1415
Merged
Conversation
typeof crypto.randomBytes (and any native-module method read as a value) returned "undefined": the member is only addressable through the call- dispatch arms, so reading it as a plain value yields the module's 0.0 stub, which js_value_typeof classifies as undefined/number. Add a NativeModuleRef arm to the typeof short-circuit in literals_vars.rs: look the member up in the API manifest and emit "function" for Method/Class entries. Properties fall through (None) so their materialized value types correctly — process.pid stays "number", os.EOL "string", crypto.constants "object". General fix: any manifest-registered native method now reports "function" (crypto.*; process.* once those methods are registered). Verified vs `node --experimental-strip-types`: typeof of randomBytes / createHash / randomUUID / pbkdf2Sync / scryptSync / timingSafeEqual / getHashes is "function", crypto.constants is "object", and call-result / string regressions are unchanged. Closes #1343
proggeramlug
force-pushed
the
fix/native-method-typeof-1343
branch
from
May 22, 2026 18:51
96d0697 to
988494b
Compare
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.
typeof crypto.randomBytes(and any native-module method read as a value, not called) returned"undefined". The member is only addressable through the call-dispatch arms, so reading it as a plain value yields the module's0.0stub, whichjs_value_typeofclassifies asundefined/number.Fix
Add a
NativeModuleRefarm to thetypeofshort-circuit inexpr/literals_vars.rs: look the member up in the API manifest (perry_api_manifest::module_has_symbol) and emit"function"forMethod/Classentries. Properties fall through (None) so their materialized value types correctly —process.pidstays"number",os.EOL"string",crypto.constants"object".General fix: any manifest-registered native method now reports
"function". Coverscrypto.*today;process.*methods benefit automatically once they're registered (currently several aren't, which is a separate gap — they hit the #463 gate before typeof).Validation
Byte-for-byte vs
node --experimental-strip-types:typeofofrandomBytes/createHash/randomUUID/pbkdf2Sync/scryptSync/timingSafeEqual/getHashes→"function"typeof crypto.constants→"object"(property, falls through)typeof crypto.randomUUID()→"string",typeof crypto.randomBytes(4).toString('hex')→"string"Codegen-only; no manifest/runtime change.
Closes #1343