当前位置: 首页>>代码示例>>C++>>正文


C++ Isolate::NewFromUtf8方法代码示例

本文整理汇总了C++中Isolate::NewFromUtf8方法的典型用法代码示例。如果您正苦于以下问题:C++ Isolate::NewFromUtf8方法的具体用法?C++ Isolate::NewFromUtf8怎么用?C++ Isolate::NewFromUtf8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Isolate的用法示例。


在下文中一共展示了Isolate::NewFromUtf8方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _jsonEncode

inline result_t _jsonEncode(v8::Local<v8::Value> data,
                            std::string &retVal)
{
	Isolate* isolate = Isolate::current();
	v8::Local<v8::Object> _json;

	if (isolate->m_json.IsEmpty())
	{
		v8::Local<v8::Object> glob = v8::Local<v8::Object>::New(isolate->m_isolate, isolate->m_global);
		_json = glob->Get(isolate->NewFromUtf8("JSON"))->ToObject();
		isolate->m_json.Reset(isolate->m_isolate, _json);

		isolate->m_stringify.Reset(isolate->m_isolate,
		                           v8::Local<v8::Function>::Cast(_json->Get(isolate->NewFromUtf8("stringify"))));
	} else
		_json = v8::Local<v8::Object>::New(isolate->m_isolate, isolate->m_json);

	TryCatch try_catch;
	v8::Local<v8::Value> str = v8::Local<v8::Function>::New(isolate->m_isolate, isolate->m_stringify)->Call(_json, 1, &data);
	if (try_catch.HasCaught())
		return CHECK_ERROR(Runtime::setError(*v8::String::Utf8Value(try_catch.Exception())));

	v8::String::Utf8Value v(str);
	retVal.assign(*v, v.length());

	return 0;
}
开发者ID:fibx,项目名称:fibjs,代码行数:27,代码来源:encoding_json.cpp

示例2: create

result_t HttpsServer::create(v8::Local<v8::Array> certs, const char *addr, int32_t port,
                             v8::Local<v8::Value> hdlr)
{
    result_t hr;
    obj_ptr<SslServer_base> _server;
    obj_ptr<HttpHandler_base> _handler;

    hr = HttpHandler_base::_new(hdlr, _handler);
    if (hr < 0)
        return hr;

    hr = SslServer_base::_new(certs, addr, port, _handler->wrap(), _server);
    if (hr < 0)
        return hr;

    v8::Local<v8::Object> o = wrap();
    Isolate* isolate = holder();

    m_handler = _handler;
    o->SetHiddenValue(isolate->NewFromUtf8("handler"), _handler->wrap());

    m_server = _server;
    o->SetHiddenValue(isolate->NewFromUtf8("server"), _server->wrap());

    return 0;
}
开发者ID:fibx,项目名称:fibjs,代码行数:26,代码来源:HttpsServer.cpp

示例3: get_env

result_t process_base::get_env(v8::Local<v8::Object>& retVal)
{
    Isolate* isolate = Isolate::current();
    v8::Local<v8::Object> glob = v8::Local<v8::Object>::New(isolate->m_isolate, isolate->m_global);
    v8::Local<v8::Value> ev = isolate->GetPrivate(glob, "_env");

    if (ev->IsUndefined())
    {
        v8::Local<v8::Object> o = v8::Object::New(isolate->m_isolate);
        char** env = environ;
        const char *p, *p1;

        while ((p = *env++) != NULL)
        {
            p1 = qstrchr(p, '=');
            if (p1)
                o->Set(isolate->NewFromUtf8(p, (int32_t)(p1 - p)), isolate->NewFromUtf8(p1 + 1));
        }

        isolate->SetPrivate(glob, "_env", o);
        retVal = o;
    } else
        retVal = v8::Local<v8::Object>::Cast(ev);

    return 0;
}
开发者ID:anlebcoder,项目名称:fibjs,代码行数:26,代码来源:process.cpp

示例4: ThrowResult

v8::Local<v8::Value> ThrowResult(result_t hr)
{
    Isolate* isolate = Isolate::current();
    v8::Local<v8::Value> e = v8::Exception::Error(
                                 isolate->NewFromUtf8(getResultMessage(hr)));
    e->ToObject()->Set(isolate->NewFromUtf8("number"), v8::Int32::New(isolate->m_isolate, -hr));

    return isolate->m_isolate->ThrowException(e);
}
开发者ID:anlebcoder,项目名称:fibjs,代码行数:9,代码来源:utils.cpp

示例5: readLines

result_t BufferedStream::readLines(int32_t maxlines, v8::Local<v8::Array> &retVal)
{
    result_t hr = 0;
    std::string str;
    int32_t n = 0;
    Isolate* isolate = holder();
    retVal = v8::Array::New(isolate->m_isolate);

    if (maxlines == 0)
        return 0;

    while (true)
    {
        hr = ac_readLine(-1, str);

        if (hr < 0)
            return hr;
        if (hr > 0)
            return 0;

        retVal->Set(n ++, isolate->NewFromUtf8(str));
        if (maxlines > 0)
        {
            maxlines --;
            if (maxlines == 0)
                break;
        }
    }

    return 0;
}
开发者ID:540513310,项目名称:fibjs,代码行数:31,代码来源:BufferedStream.cpp

