Skip to content

Commit

Permalink
isTTY in tty_wrap.cpp
Browse files Browse the repository at this point in the history
Summary: isTTY added to tty_wrap.cpp.

Reviewed By: avp

Differential Revision: D29746445

fbshipit-source-id: cd19d71b950c7f4cdb4f4ab3293f2f292c38b5c7
  • Loading branch information
adithiraofb authored and facebook-github-bot committed Jul 27, 2021
1 parent cd8da58 commit 6760637
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/node-hermes/InternalBindings/tty_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,29 @@ static jsi::Value TTY(
return jsi::Value(rt, thisValue);
}

/// Checks whether the stream handle is a tty handle.
static jsi::Value isTTY(
RuntimeState &rs,
const jsi::Value &,
const jsi::Value *args,
size_t count) {
jsi::Runtime &rt = rs.getRuntime();
if (count < 1) {
throw jsi::JSError(
rt, "Not enough arguments being passed into isTTY call.");
}
int fd = args[0].asNumber();
bool rc = uv_guess_handle(fd) == UV_TTY;
return rc;
}

/// Adds the 'tty_wrap' object as a property of internalBinding.
jsi::Value facebook::ttyBinding(RuntimeState &rs) {
jsi::Runtime &rt = rs.getRuntime();
jsi::Object tty_wrap{rt};

rs.defineJSFunction(TTY, "TTY", 2, tty_wrap);
rs.defineJSFunction(isTTY, "isTTY", 1, tty_wrap);

rs.setInternalBindingProp("tty_wrap", std::move(tty_wrap));
return rs.getInternalBindingProp("tty_wrap");
Expand Down

0 comments on commit 6760637

Please sign in to comment.