Skip to content

Conversation

@ThatOneBro
Copy link
Contributor

@ThatOneBro ThatOneBro commented Jan 6, 2023

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.

readline

The 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 underscore
  • Start polyfilling Node internal errors in a way which tests can easily be autoimported from Node without any or little changes to the code. There is still some work to be done here when it comes to creating multiple errors for the same error code (for example,ERR_INVALID_ARG_VALUE can 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 of common.mustCall, common.mustNotCall and friends used frequently in Node tests. This is useful for working with callbacks in conjunction with done callback, without wrapping everything in Promises.

Next

Need to implement tty.setRawMode, shouldn't be too hard. That should get basically readline pretty much 1:1 Node parity.

Also because we are using only two files for readline and readline/promises respectively, need to figure out how to fix a circular dependency we created with promises which 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.

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a 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);
Copy link
Collaborator

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

var { StringDecoder } = import.meta.require("string_decoder");

var { inspect } = Bun;
var debug = process.env.DEBUG ? console.log : () => {};
Copy link
Collaborator

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

Copy link
Contributor Author

@ThatOneBro ThatOneBro Jan 7, 2023

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?

Copy link
Contributor Author

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

@Jarred-Sumner Jarred-Sumner merged commit 9440977 into oven-sh:main Jan 8, 2023
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.

2 participants