示例6: map

result_t util_base::map(v8::Local<v8::Value> list, v8::Local<v8::Function> iterator,
                        v8::Local<v8::Value> context, v8::Local<v8::Array> &retVal)
{
    Isolate* isolate = Isolate::current();
    v8::Local<v8::Array> arr = v8::Array::New(isolate->m_isolate);

    if (!list->IsObject())
    {
        retVal = arr;
        return 0;
    }

    v8::Local<v8::Value> args[3];
    args[2] = list;

    v8::Local<v8::Object> o = v8::Local<v8::Object>::Cast(list);
    v8::Local<v8::Value> v = o->Get(isolate->NewFromUtf8("length"));
    int32_t cnt = 0;

    if (IsEmpty(v))
    {
        v8::Local<v8::Array> keys = o->GetPropertyNames();
        int32_t len = keys->Length();
        int32_t i;

        for (i = 0; i < len; i ++)
        {
            args[1] = keys->Get(i);
            args[0] = o->Get(args[1]);

            v = iterator->Call(context, 3, args);
            if (v.IsEmpty())
                return CALL_E_JAVASCRIPT;

            arr->Set(cnt ++, v);
        }
    }
    else
    {
        int32_t len = v->Int32Value();

        int32_t i;

        for (i = 0; i < len; i ++)
        {
            args[1] = v8::Int32::New(isolate->m_isolate, i);
            args[0] = o->Get(args[1]);

            v = iterator->Call(context, 3, args);
            if (v.IsEmpty())
                return CALL_E_JAVASCRIPT;

            arr->Set(cnt ++, v);
        }
    }

    retVal = arr;

    return 0;
}
开发者ID:jim4node,项目名称:fibjs,代码行数:60,代码来源:util.cpp

示例7: CHECK_ERROR

result_t X509Crl::dump(v8::Local<v8::Array> &retVal)
{
    Isolate* isolate = holder();
    retVal = v8::Array::New(isolate->m_isolate);

    const mbedtls_x509_crl *pCrl = &m_crl;
    int32_t ret, n = 0;
    exlib::string buf;
    size_t olen;

    while (pCrl)
    {
        if (pCrl->raw.len > 0)
        {
            buf.resize(pCrl->raw.len * 2 + 64);
            ret = mbedtls_pem_write_buffer(PEM_BEGIN_CRL, PEM_END_CRL,
                                           pCrl->raw.p, pCrl->raw.len,
                                           (unsigned char *)&buf[0], buf.length(), &olen);
            if (ret != 0)
                return CHECK_ERROR(_ssl::setError(ret));

            retVal->Set(n ++, isolate->NewFromUtf8(buf.c_str(), (int32_t) olen - 1));
        }
        pCrl = pCrl->next;
    }

    return 0;
}
开发者ID:ngot,项目名称:fibjs,代码行数:28,代码来源:X509Crl.cpp

示例8: toJSON

result_t Buffer::toJSON(const char *key, v8::Local<v8::Value> &retVal)
{
    Isolate* isolate = holder();
    v8::Local<v8::Object> o = v8::Object::New(isolate->m_isolate);
    v8::Local<v8::Array> a = v8::Array::New(isolate->m_isolate, (int32_t) m_data.length());
    int32_t i;

    for (i = 0; i < (int32_t) m_data.length(); i++)
        a->Set(i, v8::Number::New(isolate->m_isolate, (unsigned char) m_data[i]));

    o->Set(isolate->NewFromUtf8("type"), isolate->NewFromUtf8("Buffer"));
    o->Set(isolate->NewFromUtf8("data"), a);

    retVal = o;

    return 0;
}
开发者ID:MikeIOT,项目名称:fibjs,代码行数:17,代码来源:Buffer.cpp

示例9: toJSON

result_t DBResult::toJSON(exlib::string key, v8::Local<v8::Value> &retVal)
{
    if (m_size)
        return m_array->toJSON(key, retVal);

    Isolate* isolate = holder();
    v8::Local<v8::Object> o = v8::Object::New(isolate->m_isolate);

    o->Set(isolate->NewFromUtf8("affected", 8),
           v8::Number::New(isolate->m_isolate, (double) m_affected));
    o->Set(isolate->NewFromUtf8("insertId", 8),
           v8::Number::New(isolate->m_isolate, (double) m_insertId));

    retVal = o;

    return 0;
}
开发者ID:ngot,项目名称:fibjs,代码行数:17,代码来源:DBResult.cpp

示例10: flatten

