Permalink
Browse files

process, feat: support process.stdin, process.stdout, process.stderr.

  • Loading branch information...
xicilion committed Sep 25, 2017
1 parent 8085d42 commit b3f68688b05f6af6cd6b8a09a8cde0a84b25486b
Showing with 92 additions and 1 deletion.
  1. +5 −0 fibjs/include/Isolate.h
  2. +45 −1 fibjs/include/ifs/process.h
  3. +33 −0 fibjs/src/process/process.cpp
  4. +9 −0 idl/zh-cn/process.idl
View
@@ -31,6 +31,7 @@ inline v8::Local<v8::String> NewString(v8::Isolate* isolate, exlib::string str)
class SandBox;
class JSFiber;
class LruCache;
class File_base;
class Isolate : public exlib::linkitem {
public:
@@ -92,6 +93,10 @@ class Isolate : public exlib::linkitem {
obj_ptr<SandBox> m_topSandbox;
obj_ptr<obj_base> m_httpclient;
obj_ptr<File_base> m_stdin;
obj_ptr<File_base> m_stdout;
obj_ptr<File_base> m_stderr;
exlib::List<exlib::linkitem> m_fibers;
void* m_test;
@@ -18,6 +18,7 @@
namespace fibjs {
class EventEmitter_base;
class File_base;
class SubProcess_base;
class process_base : public EventEmitter_base {
@@ -32,6 +33,9 @@ class process_base : public EventEmitter_base {
static result_t get_env(v8::Local<v8::Object>& retVal);
static result_t get_arch(exlib::string& retVal);
static result_t get_platform(exlib::string& retVal);
static result_t get_stdin(obj_ptr<File_base>& retVal);
static result_t get_stdout(obj_ptr<File_base>& retVal);
static result_t get_stderr(obj_ptr<File_base>& retVal);
static result_t umask(int32_t mask, int32_t& retVal);
static result_t umask(exlib::string mask, int32_t& retVal);
static result_t umask(int32_t& retVal);
@@ -68,6 +72,9 @@ class process_base : public EventEmitter_base {
static void s_get_env(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_arch(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_platform(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_stdin(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_stdout(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_stderr(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_umask(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_hrtime(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_exit(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -82,6 +89,7 @@ class process_base : public EventEmitter_base {
};
}
#include "File.h"
#include "SubProcess.h"
namespace fibjs {
@@ -108,7 +116,10 @@ inline ClassInfo& process_base::class_info()
{ "execPath", s_get_execPath, block_set, true },
{ "env", s_get_env, block_set, true },
{ "arch", s_get_arch, block_set, true },
{ "platform", s_get_platform, block_set, true }
{ "platform", s_get_platform, block_set, true },
{ "stdin", s_get_stdin, block_set, true },
{ "stdout", s_get_stdout, block_set, true },
{ "stderr", s_get_stderr, block_set, true }
};
static ClassData s_cd = {
@@ -198,6 +209,39 @@ inline void process_base::s_get_platform(v8::Local<v8::String> property, const v
METHOD_RETURN();
}
inline void process_base::s_get_stdin(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
obj_ptr<File_base> vr;
PROPERTY_ENTER();
hr = get_stdin(vr);
METHOD_RETURN();
}
inline void process_base::s_get_stdout(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
obj_ptr<File_base> vr;
PROPERTY_ENTER();
hr = get_stdout(vr);
METHOD_RETURN();
}
inline void process_base::s_get_stderr(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
obj_ptr<File_base> vr;
PROPERTY_ENTER();
hr = get_stderr(vr);
METHOD_RETURN();
}
inline void process_base::s_umask(const v8::FunctionCallbackInfo<v8::Value>& args)
{
int32_t vr;
@@ -199,6 +199,39 @@ result_t process_base::get_platform(exlib::string& retVal)
return os_base::platform(retVal);
}
result_t process_base::get_stdin(obj_ptr<File_base>& retVal)
{
Isolate* isolate = Isolate::current();
if (!isolate->m_stdin)
isolate->m_stdin = new File(0);
retVal = isolate->m_stdin;
return 0;
}
result_t process_base::get_stdout(obj_ptr<File_base>& retVal)
{
Isolate* isolate = Isolate::current();
if (!isolate->m_stdout)
isolate->m_stdout = new File(1);
retVal = isolate->m_stdout;
return 0;
}
result_t process_base::get_stderr(obj_ptr<File_base>& retVal)
{
Isolate* isolate = Isolate::current();
if (!isolate->m_stderr)
isolate->m_stderr = new File(2);
retVal = isolate->m_stderr;
return 0;
}
result_t process_base::exit(int32_t code)
{
flushLog();
View
@@ -28,6 +28,15 @@ module process : EventEmitter
/*! @brief 查询当前平台名称,可能的结果为 'darwin', 'freebsd', 'linux', 或 'win32' */
static readonly String platform;
/*! @brief 查询当前进程标准输入对象 */
static readonly File stdin
/*! @brief 查询当前进程标准输出对象 */;
static readonly File stdout;
/*! @brief 查询当前进程标准错误输出对象 */
static readonly File stderr;
/*! @brief 改变当前的 umask,Windows 不支持此方法
@param mask 指定新的掩码
@return 返回之前的 mask

0 comments on commit b3f6868

Please sign in to comment.