From c2a77cf7ec9de9eadf938046bdf78e58561c8a6d Mon Sep 17 00:00:00 2001 From: dave caruso Date: Wed, 2 Aug 2023 16:27:36 -0700 Subject: Rewrite built-in modules to use CommonJS over ESM (#3814) * stfdsafsd sadffdsa stuff finish commonjs stuff asdf not done but work not done but work not done yet but this is how far i am remove files lol update built files uncomment everything in events lol export default stuff * afdsafsd * its not perfect but almost done * okay * cool * remove temp file * finish rebase * revert settings.json * a * ch-ch-ch-ch-changes * okay * remove this check in release for now * sxdcfghnjm, * lkjhgf * fmt * filename can be null * Update NodeModuleModule.h * weee * fmt --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- src/bun.js/modules/NodeTTYModule.h | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/bun.js/modules/NodeTTYModule.h (limited to 'src/bun.js/modules/NodeTTYModule.h') diff --git a/src/bun.js/modules/NodeTTYModule.h b/src/bun.js/modules/NodeTTYModule.h new file mode 100644 index 000000000..18a8f59a9 --- /dev/null +++ b/src/bun.js/modules/NodeTTYModule.h @@ -0,0 +1,50 @@ +#include "JSBuffer.h" +#include "_NativeModule.h" + +namespace Zig { +using namespace WebCore; + +JSC_DEFINE_HOST_FUNCTION(jsFunctionTty_isatty, (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + VM &vm = globalObject->vm(); + if (callFrame->argumentCount() < 1) { + return JSValue::encode(jsBoolean(false)); + } + + auto scope = DECLARE_CATCH_SCOPE(vm); + int fd = callFrame->argument(0).toInt32(globalObject); + RETURN_IF_EXCEPTION(scope, encodedJSValue()); + + return JSValue::encode(jsBoolean(isatty(fd))); +} + +JSC_DEFINE_HOST_FUNCTION(jsFunctionNotImplementedYet, + (JSGlobalObject * globalObject, + CallFrame *callFrame)) { + VM &vm = globalObject->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + throwException(globalObject, throwScope, + createError(globalObject, "Not implemented yet"_s)); + return JSValue::encode(jsUndefined()); +} + +DEFINE_NATIVE_MODULE(NodeTTY) { + INIT_NATIVE_MODULE(3); + + auto *isattyFunction = + JSFunction::create(vm, globalObject, 1, "isatty"_s, jsFunctionTty_isatty, + ImplementationVisibility::Public); + + auto *notimpl = JSFunction::create(vm, globalObject, 0, "notimpl"_s, + jsFunctionNotImplementedYet, + ImplementationVisibility::Public, + NoIntrinsic, jsFunctionNotImplementedYet); + + putNativeFn(Identifier::fromString(vm, "isatty"_s), jsFunctionTty_isatty); + put(Identifier::fromString(vm, "ReadStream"_s), notimpl); + put(Identifier::fromString(vm, "WriteStream"_s), notimpl); + + RETURN_NATIVE_MODULE(); +} + +} // namespace Zig -- cgit v1.2.3