Skip to content

implement require.extensions attempt 2 - #18686

Merged
paperclover merged 14 commits into
mainfrom
chloe/extensions-attempt2
Apr 1, 2025
Merged

paperclover merged 14 commits into
mainfrom
chloe/extensions-attempt2

Conversation

@paperclover

Copy link
Copy Markdown
Contributor

Closes #18570

@robobun

robobun commented Mar 31, 2025 •

Copy link
Copy Markdown
Collaborator
Updated 2:04 PM PT - Apr 1st, 2025

✅ @paperclover, your commit 7c5b39729493bb93462606411d387e0c2fd1841a passed in Build #14348! 🎉


🧪   try this PR locally:

bunx bun-pr 18686


// When adding to this list, please comment why the package is using extensions incorrectly.

WTF::String url = frame.sourceURL(vm);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if null

{
if (propertyName.isSymbol()) return;
auto* name = propertyName.publicName();
if (!name->startsWith("."_s)) return;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'.'

auto& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!compileFunction || !compileFunction.isCallable()) {
throwTypeError(globalObject, scope, makeString("overridden module._compile is not a function (called from overridden Module._extensions)"_s));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not dynamic

if (JSValue compileFunction = this->m_overriddenCompile.get()) {
auto& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!compileFunction || !compileFunction.isCallable()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already checked

throwTypeError(globalObject, scope, makeString("overridden module._compile is not a function (called from overridden Module._extensions)"_s));
return;
}
WTF::String sourceString = source.source_code.toWTFString(BunString::ZeroCopy);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception

Comment thread src/bun.js/bindings/ModuleLoader.cpp Outdated
Bun::JSCommonJSExtensions* extensions = globalObject->lazyRequireExtensionsObject();
JSValue extension = extensions->m_registeredFunctions[extensionIndex].get();

if (!extension || !extension.isCallable()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!!!!!!!!!

visitor.append(thisObject->m_currentNapiHandleScopeImpl);

thisObject->m_moduleResolveFilenameFunction.visit(visitor);
thisObject->m_modulePrototypeUnderscoreCompileFunction.visit(visitor);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!

@paperclover paperclover left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

me wehen the

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling Module._extensions[".ts"] directly is not implemented.

2 participants