Skip to content

Commit

Permalink
process, feat: process.exit support return 0;
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Oct 29, 2017
1 parent 04f0b5d commit c4be76a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
9 changes: 7 additions & 2 deletions fibjs/include/ifs/process.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class process_base : public EventEmitter_base {
static result_t umask(exlib::string mask, int32_t& retVal); static result_t umask(exlib::string mask, int32_t& retVal);
static result_t umask(int32_t& retVal); static result_t umask(int32_t& retVal);
static result_t hrtime(v8::Local<v8::Array> diff, v8::Local<v8::Array>& retVal); static result_t hrtime(v8::Local<v8::Array> diff, v8::Local<v8::Array>& retVal);
static result_t exit();
static result_t exit(int32_t code); static result_t exit(int32_t code);
static result_t cwd(exlib::string& retVal); static result_t cwd(exlib::string& retVal);
static result_t chdir(exlib::string directory); static result_t chdir(exlib::string directory);
Expand Down Expand Up @@ -342,9 +343,13 @@ inline void process_base::s_exit(const v8::FunctionCallbackInfo<v8::Value>& args
METHOD_NAME("process.exit"); METHOD_NAME("process.exit");
METHOD_ENTER(); METHOD_ENTER();


METHOD_OVER(1, 0); METHOD_OVER(0, 0);

hr = exit();


OPT_ARG(int32_t, 0, 0); METHOD_OVER(1, 1);

ARG(int32_t, 0);


hr = exit(v0); hr = exit(v0);


Expand Down
8 changes: 6 additions & 2 deletions fibjs/src/coroutine/Fiber.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ void JSFiber::fiber_proc(void* p)


isolate->m_pendding.inc(); isolate->m_pendding.inc();
t._emit("beforeExit", &code, 1, r); t._emit("beforeExit", &code, 1, r);
if (isolate->m_pendding.dec() == 0) if (isolate->m_pendding.dec() == 0) {
process_base::exit(hr); if (hr >= 0)
process_base::exit();
else
process_base::exit(hr);
}
} }
} }


Expand Down
15 changes: 9 additions & 6 deletions fibjs/src/process/process.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -251,14 +251,10 @@ result_t process_base::get_stderr(obj_ptr<File_base>& retVal)
return 0; return 0;
} }


result_t process_base::exit(int32_t code) result_t process_base::exit()
{ {
Isolate* isolate = Isolate::current(); Isolate* isolate = Isolate::current();

int32_t code = isolate->m_exitCode;
if (code != 0)
isolate->m_exitCode = code;
else
code = isolate->m_exitCode;


JSTrigger t(isolate->m_isolate, class_info().getModule(isolate)); JSTrigger t(isolate->m_isolate, class_info().getModule(isolate));
v8::Local<v8::Value> v = v8::Number::New(isolate->m_isolate, code); v8::Local<v8::Value> v = v8::Number::New(isolate->m_isolate, code);
Expand All @@ -278,6 +274,13 @@ result_t process_base::exit(int32_t code)
return 0; return 0;
} }


result_t process_base::exit(int32_t code)
{
Isolate* isolate = Isolate::current();
isolate->m_exitCode = code;
return process_base::exit();
}

result_t process_base::memoryUsage(v8::Local<v8::Object>& retVal) result_t process_base::memoryUsage(v8::Local<v8::Object>& retVal)
{ {
return os_base::memoryUsage(retVal); return os_base::memoryUsage(retVal);
Expand Down
2 changes: 1 addition & 1 deletion fibjs/src/process/process_signal.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void _InterruptCallback(v8::Isolate* v8_isolate, void* data)


t._emit((const char*)data, NULL, 0, r); t._emit((const char*)data, NULL, 0, r);
if (!r) if (!r)
_exit(1); process_base::exit(1);
} }


result_t async_signal(const char* name) result_t async_signal(const char* name)
Expand Down
7 changes: 5 additions & 2 deletions idl/zh-cn/process.idl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ module process : EventEmitter
*/ */
static Array hrtime(Array diff = []); static Array hrtime(Array diff = []);


/*! @brief 退出当前进程,并返回 exitCode 作为进程结果 */
static exit();

/*! @brief 退出当前进程,并返回结果 /*! @brief 退出当前进程,并返回结果
@param code 返回进程结果, 默认为 0,此时将使用 exitCode 作为进程结果 @param code 返回进程结果
*/ */
static exit(Integer code = 0); static exit(Integer code);


/*! @brief 返回操作系统当前工作路径 /*! @brief 返回操作系统当前工作路径
@return 返回当前系统路径 @return 返回当前系统路径
Expand Down

0 comments on commit c4be76a

Please sign in to comment.