-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make process.mainModule
writable
#18730
base: main
Are you sure you want to change the base?
Conversation
Updated 5:27 PM PT - Apr 9th, 2025
❌ @Jarred-Sumner, your commit 7633980 has 1 failures in
🧪 try this PR locally: bunx bun-pr 18730 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The private variable is unnecessary, and calling BunObject__getter_wrap_main
is non-trivial overhead
Instead, we can add a LazyProperty onto Zig::GlobalObject and make Bun.main
access that LazyProperty and the process.mainModule
getter & setter can get/set that LazyProperty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments
} | ||
|
||
// NOTE: we cannot assume `main` is ascii. | ||
var main_module = bun.String.init(bun_vm.main); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var main_module = bun.String.init(bun_vm.main); | |
return bun.String.createUTF8ForJS(bun_vm.main); |
@@ -3335,6 +3336,13 @@ void GlobalObject::finishCreation(VM& vm) | |||
InternalModuleRegistry::createStructure(init.vm, init.owner))); | |||
}); | |||
|
|||
m_mainModule.initLater( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this visited?
return JSValue::encode(jsUndefined()); | ||
} | ||
auto prop = PropertyName(JSC::Identifier::fromString(vm, WTFMove(mm->getString(global)))); | ||
auto mainModule = requireCache->getIfPropertyExists(global, prop); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this accessing the require object? Why isn't this a getter/setter for the same main module LazyProperty defined on the global object? The require.main and the process.mainModule implementations should both access the same underlying WriteBarrier
What does this PR do?
Add a setter for
process.mainModule
. This snippet works in node but not in bun, causing some older test runners to breakHow did you verify your code works?
I've added tests