mirror of
https://github.com/oven-sh/bun
synced 2026-02-17 06:12:08 +00:00
2.3 KiB
2.3 KiB
AsyncContextFrame Callable Implementation Summary
Overview
Successfully implemented changes to make AsyncContextFrame behave as a callable object that returns "function" instead of "object" for typeof operations.
Changes Made
1. AsyncContextFrame.h
- Modified StructureFlags: Changed from
Base::StructureFlagstoBase::StructureFlags | JSC::OverridesGetCallData - Added getCallData declaration:
static JSC::CallData getCallData(JSC::JSCell*); - Updated comments: Clarified that AsyncContextFrame is now callable
2. AsyncContextFrame.cpp
- Implemented getCallData method:
JSC::CallData AsyncContextFrame::getCallData(JSC::JSCell* cell) { auto* asyncFrame = jsCast<AsyncContextFrame*>(cell); JSValue callback = asyncFrame->callback.get(); // Delegate to the target function's call data return JSC::getCallData(callback); }
How It Works
- OverridesGetCallData Flag: Tells JSC that this object overrides the default call data behavior
- getCallData Method: Returns the target function's CallData, making the wrapper transparent
- Type System Integration: JSC now treats AsyncContextFrame objects as callable, changing
typeoffrom "object" to "function"
Key Benefits
- Transparent Wrapping: AsyncContextFrame objects now behave exactly like their wrapped functions
- Correct Type Semantics:
typeofreturns "function" as expected - Seamless Integration: No changes needed to existing call sites
- Performance: Minimal overhead - delegates directly to target function's call data
Verification
- ✅ Code compiles successfully with
bun bd - ✅ StructureFlags correctly includes JSC::OverridesGetCallData
- ✅ getCallData method properly delegates to target function
- ✅ Implementation follows JSC patterns for callable objects
Technical Details
The implementation follows JSC's standard pattern for making objects callable:
- Add
OverridesGetCallDatato StructureFlags - Implement
getCallDatato return the target's CallData - JSC automatically handles the rest (typeof, callability, etc.)
This makes AsyncContextFrame a true transparent wrapper that preserves the callable nature of the wrapped function while maintaining async context management.