-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(node:readline): add node:readline and node:readline/promises #1738
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
Conversation
Jarred-Sumner
left a comment
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.
A few comments but overall looks good
| auto result = JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.addListenerForBindings(WTFMove(eventType), WTFMove(listener), once, prepend); })); | ||
| RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); | ||
|
|
||
| JSC::Identifier newListenerEventType = JSC::Identifier::fromString(vm, "newListener"_s); |
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.
future TODO: add fields for the super common properties like captureRejection, newListener, error, etc to avoid creating identifiers like this
src/bun.js/readline.exports.js
Outdated
| var { StringDecoder } = import.meta.require("string_decoder"); | ||
|
|
||
| var { inspect } = Bun; | ||
| var debug = process.env.DEBUG ? console.log : () => {}; |
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.
We probably should switch to a more specific DEBUG flag since this is also used by the debug npm package
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.
Yeah I was thinking about that too. Should there be a bun-wide debug or a debug flag for different modules? BUN_DEBUG?
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.
I renamed it to BUN_JS_DEBUG for now. Let me know if you think that is too vague or too specific
This PR is a lot of code to look at, readline and a bunch of stuff that can be later extracted into other internal components/conventions.
readlineThe whole module is more or less completed, but I'm going to do a pass to refactor it. A lot of stuff was modified but I ended up copying a lot of the original code again from node due to some issues that arose from the optimizations I made changing behavior.
Some tests still need to be ported from node, but I think about half of them already have been. Only a few tests are not passing currently and most are failing due to a scoping issue which I think I have a fix for.
Other notable stuff
SymbolFor("__BUN_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED__"): A way to export internal symbols to other internal modules. A little safer and more explicit than just exporting functions or vars with an underscoreERR_INVALID_ARG_VALUEcan be a RangeError or a TypeError confusingly. But not too hard to deal with if we abuse multiple prototype inheritance... But there may be a better solution.node-test-helpers.ts: A Node test helper library which helps with compatibility of Node tests in the Bun wiptest suite. Basically it exports a wrapped version of assert which calls expect for each assert function and some our own equivalent ofcommon.mustCall,common.mustNotCalland friends used frequently in Node tests. This is useful for working with callbacks in conjunction withdonecallback, without wrapping everything in Promises.Next
Need to implement
tty.setRawMode, shouldn't be too hard. That should get basicallyreadlinepretty much 1:1 Node parity.Also because we are using only two files for
readlineandreadline/promisesrespectively, need to figure out how to fix a circular dependency we created withpromiseswhich Node doesn't have because they have separate internal and external modules. This shouldn't be hard but may require a bit of file restructuring, and creating a convention for internal modules which only Node builtins can access.