Permalink
Browse files

process, feat: support process.exitCode.

  • Loading branch information...
xicilion committed Oct 16, 2017
1 parent 7c9a6cb commit b6ec6558ef408b593dfe3900f00cf3373be2f2c1
Showing with 53 additions and 2 deletions.
  1. +2 −0 fibjs/include/Isolate.h
  2. +29 −1 fibjs/include/ifs/process.h
  3. +1 −0 fibjs/src/base/Runtime.cpp
  4. +17 −0 fibjs/src/process/process.cpp
  5. +4 −1 idl/zh-cn/process.idl
View
@@ -124,6 +124,8 @@ class Isolate : public exlib::linkitem {
int32_t m_loglevel;
int32_t m_defaultMaxListeners;
int32_t m_exitCode;
};
} /* namespace fibjs */
@@ -37,6 +37,8 @@ class process_base : public EventEmitter_base {
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 get_exitCode(int32_t& retVal);
static result_t set_exitCode(int32_t newVal);
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);
@@ -77,6 +79,8 @@ class process_base : public EventEmitter_base {
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_get_exitCode(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_exitCode(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& 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);
@@ -122,7 +126,8 @@ inline ClassInfo& process_base::class_info()
{ "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 }
{ "stderr", s_get_stderr, block_set, true },
{ "exitCode", s_get_exitCode, s_set_exitCode, true }
};
static ClassData s_cd = {
@@ -267,6 +272,29 @@ inline void process_base::s_get_stderr(v8::Local<v8::String> property, const v8:
METHOD_RETURN();
}
inline void process_base::s_get_exitCode(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
int32_t vr;
METHOD_NAME("process.exitCode");
PROPERTY_ENTER();
hr = get_exitCode(vr);
METHOD_RETURN();
}
inline void process_base::s_set_exitCode(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
{
METHOD_NAME("process.exitCode");
PROPERTY_ENTER();
PROPERTY_VAL(int32_t);
hr = set_exitCode(v0);
PROPERTY_SET_LEAVE();
}
inline void process_base::s_umask(const v8::FunctionCallbackInfo<v8::Value>& args)
{
int32_t vr;
@@ -107,6 +107,7 @@ Isolate::Isolate(exlib::string fname)
, m_flake_count(0)
, m_loglevel(console_base::_NOTSET)
, m_defaultMaxListeners(10)
, m_exitCode(0)
{
m_fname = fname;
@@ -114,6 +114,18 @@ result_t process_base::get_versions(v8::Local<v8::Object>& retVal)
return util_base::buildInfo(retVal);
}
result_t process_base::get_exitCode(int32_t& retVal)
{
retVal = Isolate::current()->m_exitCode;
return 0;
}
result_t process_base::set_exitCode(int32_t newVal)
{
Isolate::current()->m_exitCode = newVal;
return 0;
}
result_t process_base::umask(int32_t mask, int32_t& retVal)
{
retVal = _umask(mask);
@@ -240,6 +252,11 @@ result_t process_base::get_stderr(obj_ptr<File_base>& retVal)
result_t process_base::exit(int32_t code)
{
if (code != 0)
set_exitCode(code);
else
get_exitCode(code);
flushLog();
#ifdef _WIN32
View
@@ -40,6 +40,9 @@ module process : EventEmitter
/*! @brief 查询当前进程标准错误输出对象 */
static readonly File stderr;
/*! @brief 查询和设置当前进程的退出码 */
static Integer exitCode;
/*! @brief 改变当前的 umask,Windows 不支持此方法
@param mask 指定新的掩码
@return 返回之前的 mask
@@ -64,7 +67,7 @@ module process : EventEmitter
static Array hrtime(Array diff = []);
/*! @brief 退出当前进程,并返回结果
@param code 返回进程结果, 默认为 0
@param code 返回进程结果, 默认为 0,此时将使用 exitCode 作为进程结果
*/
static exit(Integer code = 0);

0 comments on commit b6ec655

Please sign in to comment.