Permalink
Browse files

util, feat: support using vector array to init OptArg.

  • Loading branch information...
xicilion committed Jul 27, 2018
1 parent b6d44ff commit 8b3835cde44612004c00517a2a30f4e16bb61a6c
Showing with 22 additions and 0 deletions.
  1. +22 −0 fibjs/include/utils.h
View
@@ -679,22 +679,33 @@ class OptArgs {
public:
OptArgs(const v8::FunctionCallbackInfo<v8::Value>& args, int32_t base, int32_t argc)
: m_args(&args)
, m_argv(NULL)
, m_base(base)
, m_argc(argc)
{
if (m_base > m_argc)
m_base = m_argc;
}
OptArgs(const std::vector<v8::Local<v8::Value>>& argv)
: m_args(NULL)
, m_argv(&argv)
, m_base(0)
, m_argc((int32_t)argv.size())
{
}
OptArgs(const OptArgs& a)
: m_args(a.m_args)
, m_argv(a.m_argv)
, m_base(a.m_base)
, m_argc(a.m_argc)
{
}
OptArgs()
: m_args(NULL)
, m_argv(NULL)
, m_base(0)
, m_argc(0)
{
@@ -707,18 +718,29 @@ class OptArgs {
v8::Local<v8::Value> operator[](int32_t i) const
{
if (m_argv)
return (*m_argv)[i];
return (*m_args)[i + m_base];
}
void GetData(std::vector<v8::Local<v8::Value>>& datas)
{
if (m_argv) {
datas.resize(m_argc);
for (int32_t i = 0; i < m_argc; i++)
datas[i] = (*m_argv)[i];
return;
}
datas.resize(m_argc - m_base);
for (int32_t i = 0; i < m_argc - m_base; i++)
datas[i] = (*m_args)[m_base + i];
}
private:
const v8::FunctionCallbackInfo<v8::Value>* m_args;
const std::vector<v8::Local<v8::Value>>* m_argv;
int32_t m_base;
int32_t m_argc;
};

0 comments on commit 8b3835c

Please sign in to comment.