本文整理汇总了C++中Local::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::Get方法的具体用法?C++ Local::Get怎么用?C++ Local::Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ToJavaMap
int Conv::ToJavaMap(JNIEnv *jniEnv, Handle<Value> val, int componentType, jobject *jVal) {
Local<Object> oVal;
Local<Array> aPropertyNames;
if(val.IsEmpty() || val->IsNull() || val->IsUndefined()) {
*jVal = 0;
return OK;
}
if(!val->IsObject())
return ErrorType;
oVal = val->ToObject();
aPropertyNames = oVal->GetOwnPropertyNames();
int len = aPropertyNames->Length();
jobject ob = jniEnv->NewObject(mapClass, mapCtor);
if(ob) {
int res = OK;
for(int i = 0; i < len; i++) {
Local<String> key = Local<String>::Cast(aPropertyNames->Get(i));
jstring jKey; jobject item;
res = ToJavaString(jniEnv, key, &jKey);
if(res != OK) break;
res = ToJavaObject(jniEnv, oVal->Get(key), componentType, &item);
if(res != OK) break;
jniEnv->CallObjectMethod(ob, mapPut, jKey, item);
}
}
if(ob) {
*jVal = ob;
return OK;
}
if(jniEnv->ExceptionCheck())
jniEnv->ExceptionClear();
return ErrorVM;
}
示例2: ThrowException
/* static */
Handle<Value> MemoryObject::createSubBuffer(const Arguments& args)
{
HandleScope scope;
MemoryObject *mo = ObjectWrap::Unwrap<MemoryObject>(args.This());
cl_mem_flags flags = args[0]->NumberValue();
if (flags != CL_BUFFER_CREATE_TYPE_REGION)
return ThrowException(Exception::Error(String::New("CL_INVALID_VALUE")));
RegionWrapper region;
Local<Object> obj = args[1]->ToObject();
region.origin = obj->Get(String::New("origin"))->NumberValue();
region.size = obj->Get(String::New("size"))->NumberValue();
MemoryObjectWrapper *mw = 0;
cl_int ret = mo->getMemoryObjectWrapper()->createSubBuffer(flags,
region,
&mw);
if (ret != CL_SUCCESS) {
WEBCL_COND_RETURN_THROW(CL_INVALID_VALUE);
WEBCL_COND_RETURN_THROW(CL_INVALID_BUFFER_SIZE);
WEBCL_COND_RETURN_THROW(CL_INVALID_HOST_PTR);
WEBCL_COND_RETURN_THROW(CL_MEM_OBJECT_ALLOCATION_FAILURE);
WEBCL_COND_RETURN_THROW(CL_OUT_OF_RESOURCES);
WEBCL_COND_RETURN_THROW(CL_OUT_OF_HOST_MEMORY);
return ThrowException(Exception::Error(String::New("UNKNOWN ERROR")));
}
return scope.Close(MemoryObject::New(mw)->handle_);
}
示例3: NwkAddr
TEST_F(JSDeviceTest, getEndpoints) {
EndpointID endpointId1{20};
EndpointID endpointId2{21};
ZEndpoint endpoint1{NwkAddr {1}, endpointId1, 30, 31, 32, {ClusterID {50}}, {ClusterID {51}}};
ZEndpoint endpoint2{NwkAddr {1}, endpointId2, 30, 31, 32, {ClusterID {60}}, {ClusterID {61}}};
ZDevice zDevice{extAddress, NwkAddr(1), 0, {endpoint1, endpoint2}};
V8_SETUP
Local<Object> objectEndpoint1 = Object::New(isolate);
Local<Object> objectEndpoint2 = Object::New(isolate);
EXPECT_CALL(*zDevices, exists(extAddress)).WillOnce(Return(true));
EXPECT_CALL(*zDevices, getDevice(extAddress)).WillOnce(Return(&zDevice));
EXPECT_CALL(*jsEndpoint, createInstance(isolate, extAddress, endpointId1)).WillOnce(
Return(objectEndpoint1));
EXPECT_CALL(*jsEndpoint, createInstance(isolate, extAddress, endpointId2)).WillOnce(
Return(objectEndpoint2));
v8::Local<v8::Value> result = runScript(creatingZDeviceScript + "a.getEndpoints();");
ASSERT_THAT(result.IsEmpty(), false);
ASSERT_THAT(result->IsArray(), true);
Local<Array> array = result.As<Array>();
ASSERT_THAT(array->Length(), 2);
ASSERT_THAT(array->Get(0)->IsObject(), true);
ASSERT_THAT(array->Get(1)->IsObject(), true);
Local<Object> jszEndpoint0 = array->Get(0).As<Object>();
Local<Object> jszEndpoint1 = array->Get(1).As<Object>();
ASSERT_THAT(jszEndpoint0->GetIdentityHash(), Eq(objectEndpoint1->GetIdentityHash()));
ASSERT_THAT(jszEndpoint1->GetIdentityHash(), Eq(objectEndpoint2->GetIdentityHash()));
}
示例4: New
static Handle<Value> New(const Arguments& args) {
v8::HandleScope scope;
Local<Object> options = args[0]->ToObject();
//TODO: Enable passing of config options for most params. Start with the three below.
v8::String::AsciiValue hmmValue(options->Get(String::NewSymbol("hmm")));
v8::String::AsciiValue lmValue(options->Get(String::NewSymbol("lm")));
v8::String::AsciiValue dictValue(options->Get(String::NewSymbol("dict")));
v8::String::AsciiValue samprateValue(options->Get(String::NewSymbol("samprate")));
v8::String::AsciiValue nfftValue(options->Get(String::NewSymbol("nfft")));
PocketSphinx* instance = new PocketSphinx();
cmd_ln_t* config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", *hmmValue,
"-lm", *lmValue,
"-dict", *dictValue,
"-samprate", *samprateValue,
"-nfft", *nfftValue,
NULL);
instance->m_ps = ps_init(config);
instance->Wrap(args.This());
return scope.Close(args.This());
}
示例5: lock_scope
Handle<Value> AppjsSchemeHandler::NodeCallback(const Arguments& args) {
HandleScope scope;
AppjsSchemeHandler* me = static_cast<AppjsSchemeHandler *>(UnwrapObject(args.Data()));
AutoLock lock_scope(me);
me->status_ = args[0]->NumberValue();
me->status_text_ = V8StringToChar(args[1]->ToString());
me->mime_type_ = V8StringToChar(args[2]->ToString());
me->data_ = node::Buffer::Data(args[4]->ToObject());
me->data_length_ = node::Buffer::Length(args[4]->ToObject());
Local<Object> headerSets = args[3]->ToObject();
Local<Array> names = Local<Array>::Cast(headerSets->Get(String::NewSymbol("names")));
Local<Array> headers = Local<Array>::Cast(headerSets->Get(String::NewSymbol("headers")));
for(int i = 0; i < names->Length(); i++) {
me->headers_.insert(
std::pair<CefString,CefString>(
V8StringToChar(names->Get(i)),
V8StringToChar(headers->Get(i))
)
);
}
me->callback_->HeadersAvailable();
return args.This();
}
示例6: OnBeforeClose
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
// There is a bug in CEF for Linux I think that there is no window object
// when the code reaches here.
#if not defined(__LINUX__)
const int argc = 1;
Handle<Object> handle = this->GetV8WindowHandle(browser);
Handle<Value> argv[argc] = {String::New("close")};
node::MakeCallback(handle,"emit",argc,argv);
#endif
if (m_BrowserHwnd == browser->GetWindowHandle()) {
// Free the browser pointer so that the browser can be destroyed
m_Browser = NULL;
Local<Object> global = Context::GetCurrent()->Global();
Local<Object> process = global->Get(String::NewSymbol("process"))->ToObject();
Local<Object> emitter = Local<Object>::Cast(process->Get(String::NewSymbol("AppjsEmitter")));
const int argc = 1;
Handle<Value> argv[argc] = {String::New("exit")};
node::MakeCallback(emitter,"emit",argc,argv);
DoClose(browser);
}
}
示例7: init_commentary
// Initializes commentary data, reading it from the language.dat file
//
void commentary::init_commentary(Handle<Object> languageDat)
{
HandleScope scope;
// Read languageDat line by line, updating the
// commentary database
//
const Local<Array> props = languageDat->GetOwnPropertyNames();
const uint32_t length = props->Length();
Local<String> key;
Local<Array> value;
Local<String> event, comment;
char strKey[64];
char strValue[128];
for (uint32_t i=0 ; i<length ; ++i) {
key = props->Get(i)->ToString();
value = Local<Array>::Cast(languageDat->Get(key));
event = value->Get(0)->ToString();
comment = value->Get(1)->ToString();
// Add line to the commentary database
//
comm_data[toAscii(event, strKey)].push_back(toAscii(comment, strValue));
}
}
示例8: WrappedContext
Handle<Value> WrappedScript::CreateContext(const Arguments& args)
{
HandleScope scope;
Persistent<Context> context = Context::New(NULL, WrappedContext::global_template);
WrappedContext *wrappedContext = new WrappedContext(context);
Local<Object> global = context->Global();
// Allow current context access to newly created context's objects.
context->SetSecurityToken(Context::GetCurrent()->GetSecurityToken());
// If a sandbox is provided initial the new context's global with it.
if (args.Length() > 0) {
Local<Object> sandbox = args[0]->ToObject();
Local<Array> keys = sandbox->GetPropertyNames();
for (uint32_t i = 0; i < keys->Length(); i++) {
Handle<String> key = keys->Get(Integer::New(i))->ToString();
Handle<Value> value = sandbox->Get(key);
if (value == sandbox) {
value = global;
}
global->Set(key, value);
}
}
return scope.Close(global);
}
示例9:
Handle<Value> WrappedScript::CreateContext(const Arguments& args)
{
HandleScope scope;
Local<Object> context = WrappedContext::NewInstance();
WrappedContext *wrappedContext = NativeObject::Unwrap<WrappedContext>(context);
if (args.Length() > 0) {
Local<Object> sandbox = args[0]->ToObject();
Local<Array> keys = sandbox->GetPropertyNames();
for (uint32_t i = 0; i < keys->Length(); i++) {
Handle<String> key = keys->Get(Integer::New(i))->ToString();
Handle<Value> value = sandbox->Get(key);
if (value == sandbox) {
value = context;
}
context->Set(key, value);
}
if (args.Length() > 1 && args[1]->IsFunction()) {
wrappedContext->SetInitCallback(Persistent<Function>::New(Handle<Function>::Cast(args[1])));
}
}
wrappedContext->GetV8Context()->SetSecurityToken(
Context::GetCurrent()->GetSecurityToken());
return scope.Close(context);
}
示例10: FireEvent
void Server::FireEvent(std::string name, const int argc, Local<Value> argv[] ){
Locker v8Locker(isolate);
Isolate::Scope isoscope(isolate);
HandleScope hs(isolate);
Local<Context> ctx = Local<Context>::New(isolate, context);
Context::Scope cs(ctx);
TryCatch try_catch;
JS_Object global(ctx->Global());
Local<Object> serverjs = global.getObject("$server");
Local<Value> fire = serverjs->Get(String::NewFromUtf8(isolate, "fire"));
Local<Function> fn = Local<Function>::Cast(fire);
if (name == "ScriptInit"){
Local<Value> check = serverjs->Get(String::NewFromUtf8(isolate, "checkPlayers"));
Local<Function> cpfn = Local<Function>::Cast(check);
cpfn->Call(serverjs, 0, NULL);
}
Local<Value> *args = new Local<Value>[argc + 1];
args[0] = String::NewFromUtf8(isolate, name.c_str());
if (argc > 0){
for (int i = 0; i < argc; i++){
args[i + 1] = argv[i];
}
}
fn->Call(serverjs, argc + 1, args);
delete[] args;
if (try_catch.HasCaught()){
Utils::PrintException(&try_catch);
}
}
示例11: nroConstructor
/* Generic constructor wrapper.
* args[0]: row buffer
* args[1]: array of blob & text column values
* args.Data(): mapData holding the record and ColumnHandlers
* args.This(): VO built from the mapping-specific InstanceTemplate
*/
Handle<Value> nroConstructor(const Arguments &args) {
HandleScope scope;
if(args.IsConstructCall()) {
/* Unwrap record from mapData */
Local<Object> mapData = args.Data()->ToObject();
const Record * record =
unwrapPointer<const Record *>(mapData->Get(0)->ToObject());
/* Unwrap Column Handlers from mapData */
ColumnHandlerSet * handlers =
unwrapPointer<ColumnHandlerSet *>(mapData->Get(1)->ToObject());
/* Build NdbRecordObject */
NdbRecordObject * nro = new NdbRecordObject(record, handlers, args[0], args[1]);
/* Wrap for JavaScript */
wrapPointerInObject<NdbRecordObject *>(nro, nroEnvelope, args.This());
freeFromGC(nro, args.This());
}
else {
ThrowException(Exception::Error(String::New("must be a called as constructor")));
}
return args.This();
}
示例12: DoClose
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
if (!browser->IsPopup() && m_BrowserHwnd == browser->GetWindowHandle()) {
Local<Object> global = Context::GetCurrent()->Global();
Local<Object> process = global->Get(String::NewSymbol("process"))->ToObject();
Local<Object> emitter = Local<Object>::Cast(process->Get(String::NewSymbol("AppjsEmitter")));
Handle<Value> exitArgv[1] = {String::New("exit")};
node::MakeCallback(emitter,"emit",1,exitArgv);
m_Browser = NULL;
m_BrowserHwnd = NULL;
CloseMainWindow();
// Return true here so that we can skip closing the browser window
// in this pass. (It will be destroyed due to the call to close
// the parent above.)
return true;
}
// A popup browser window is not contained in another window, so we can let
// these windows close by themselves.
return false;
}
示例13: createQueryOperation
/* JS QueryOperation.create(ndbRootProjection, keyBuffer, depth)
*/
void createQueryOperation(const Arguments & args) {
DEBUG_MARKER(UDEB_DEBUG);
REQUIRE_ARGS_LENGTH(3);
Isolate * isolate = Isolate::GetCurrent();
int size = args[2]->Int32Value();
QueryOperation * queryOperation = new QueryOperation(size);
const NdbQueryOperationDef * root, * current;
Local<Value> v;
Local<Object> spec = args[0]->ToObject();
setRowBuffers(queryOperation, spec);
current = root = createTopLevelQuery(queryOperation, spec,
args[1]->ToObject());
while(! (v = spec->Get(GET_KEY(K_next)))->IsNull()) {
spec = v->ToObject();
current = createNextLevel(queryOperation, spec, current);
assert(current->getOpNo() == spec->Get(GET_KEY(K_depth))->Uint32Value());
setRowBuffers(queryOperation, spec);
}
queryOperation->prepare(root);
args.GetReturnValue().Set(QueryOperation_Wrapper(queryOperation));
}
示例14: build_buffer_map
void Msg_Struct::build_buffer_map(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate, v8::Local<v8::Value> value) {
if (!value->IsMap()) {
LOG_ERROR("field_name:%s is not map, struct_name:%s", field_info.field_name.c_str(), struct_name().c_str());
buffer.write_uint16(0);
return;
}
Local<Map> map = Local<Map>::Cast(value);
int16_t len = map->Size();
buffer.write_uint16(len);
Local<Array> array = map->AsArray();
//index N is the Nth key and index N + 1 is the Nth value.
if(is_struct(field_info.field_type)) {
for (int i = 0; i < len * 2; i = i + 2) {
Local<Value> element = array->Get(isolate->GetCurrentContext(), i + 1).ToLocalChecked();
build_buffer_struct(field_info, buffer, isolate, element);
}
}
else {
Field_Info key_info;
key_info.field_label = "args";
key_info.field_type = field_info.key_type;
key_info.field_name = field_info.key_name;
for (int i = 0; i < len * 2; i = i + 2) {
Local<Value> key = array->Get(isolate->GetCurrentContext(), i).ToLocalChecked();
Local<Value> element = array->Get(isolate->GetCurrentContext(), i + 1).ToLocalChecked();
build_buffer_struct(key_info, buffer, isolate, key);
build_buffer_struct(field_info, buffer, isolate, element);
}
}
}
示例15: cuLaunchKernel
Handle<Value> NodeCuda::Function::LaunchKernel(const Arguments& args) {
HandleScope scope;
Function *pfunction = ObjectWrap::Unwrap<Function>(args.This());
Local<Array> gridDim = Local<Array>::Cast(args[0]);
unsigned int gridDimX = gridDim->Get(0)->Uint32Value();
unsigned int gridDimY = gridDim->Get(1)->Uint32Value();
unsigned int gridDimZ = gridDim->Get(2)->Uint32Value();
Local<Array> blockDim = Local<Array>::Cast(args[1]);
unsigned int blockDimX = blockDim->Get(0)->Uint32Value();
unsigned int blockDimY = blockDim->Get(1)->Uint32Value();
unsigned int blockDimZ = blockDim->Get(2)->Uint32Value();
Local<Object> buf = args[2]->ToObject();
char *pbuffer = Buffer::Data(buf);
size_t bufferSize = Buffer::Length(buf);
void *cuExtra[] = {
CU_LAUNCH_PARAM_BUFFER_POINTER, pbuffer,
CU_LAUNCH_PARAM_BUFFER_SIZE, &bufferSize,
CU_LAUNCH_PARAM_END
};
CUresult error = cuLaunchKernel(pfunction->m_function,
gridDimX, gridDimY, gridDimZ,
blockDimX, blockDimY, blockDimZ,
0, 0, NULL, cuExtra);
return scope.Close(Number::New(error));
}