本文整理汇总了C++中Isolate::NewString方法的典型用法代码示例。如果您正苦于以下问题:C++ Isolate::NewString方法的具体用法?C++ Isolate::NewString怎么用?C++ Isolate::NewString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Isolate
的用法示例。
在下文中一共展示了Isolate::NewString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compile
result_t CustomExtLoader::compile(SandBox::Context* ctx, Buffer_base* src, exlib::string name,
exlib::string arg_names, v8::Local<v8::Script>& script)
{
Isolate* isolate = ctx->m_sb->holder();
v8::Local<v8::Value> require_fn = ctx->m_sb->GetPrivate(SandBox::_get_extloader_pname(m_ext));
exlib::string strScript;
// read filecontent and compile to strScript :start
v8::Local<v8::Value> transpileArgs[2];
src->valueOf(transpileArgs[0]);
v8::Local<v8::Object> requireInfo = v8::Object::New(isolate->m_isolate);
transpileArgs[1] = requireInfo;
requireInfo->Set(isolate->NewString("filename"), isolate->NewString(name));
v8::Local<v8::Value> fileContent = v8::Local<v8::Function>::Cast(require_fn)->Call(v8::Undefined(isolate->m_isolate), 2, transpileArgs);
if (fileContent.IsEmpty())
return CALL_E_JAVASCRIPT;
result_t hr = GetArgumentValue(fileContent, strScript, true);
if (hr < 0)
return CHECK_ERROR(hr);
// read filecontent and compile to strScript :end
obj_ptr<Buffer_base> buf = new Buffer(strScript);
return JsLoader::compile(ctx, buf, name, arg_names, script);
}
示例2: update
result_t MongoCollection::update(v8::Local<v8::Object> query,
v8::Local<v8::Object> document, v8::Local<v8::Object> options)
{
Isolate* isolate = holder();
return update(query, document,
options->Get(isolate->NewString("upsert", 6))->BooleanValue(),
options->Get(isolate->NewString("multi", 5))->BooleanValue());
}
示例3: get_constants
result_t fs_base::get_constants(v8::Local<v8::Object>& retVal)
{
Isolate* isolate = Isolate::current();
retVal = v8::Object::New(isolate->m_isolate);
retVal->Set(isolate->NewString("F_OK"), v8::Integer::New(isolate->m_isolate, F_OK));
retVal->Set(isolate->NewString("R_OK"), v8::Integer::New(isolate->m_isolate, R_OK));
retVal->Set(isolate->NewString("W_OK"), v8::Integer::New(isolate->m_isolate, W_OK));
retVal->Set(isolate->NewString("X_OK"), v8::Integer::New(isolate->m_isolate, X_OK));
return 0;
}
示例4: ensureIndex
result_t MongoCollection::ensureIndex(v8::Local<v8::Object> keys,
v8::Local<v8::Object> options)
{
obj_ptr<MongoDB> db(m_db);
if (!db)
return CHECK_ERROR(CALL_E_INVALID_CALL);
exlib::string name;
v8::Local<v8::Array> ks = keys->GetPropertyNames();
int32_t len = (int32_t)ks->Length();
int32_t i;
for (i = 0; i < len; i++) {
v8::Local<v8::Value> k = ks->Get(i);
v8::Local<v8::Value> v = keys->Get(k);
if (!v->IsNumber() && !v->IsNumberObject())
return CHECK_ERROR(CALL_E_INVALIDARG);
v8::String::Utf8Value sk(k);
v8::String::Utf8Value sv(v);
if (name.length())
name += '_';
name.append(*sk, sk.length());
name += '_';
name.append(*sv, sv.length());
}
Isolate* isolate = holder();
v8::Local<v8::Object> idx = v8::Object::New(isolate->m_isolate);
idx->Set(isolate->NewString("name"), isolate->NewString(name));
idx->Set(isolate->NewString("key"), keys);
extend(options, idx);
v8::Local<v8::Array> idxs = v8::Array::New(isolate->m_isolate);
idxs->Set(0, idx);
v8::Local<v8::Object> cmd = v8::Object::New(isolate->m_isolate);
cmd->Set(isolate->NewString("indexes"), idxs);
v8::Local<v8::Object> retVal;
return runCommand("createIndexes", cmd, retVal);
}
示例5: getIndexes
result_t MongoCollection::getIndexes(obj_ptr<MongoCursor_base>& retVal)
{
obj_ptr<MongoDB> db(m_db);
if (!db)
return CHECK_ERROR(CALL_E_INVALID_CALL);
result_t hr;
obj_ptr<MongoCollection_base> coll;
hr = db->getCollection("system.indexes", coll);
if (hr < 0)
return hr;
Isolate* isolate = holder();
v8::Local<v8::Object> f = v8::Object::New(isolate->m_isolate);
v8::Local<v8::Object> q = v8::Object::New(isolate->m_isolate);
q->Set(isolate->NewString("ns"), isolate->NewString(m_ns));
return coll->find(q, f, retVal);
}
示例6: _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->NewString(m_map[i].first));
return 0;
}
示例7: _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_map[i].first;
if (name_set.insert(name).second)
retVal->Set(n++, isolate->NewString(name));
}
return 0;
}
示例8: save
result_t MongoCollection::save(v8::Local<v8::Object> document)
{
Isolate* isolate = holder();
v8::Local<v8::String> strId = isolate->NewString("_id", 3);
v8::Local<v8::Value> id = document->Get(strId);
if (IsEmpty(id))
return insert(document);
else {
v8::Local<v8::Object> query = v8::Object::New(isolate->m_isolate);
query->Set(strId, id);
return update(query, document, true, false);
}
}
示例9: run
result_t JsonLoader::run(SandBox::Context* ctx, Buffer_base* src, exlib::string name,
exlib::string arg_names, std::vector<v8::Local<v8::Value>>& args)
{
Isolate* isolate = ctx->m_sb->holder();
v8::Local<v8::Function> func = isolate->NewFunction("json_loader", _json_loader, src->wrap());
if (func.IsEmpty())
return CHECK_ERROR(Runtime::setError("function alloc error."));
v8::Local<v8::Object> module = v8::Local<v8::Object>::Cast(args[5]);
module->SetPrivate(module->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString("entry")),
func);
v8::Local<v8::Object> glob = isolate->context()->Global();
v8::Local<v8::Value> v = func->Call(glob, (int32_t)args.size(), args.data());
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;
return 0;
}
示例10: buildInfo
result_t util_base::buildInfo(v8::Local<v8::Object>& retVal)
{
Isolate* isolate = Isolate::current();
retVal = v8::Object::New(isolate->m_isolate);
retVal->Set(isolate->NewString("fibjs"), isolate->NewString(fibjs_version));
#ifdef GIT_INFO
retVal->Set(isolate->NewString("git"), isolate->NewString(GIT_INFO));
#endif
#if defined(__clang__)
retVal->Set(isolate->NewString("clang"),
isolate->NewString(STR(__clang_major__) "." STR(__clang_minor__)));
#elif defined(__GNUC__)
retVal->Set(isolate->NewString("gcc"),
isolate->NewString(STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__)));
#elif defined(_MSC_VER)
retVal->Set(isolate->NewString("msvc"),
isolate->NewString(STR(_MSC_VER)));
#endif
retVal->Set(isolate->NewString("date"),
isolate->NewString(__DATE__ " " __TIME__));
#ifndef NDEBUG
retVal->Set(isolate->NewString("debug"), v8::True(isolate->m_isolate));
#endif
{
v8::Local<v8::Object> vender = v8::Object::New(isolate->m_isolate);
char str[64];
retVal->Set(isolate->NewString("vender"), vender);
vender->Set(isolate->NewString("ev"),
isolate->NewString(STR(EV_VERSION_MAJOR) "." STR(EV_VERSION_MINOR)));
vender->Set(isolate->NewString("expat"),
isolate->NewString(STR(XML_MAJOR_VERSION) "." STR(XML_MINOR_VERSION) "." STR(XML_MICRO_VERSION)));
vender->Set(isolate->NewString("gd"), isolate->NewString(GD_VERSION_STRING));
vender->Set(isolate->NewString("jpeg"), isolate->NewString(STR(JPEG_LIB_VERSION_MAJOR) "." STR(JPEG_LIB_VERSION_MINOR)));
sprintf(str, "%d.%d", leveldb::kMajorVersion, leveldb::kMinorVersion);
vender->Set(isolate->NewString("leveldb"), isolate->NewString(str));
vender->Set(isolate->NewString("mongo"), isolate->NewString(STR(MONGO_MAJOR) "." STR(MONGO_MINOR)));
vender->Set(isolate->NewString("pcre"), isolate->NewString(STR(PCRE_MAJOR) "." STR(PCRE_MINOR)));
vender->Set(isolate->NewString("png"), isolate->NewString(PNG_LIBPNG_VER_STRING));
vender->Set(isolate->NewString("mbedtls"), isolate->NewString(MBEDTLS_VERSION_STRING));
vender->Set(isolate->NewString("snappy"),
isolate->NewString(STR(SNAPPY_MAJOR) "." STR(SNAPPY_MINOR) "." STR(SNAPPY_PATCHLEVEL)));
vender->Set(isolate->NewString("sqlite"), isolate->NewString(SQLITE_VERSION));
vender->Set(isolate->NewString("tiff"), isolate->NewString(TIFFLIB_VERSION_STR));
vender->Set(isolate->NewString("uuid"), isolate->NewString("1.6.2"));
vender->Set(isolate->NewString("v8"), isolate->NewString(v8::V8::GetVersion()));
vender->Set(isolate->NewString("v8-snapshot"),
v8::internal::Snapshot::DefaultSnapshotBlob() ? v8::True(isolate->m_isolate) : v8::False(isolate->m_isolate));
vender->Set(isolate->NewString("zlib"), isolate->NewString(ZLIB_VERSION));
vender->Set(isolate->NewString("zmq"), isolate->NewString(STR(ZMQ_VERSION_MAJOR) "." STR(ZMQ_VERSION_MINOR)));
}
{
v8::Local<v8::Array> modules = v8::Array::New(isolate->m_isolate);
retVal->Set(isolate->NewString("modules"), modules);
RootModule* pModule = RootModule::g_root;
intptr_t icnt = 0;
while (pModule) {
modules->Set((int32_t)(icnt++), isolate->NewString(pModule->name()));
pModule = pModule->m_next;
}
}
return 0;
}