ISSUE DESCRIPTION Node API checker: namespace reads of absent builtin exports should…
- User
ISSUE DESCRIPTION
Node API checker: namespace reads of absent builtin exports should return undefined
Summary
Perry's strict built-in API gate currently rejects some namespace property reads that Node treats as ordinary JavaScript property misses returning
undefined.This surfaced in the curated DNS constants fixture on current
origin/main@22824ba90abf:node:dns/promisesintentionally does not exportADDRCONFIG,V4MAPPED, orALL, but reading those properties from the namespace object is valid in Node and returnsundefined. Perry rejects the property read at check/lower time before the runtime can produce the matching value.This is separate from named ESM import validation. Node rejects
import { ADDRCONFIG } from "node:dns/promises", and Perry should continue not claiming that named export. The compatibility gap is namespace/property-read semantics.Local evidence
Current main:
22824ba90abf Expose globalThis.EventTarget (#3628)Node v25.9.0 behavior for the namespace object:
$ node -e 'import("node:dns/promises").then(m=>{for (const k of ["ADDRCONFIG","V4MAPPED","ALL","NODATA","CANCELLED"]){console.log(k, Object.prototype.hasOwnProperty.call(m,k), k in m, typeof m[k], m[k]);}})' ADDRCONFIG false false undefined undefined V4MAPPED false false undefined undefined ALL false false undefined undefined NODATA true true string ENODATA CANCELLED true true string ECANCELLEDNode rejects the corresponding named import, which is correct and should remain true:
$ node --input-type=module -e 'import { ADDRCONFIG } from "node:dns/promises"; console.log(ADDRCONFIG)' SyntaxError: The requested module 'node:dns/promises' does not provide an export named 'ADDRCONFIG'Perry currently rejects the namespace property read in the curated fixture:
$ target/release/perry check test-parity/node-suite/dns/constants/error-aliases.ts error[U006]: `dns/promises.ADDRCONFIG` is not implemented in Perry — see `perry --print-api-manifest` for the supported surface, or set `PERRY_ALLOW_UNIMPLEMENTED=1` to ignore. (#463) --> test-parity/node-suite/dns/constants/error-aliases.ts:9:48The manifest matches Node for named exports:
dns/promisesincludes DNS error aliases likeNODATAandCANCELLED, but does not includeADDRCONFIG,V4MAPPED, orALL.With the gate bypassed, Perry's runtime output matches Node for this fixture, including the absent namespace properties:
Assistant
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me explore the repository structure more thoroughly, focusing on the area mentioned in the issue.
Assistant
Let me search for the specific section that handles native module property reads:
Assistant
Now let me look at the
module_has_any_entriesandmodule_has_symbolfunctions:Assistant
Now let me look at the test fixture mentioned in the issue:
Assistant
Let me try to build and reproduce the issue first:
Assistant
Now let me look at the broader context around line 1813 in expr_member.rs:
Assistant
Let me look at how
NativeModuleRefis used inexpr_call:Assistant
Now let me look at how
PropertyGetis handled in codegen when the object is aNativeModuleRef:Assistant
Now let me check the call gate path. Let me look at how calls are made via
NativeModuleRef:Assistant
Now I have a clear picture. The fix is:
- In the gate at line 1813 in
expr_member.rs, whenobj_is_named_importisfalseAND the receiver is a namespace import (import * as ...), we want to allow the property read to returnundefined.
But wait, the issue says we want the gate to fire for actual calls. Let me think again...
Looking at the gate, it's currently triggered for any property read. The issue is that we want it to NOT trigger for plain property reads of absent members, only for calls.
Looking at
expr_call, the typical call todnsPromises.notARealMethod()would be:Call { callee: PropertyGet { object: NativeModuleRef("dns/promises"), property: "notARealMethod" }, ... }
When this is lowered in
lower_call, the receiver is lowered first, then we look up the method. So we need to gate at the call site too.Let me look at
lower_call.rsto understand how the callside handles this:- In the gate at line 1813 in
Assistant
Let me check how PropertyGet on a NativeModuleRef is actually executed at runtime:
Assistant
Let me look at how PropertyGet works on regular objects in the runtime:
Assistant
Now let me understand what happens at runtime when we read a property of a namespace object that doesn't exist. The
js_object_get_field_by_namefunction looks up the property in the object. If not found, it should return undefined.Let me confirm this is whathappens:
Assistant
Let me look at how the property get is actually performed on a native module namespace object:
Assistant
Let me find where the property get actually happens on the namespace object to see what happens for absent keys:
Assistant
Let me check
js_native_module_property_by_nameto see what happens for absent keys:Assistant
Let me trace how
import * as dnsPromises from "node:dns/promises"is lowered:Assistant
Let me look at how
lower_callhandles the case ofdnsPromises.notARealMethod():Assistant
So for
dnsPromises.notARealMethod():lower_callfirst callslower_memberondnsPromises.notARealMethod, which would trigger the gate at line 1813 in expr_member.rs.- So if we fix the gate to skip namespace property reads, the call path would still catch it.
Let me look at this more carefully. Actually, the gate in
lower_memberis at the lowering of the entire member expressiondnsPromises.notARealMethod. This is done before we know if we're going to call it or not.So my proposed fix is:
- Don't apply the gate for namespace property reads (when receiver is
NativeModuleReffrom animport * asbinding). - The call site gate (
lower_call/native_module.rs:1311) will still catch calls to absent methods.
Actually, looking at this more carefully, let me look at the call flow:
dnsPromises.notARealMethod()isCall { callee: MemberExpr { obj: Ident("dnsPromises"), prop: Ident("notARealMethod") }, ... }.
Assistant
Let me trace
try_native_module_methodsmore thoroughly:Assistant
Let me look at how
lower_memberis used in the assignment context:Assistant
Let me look at where else
lower_memberis used:Assistant
Let me check
lookup_native_module:Assistant
Now let me check how
register_native_moduleis calledfor different kinds of imports:Assistant
Let me look at the tests for the unimplemented-API gate:
Assistant
Let me look more carefully at
module_class_static.rs:Assistant
OK, so the gate in
module_class_static.rshandles the casemod.X.Y(). Forutil.types.notReal():mod_name = "util",module_name = "util",class_name = "types",method_name = "notReal".- The gate checks
module_has_symbol("util", "types").is_none(). - If
util.typesis in the manifest (it should be, sinceutil.typesis a known sub-namespace), this gate doesn't fire.
Hmm, but the test expects the error
util.types.notReal. So the gate must be firing somewhere. Let me checknested_namespace.rssince it handles theutil.typescase:Assistant
Let me check if there's a similar gate for property writes:
Assistant
Let me check how named imports for absent exports are rejected:
Assistant
Let me check what happens currently when calling
dnsPromises.notARealMethod():Assistant
Let me now run the existing tests to see if they pass:
Assistant
Good, now let me reproduce the issue:
Assistant
Confirmed the issue. Now let me verify the bypass works:
Assistant
The clang version issue is unrelated. Let me try with a more recent clang or check the perry doctor:
Assistant
Let me look at what perry doctor says and focus on making the fix first:
Assistant
Now I have enough understanding. Let me make the fix:
Assistant
Let me check what tests might be affected by removing the gate:
Assistant
Let me check the tests in
lower/tests.rs:Assistant
Let me check the codegen path for PropertyGet on NativeModuleRef:
Assistant
Now I'll make the fix. The plan is to remove the gate in
lower_member.rsfor property reads onNativeModuleRefreceivers:Assistant
Now I'll implement the fix. The plan is to remove the gate in
lower_member.rsfor property reads onNativeModuleRefreceivers. The call sites already gate actual calls.Assistant
Now let me apply the fix. I'll replace the entire gate with a comment explaining why it's removed:
Assistant
Now I'll edit the file to replace the gate. The gate spans lines 1720-1832. Let me write the replacement carefully:
Assistant
Let me look at the exact lines I need to remove:
Assistant
Now let me apply the fix by replacing lines 1720-1832 with a comment:
Assistant
Now let me create the new content and merge it back:
Assistant
Now let me build to check if my fix compiles:
Assistant
The check passes now. Let me also verify the runtime behavior matches Node's:
Assistant
Now let me also verify that call sites still gate calls:
Assistant
The call gate still fires. Let me also verify that named imports are still rejected:
Assistant
Named imports are still rejected. Now let me also run the existing tests to see what breaks (and what still works):
Assistant
Let me look at the call test failure in detail:
Assistant
The call test fails for 7 modules: crypto, os, child_process, fs, path, path/posix, path/win32. These are the
is_handled_modulemodules. Let me check what they do:Assistant
Ah, I see the problem. The gate for "non-handled modules" fires only when the module is NOT in the
is_handled_modulelist. So forcrypto,os,child_process,fs,path,path/posix,path/win32, the gate doesn't fire.But the test expects the gate to fire for ALL modules. This is the issue mentioned in the comment:
Without this, perry/* and other native-module call sites short-circuited past the
lower_membergate that fires for the property-read formSo previously, the
lower_membergate caught these. With my fix, thelower_membergate is removed, so these are no longer caught.This is a real issue. I need to make sure the gate still fires for these modules too.
Options:
Assistant
Let me look at the call path more carefully:
Assistant
Let me look at how
try_module_static_methodshandlescrypto.foo():Assistant
Let me look at the code after line 400 in
lower_call/mod.rs:Assistant
Let me check
lower_exprfor member:Assistant
Let me look at the structure of
lower_call/mod.rs:Assistant
Let me see what's near the fall-through in
lower_call/mod.rs:Assistant
Let me look at where to add a fallback gate in
lower_call/mod.rs:Assistant
Now I understand the issue. The current
lower_membergate is the safety net for handled modules (crypto, fs, os, etc.) when their calls fall through. Let me update my approach:- Remove the gate from
lower_member.rs(fixes the bug for reads). - Add a similar gate to
lower_call/mod.rsat the fall-through point to catch unsupported calls on handled modules.
Let me first revert my change to
expr_member.rsand rethink:- Remove the gate from
Assistant
Let me take a different approach. I'll keep the gate in
lower_member.rsbut only fire it for ACTUAL CALLS (whenmember.objis in a call context). But sincelower_memberdoesn't know this, let me think differently.Actually, the cleanest fix is:
- Remove the gate from
lower_member.rs(so reads can return undefined). - Add a similar gate to the call fall-through path in
lower_call/mod.rs(so calls still error).
Let me also check what happens to the
obj_is_named_importcheck. Maybe I should also keep some gate for the read case inlower_member.rsfor specific scenarios. Let me look more carefully:- Remove the gate from
Assistant
Let me re-apply the fix to
expr_member.rs:Assistant
Now let me add a call-specific gate to
lower_call/mod.rs:Assistant
Let me look at the code structure of
try_native_module_methods:Assistant
Now I'll add a new helper function to gate unsupported calls. Let me first add it to
native_module.rs:Assistant
Now let me add a new helper function at the end of
native_module.rs:Assistant
Now let me update
lower_call/mod.rsto call this helper:Assistant
Now let me add the call to
check_native_module_call_gateat the right place. Let me look at the fall-through point:Assistant
The shell is interpreting backticks. Let me use a different approach with the edit command:
Assistant
Now let me build and test:
Assistant
Good, builds successfully. Let me verify the DNS fixture works:
Assistant
The call gate now fires for
crypto.foo()too. Let me run the unimplemented_api tests:Assistant
Per the instructions, I can ignore tests that test the old behavior. Let me verify other tests still pass:
Assistant
Let me run the full perry-hir test suite to see what passes and what doesn't:
Assistant
Let me verify a few more edge cases to make sure the fix is correct:
Assistant
Let me check why
crypto.subtle.foobar()didn't error:Assistant
Wait, looking at this more carefully:
match method { "digest" if args.len() >= 2 => { ... } "importKey" if args.len() >= 5 => { ... } ... _ => { // Unsupported subtle method — fail loudly. // ... crate::lower_bail!(...); } }So for
crypto.subtle.foobar(), the match would hit the_arm and fire the bail. But why didn't my test show that error?Let me re-run the test:
Assistant
Both errors fire correctly. Let me clean up the test file and verify more scenarios:
Assistant
Wait, this fired but with
events.foonotEventEmitter.foo. The issue is thatEventEmitteris a named import, which gets value-lowered toExpr::NativeModuleRef("events"). So when we callEventEmitter.foo(), it's effectivelyevents.foo()which fires the gate atevents.foo.This is fine because Node's
events.EventEmitteris the class, not a property. The user is callingfooon the events module, not on EventEmitter.Hmm but the user might intend to call
fooon EventEmitter. In that case, my fix doesn't catch it - but that's the existing behavior anyway.Letme verify:
Assistant
Let me now also check the
expr_member.rsfile is clean:Assistant
Let me also check that I haven't broken anything else by running the perry-codegen tests:
Assistant
All perry-codegen tests pass. Now let me also test the test-parity DNS suite:
Assistant
Let me also run a broader test suite to make sure I haven't broken anything:
Assistant
All DNS test-parity files check successfully. Now let me also verify with a script that the runtime would produce the expected output. But since we can't compile due to clang issues, let me at least check with the AST level:
Assistant
Excellent! The bogus call still errors. Now let me also test the more complex case:
Assistant
Let me also check that the existing call gates still work:
Assistant
Only
crypto.foo()is shown. Let me check what happens with the other lines. The compilation failed at the first error, so other errors are not shown. Let me checkthem individually.Assistant
The third one (
bogus.foo()) didn't error becausebogusis not a known native module (no entries in the manifest). So my new gate skips it because ofmodule_has_any_entries(module_name)check. That's correct - we don't gate unknown modules.Let me clean up the test files and verify the test cases from the issue:
Assistant
Now let me run the issue's full verification scenarios:
Assistant
The exact test from the issue passes. Let me now also test the broader issue's acceptance criteria. Let me test additional edge cases:
Assistant
Now let me verify the call gate still fires for all these modules:
Assistant
Only
crypto.bogus()is shown (since perry check stops at the first error). Let me check each one individually to confirm the gate fires:Assistant
Hmm, the cached errors are showing up. Let me clear the perry check cache oruse separate runs:
Assistant
All modules fire the call gate. Let me clean up:
Assistant
Let me check the broader test suite for any regressions:
Assistant
Only 3 tests fail, and these are tests that test the OLD behavior (reads should error). My fix changes this to match Node's behavior (reads compile, calls error). Per the instructions, I can ignore these failures.
Let me also check the perry-codegen tests pass:
Assistant
There's a linking error in
perry-runtime, but it's unrelated to my changes (it's aboutjs_fetch_with_options). Let me check if this happens without my changes:Assistant
OK so the perry-runtime tests fail even without my changes. These are unrelated to my fix. Let me restore my changes:
Assistant
Now let me run all the perry-hir tests one more time to make sure my changes are correct:
Assistant
Only 3 tests fail:
crypto_unknown_method_is_rejected(tests thatcrypto.foobarread errors)supported_module_with_unknown_member_is_rejected(tests thataxios.fooread errors)every_supported_module_rejects_bogus_member(tests that all module reads error)
These all test the OLD behavior where reads errored. Per the issue, the new behavior should be that reads compile and return undefined (matching Node). These tests should be updated, but per the instructions, I shouldn't modify existing tests.
The important test that PASSES is
every_supported_module_rejects_bogus_call, which tests that calls still error. This is the key distinction the issue wants to maintain.Let me also review my changes:
Assistant
Let me verify a few more edge cases:
Assistant
Default imports also work correctly. Let me also think about the edge case where the call uses parentheses:
Assistant
Parens work too. Let me clean up and verify the full DNS fixture works:
Assistant
Let me also check what happens with non-existent modules:
Assistant
Bogus modules are not gated, which is consistent with the existing behavior (modules without entries in the manifest don't gate).
Let me also verify my understanding by looking at how
lookup_native_moduleworks for non-existent modules:Assistant
Let me also verify a few known-good cases still work:
Assistant
All known-good cases work. Let me also check that the perry-parser and other tests pass:
Assistant
All other tests pass. Let me also verify the diff one more time to make sure everything looks good:
Assistant
Let me clean up the
callparameter in my new helper since it's unused:Assistant
My sed command messed up the file. Let me revert and do this more carefully:
Assistant
Now let me re-add the helper function with the
callparameter removed:Assistant
Now let me update the call site in
lower_call/mod.rs:Assistant
Builds successfully. Let me re-verify the tests:
Assistant
Only the 3 tests testing the OLD behavior fail. Per the issue and the instructions, this is the correct new behavior.
Let me now check the diff one more time to make sure everything is clean:
Assistant
Now let me run all relevant tests one more time:
Assistant
All other tests pass. Let me also verify some more edge cases I might have missed. Let me think about what happens for:
Assistant
Good,
dnsPromises.MISSING()correctly errors out. Let me check theother tests:Assistant
dnsPromises.NODATA()passes through (compiles), but at runtime it would throw "NODATA is not a function" since NODATA is a string. This matches Node's behavior.Let me clean up and do a final check:
Assistant
Let me also test the runtime behavior to make sure it matches Node's. Since we can't fully compile due to clang issues, let me at least check the AST:
Assistant
There's no
print-astcommand. Let me move on. The behavior should be correct.Let me also do one more sanity check - the call site gate for
crypto.subtle.foo()(3-deep):Assistant
3-deep call gate also fires correctly. Let me also make sure I haven't accidentally broken anything else by running all relevant tests:
Assistant
All other tests pass. Let me look at my final diff:
Assistant
The diff looks good. Let me now do a final verification and check my changes one more time:
Assistant
Let me do a comprehensive test to ensure the final fix is working:
Assistant
The fix is complete. Let me also make a final summary of what I changed:
Summary of Changes
Problem
Perry's strict built-in API gate was rejecting namespace property reads like
dnsPromises.ADDRCONFIGat HIR lowering time. However, Node treats these reads as ordinary JavaScript property misses returningundefined.Solution
-
crates/perry-hir/src/lower/expr_member.rs— Removed the unimplemented-API gate that was rejecting all property reads on receivers. Now reads on namespace imports (like ) compile and return at runtime, matching Node's behavior. The machinery is no longer needed.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.