Permalink
Browse files

util, feat: support util.inspect.

  • Loading branch information...
xicilion committed Sep 25, 2017
1 parent d93ca53 commit ca05229cb21962cc40b7d21aac91523b35a66761
Showing with 34 additions and 2 deletions.
  1. +19 −0 fibjs/include/ifs/util.h
  2. +7 −2 fibjs/src/util/util_format.cpp
  3. +8 −0 idl/zh-cn/util.idl
View
@@ -28,6 +28,7 @@ class util_base : public object_base {
static result_t format(exlib::string fmt, OptArgs args, exlib::string& retVal);
static result_t format(OptArgs args, exlib::string& retVal);
static result_t inherits(v8::Local<v8::Value> constructor, v8::Local<v8::Value> superConstructor);
static result_t inspect(v8::Local<v8::Object> obj, v8::Local<v8::Object> options, exlib::string& retVal);
static result_t isEmpty(v8::Local<v8::Value> v, bool& retVal);
static result_t isArray(v8::Local<v8::Value> v, bool& retVal);
static result_t isBoolean(v8::Local<v8::Value> v, bool& retVal);
@@ -93,6 +94,7 @@ class util_base : public object_base {
public:
static void s_format(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_inherits(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_inspect(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_isEmpty(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_isArray(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_isBoolean(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -154,6 +156,7 @@ inline ClassInfo& util_base::class_info()
static ClassData::ClassMethod s_method[] = {
{ "format", s_format, true },
{ "inherits", s_inherits, true },
{ "inspect", s_inspect, true },
{ "isEmpty", s_isEmpty, true },
{ "isArray", s_isArray, true },
{ "isBoolean", s_isBoolean, true },
@@ -255,6 +258,22 @@ inline void util_base::s_inherits(const v8::FunctionCallbackInfo<v8::Value>& arg
METHOD_VOID();
}
inline void util_base::s_inspect(const v8::FunctionCallbackInfo<v8::Value>& args)
{
exlib::string vr;
METHOD_ENTER();
METHOD_OVER(2, 1);
ARG(v8::Local<v8::Object>, 0);
OPT_ARG(v8::Local<v8::Object>, 1, v8::Object::New(isolate));
hr = inspect(v0, v1, vr);
METHOD_RETURN();
}
inline void util_base::s_isEmpty(const v8::FunctionCallbackInfo<v8::Value>& args)
{
bool vr;
@@ -279,8 +279,13 @@ exlib::string json_format(v8::Local<v8::Value> obj)
return strBuffer.str();
}
result_t util_base::format(exlib::string fmt, OptArgs args,
exlib::string& retVal)
result_t util_base::inspect(v8::Local<v8::Object> obj, v8::Local<v8::Object> options, exlib::string& retVal)
{
retVal = json_format(obj);
return 0;
}
result_t util_base::format(exlib::string fmt, OptArgs args, exlib::string& retVal)
{
const char* s1;
char ch;
View
@@ -24,6 +24,14 @@ module util
*/
static inherits(Value constructor, Value superConstructor);
/*! @brief 方法返回 obj 的字符串表示,主要用于调试。 附加的 options 可用于改变格式化字符串的某些方面。
@param obj 指定需要处理的对象
@param options 指定格式控制选项
@return 返回格式化后的字符串
*/
static String inspect(Object obj, Object options = {});
/*! @brief 检测给定的变量是否不包含任何值(没有可枚举的属性)
@param v 给定需要检测的变量

0 comments on commit ca05229

Please sign in to comment.