result_t util_base::flatten(v8::Local<v8::Value> list, bool shallow,
                            v8::Local<v8::Array> &retVal)
{
    if (!list->IsObject())
        return CHECK_ERROR(CALL_E_TYPEMISMATCH);

    bool bNext = true;

    Isolate* isolate = Isolate::current();

    if (retVal.IsEmpty())
        retVal = v8::Array::New(isolate->m_isolate);
    else if (shallow)
        bNext = false;

    v8::Local<v8::Object> o = v8::Local<v8::Object>::Cast(list);
    v8::Local<v8::Value> v = o->Get(isolate->NewFromUtf8("length"));
    if (IsEmpty(v))
        return CHECK_ERROR(CALL_E_TYPEMISMATCH);

    int32_t len = v->Int32Value();
    int32_t cnt = retVal->Length();
    int32_t i;

    for (i = 0; i < len; i ++)
    {
        v = o->Get(i);
        if (bNext && v->IsObject())
        {
            v8::Local<v8::Object> o1 = v8::Local<v8::Object>::Cast(v);
            v = o->Get(isolate->NewFromUtf8("length"));
            if (IsEmpty(v))
                retVal->Set(cnt ++, o->Get(i));
            else
            {
                flatten(o1, shallow, retVal);
                cnt = retVal->Length();
            }
        }
        else
            retVal->Set(cnt ++, o->Get(i));
    }

    return 0;
}
开发者ID:jim4node,项目名称:fibjs,代码行数:45,代码来源:util.cpp

示例11: get

result_t LruCache::get(exlib::string name, v8::Local<v8::Function> updater,
                       v8::Local<v8::Value> &retVal)
{
    static _linkedNode newNode;
    v8::Handle<v8::Object> o = wrap();
    Isolate* isolate = holder();
    exlib::string sname(name);
    v8::Handle<v8::Value> a = isolate->NewFromUtf8(name);

    std::map<exlib::string, _linkedNode>::iterator find;

    cleanup();

    while (true)
    {
        obj_ptr<Event_base> e;

        find = m_datas.find(sname);
        if (find != m_datas.end())
            break;

        if (updater.IsEmpty())
            return 0;

        std::map<exlib::string, obj_ptr<Event_base> >::iterator padding;
        padding = m_paddings.find(sname);
        if (padding == m_paddings.end())
        {
            e = new Event();
            padding = m_paddings.insert(std::pair<exlib::string, obj_ptr<Event_base> >(sname, e)).first;
            v8::Local<v8::Value> v = updater->Call(o, 1, &a);
            m_paddings.erase(padding);
            e->set();

            if (v.IsEmpty())
                return CALL_E_JAVASCRIPT;

            find = m_datas.insert(std::pair<exlib::string, _linkedNode>(sname, newNode)).first;
            insert(find);

            if (m_timeout > 0)
                find->second.insert.now();
            SetPrivate(name, v);

            retVal = v;
            return 0;
        }

        e = padding->second;
        e->wait();
    }

    update(find);
    retVal = GetPrivate(name);

    return 0;
}
开发者ID:asionius92,项目名称:fibjs,代码行数:57,代码来源:LruCache.cpp

示例12: _named_enumerator

result_t HttpUploadCollection::_named_enumerator(v8::Local<v8::Array> &retVal)
{
    int32_t i;
    Isolate* isolate = holder();

    retVal = v8::Array::New(isolate->m_isolate);
    for (i = 0; i < m_count; i++)
        retVal->Set(i, isolate->NewFromUtf8(m_names[i]));

    return 0;
}
开发者ID:anlebcoder,项目名称:fibjs,代码行数:11,代码来源:HttpUploadCollection.cpp

示例13: get_argv

result_t process_base::get_argv(v8::Local<v8::Array> &retVal)
{
    Isolate* isolate = Isolate::current();
    v8::Local<v8::Array> args = v8::Array::New(isolate->m_isolate, (int32_t)s_argv.size());

    for (int32_t i = 0; i < (int32_t)s_argv.size(); i ++)
        args->Set(i, isolate->NewFromUtf8(s_argv[i]));

    retVal = args;

    return 0;
}
开发者ID:anlebcoder,项目名称:fibjs,代码行数:12,代码来源:process.cpp

示例14: _named_enumerator

result_t Map::_named_enumerator(v8::Local<v8::Array> &retVal)
{
    int32_t i = 0;
    Isolate* isolate = holder();

    retVal = v8::Array::New(isolate->m_isolate, (int32_t)m_datas.size());
    std::map<exlib::string, VariantEx>::iterator iter;

    for (iter = m_datas.begin(); iter != m_datas.end(); iter++)
        retVal->Set(i++, isolate->NewFromUtf8(iter->first));

    return 0;
}
开发者ID:ngot,项目名称:fibjs,代码行数:13,代码来源:Map.cpp

示例15: _named_enumerator

result_t HttpCollection::_named_enumerator(v8::Local<v8::Array> &retVal)
{
    int32_t i, n;
    std::set<exlib::string> name_set;
    Isolate* isolate = holder();

    retVal = v8::Array::New(isolate->m_isolate);
    for (i = 0, n = 0; i < m_count; i++)
    {
        exlib::string& name = m_names[i];
        if (name_set.insert(name).second)
            retVal->Set(n ++, isolate->NewFromUtf8(name));
    }

    return 0;
}
开发者ID:ngot,项目名称:fibjs,代码行数:16,代码来源:HttpCollection.cpp


注:本文中的Isolate::NewFromUtf8方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。