本文整理汇总了C++中Local::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::Length方法的具体用法?C++ Local::Length怎么用?C++ Local::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Setter
void BookWrap::Setter(uint32_t index, Local<Value> value, const PropertyCallbackInfo<Value>& info) {
Isolate* isolate = info.GetIsolate();
HandleScope scope(isolate);
BookWrap* bw = ObjectWrap::Unwrap<BookWrap>(info.This());
Book* b = bw->m_book;
if (value->IsArray()) {
if (index < b->size()) {
Local<v8::Array> arr = Local<v8::Array>::Cast(value);
if (arr->Length() == 3) {
const String::Utf8Value firstname(arr->Get(0)->ToString());
const String::Utf8Value lastname(arr->Get(1)->ToString());
const time_t birthday = time_t(0.001*(*arr->Get(2))->NumberValue());
Person *p = (*b)[index];
p->firstname(*firstname);
p->lastname(*lastname);
p->birthday(birthday);
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Three elements expected")));
info.GetReturnValue().SetUndefined();
return;
}
}
if (index == b->size()) {
Local<v8::Array> arr = Local<v8::Array>::Cast(value);
if (arr->Length() == 3) {
const String::Utf8Value firstname(arr->Get(0)->ToString());
const String::Utf8Value lastname(arr->Get(1)->ToString());
const time_t birthday = time_t(0.001*(*arr->Get(2))->NumberValue());
Person *p = new Person();
p->firstname(*firstname);
p->lastname(*lastname);
p->birthday(birthday);
b->add(p);
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Three elements expected")));
info.GetReturnValue().SetUndefined();
return;
}
}
else {
isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "Invalid index")));
info.GetReturnValue().SetUndefined();
return;
}
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Object expected")));
info.GetReturnValue().SetUndefined();
return;
}
info.GetReturnValue().SetUndefined();
}
示例2: keyStr
Susi::Util::Any Susi::JS::Engine::convertFromJS(Handle<Value> jsVal){
if(jsVal->IsArray()){
Susi::Util::Any::Array result;
auto obj = jsVal->ToObject();
const Local<Array> props = obj->GetPropertyNames();
const uint32_t length = props->Length();
for (uint32_t i=0 ; i<length ; ++i){
const Local<Value> key = props->Get(i);
const Local<Value> value = obj->Get(key);
result.push_back(Susi::JS::Engine::convertFromJS(value));
}
return result;
}
if(jsVal->IsObject()){
Susi::Util::Any result = Susi::Util::Any::Object{};
auto obj = jsVal->ToObject();
const Local<Array> props = obj->GetPropertyNames();
const uint32_t length = props->Length();
for (uint32_t i=0 ; i<length ; ++i){
const Local<Value> key = props->Get(i);
const Local<Value> value = obj->Get(key);
String::Utf8Value keyStr(key);
result[std::string(*keyStr)] = Susi::JS::Engine::convertFromJS(value);
}
return result;
}
if(jsVal->IsString()){
String::Utf8Value val(jsVal);
Susi::Util::Any result{std::string(*val)};
return result;
}
if(jsVal->IsNumber()){
Susi::Util::Any result{jsVal->ToNumber()->Value()};
return result;
}
if(jsVal->IsBoolean()){
Susi::Util::Any result{jsVal->ToBoolean()->Value()};
return result;
}
if(jsVal->IsNativeError()){
String::Utf8Value val(jsVal);
Susi::Util::Any result{std::string(*val)};
return result;
}
if(jsVal->IsUndefined()){
Susi::Util::Any result;
return result;
}
return Susi::Util::Any{"type not known"};
}
示例3: isGlobalAgentAlreadyLoaded
// Check if a global appmetrics agent module is already loaded.
// This is actually searching the module cache for a module with filepath
// ending .../appmetrics/launcher.js
static bool isGlobalAgentAlreadyLoaded(Handle<Object> module) {
//Nan::HandleScope scope;
Local<Object> cache = getRequireCache(module);
Local<Array> props = cache->GetOwnPropertyNames();
if (props->Length() > 0) {
for (uint32_t i=0; i<props->Length(); i++) {
Local<Value> entry = props->Get(i);
if (entry->IsString() && isAppMetricsFile("launcher.js", toStdString(entry->ToString()))) {
return true;
}
}
}
return false;
}
示例4: _setEmail
void ContactsPersonProxy::_setEmail(void* userContext, Handle<Value> value)
{
ContactsPersonProxy *obj = (ContactsPersonProxy*) userContext;
if(!value->IsObject()) return;
Handle<Object> emailObject = value->ToObject();
Local<Array> emailProperties = emailObject->GetPropertyNames();
for(int i = 0, len = emailProperties->Length(); i < len; i++)
{
Local<String> allEmailsKey = emailProperties->Get(i)->ToString();
Local<Value> allEmailsValue = emailObject->Get(allEmailsKey);
AttributeSubKind::Type subKind = AttributeSubKind::Other;
QString allEmailsKeyString = titanium::V8ValueToQString(allEmailsKey).toLower();
if(allEmailsKeyString == "work")
{
subKind = AttributeSubKind::Work;
}
else
if(allEmailsKeyString == "personal")
{
subKind = AttributeSubKind::Personal;
}
else
if(allEmailsKeyString == "home")
{
subKind = AttributeSubKind::Home;
}
if(!allEmailsValue->IsArray()) return;
Local<Array> emails = Local<Array>::Cast(allEmailsValue);
for(int i = 0, len = emails->Length(); i < len; i++)
{
Local<Value> emailValue = emails->Get(Number::New(i));
if(emailValue->IsString() || emailValue->IsNumber())
{
obj->setContactDetails(AttributeKind::Email, subKind, emailValue);
}
else
{
// Something goes here, throw an error?
}
}
}
}
示例5: 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()));
}
示例6: Undefined
Handle<Value> TiTitaniumObject::_globalInclude(void*, TiObject*, const Arguments& args)
{
if (!args.Length()) {
return Undefined();
}
bool error = false;
if (args[0]->IsArray()) {
Local<Array> ids = Local<Array>::Cast(args[0]);
uint32_t count = ids->Length();
string parentFolder = *String::Utf8Value(args[1]);
for (uint32_t i = 0; i < count; i++) {
string id = *String::Utf8Value(ids->Get(i));
Handle<Value> result = includeJavaScript(id, parentFolder, &error);
if (error) return result;
}
}
else {
for (uint32_t i = 0; i < args.Length(); i++) {
string id = *String::Utf8Value(args[i]);
Handle<Value> result = includeJavaScript(id, rootFolder, &error);
if (error) return result;
}
}
return Undefined();
}
示例7: setSharedRAM
/* Set the shared PRU RAM to an input array
* Takes an integer array as input, writes it to PRU shared memory
* Not much error checking here, don't pass in large arrays or seg faults will happen
* TODO: error checking and allow user to select range to set
*/
Handle<Value> setSharedRAM(const Arguments& args) {
HandleScope scope;
//Check we have a single argument
if (args.Length() != 1) {
ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
return scope.Close(Undefined());
}
//Check that it's an array
if (!args[0]->IsArray()) {
ThrowException(Exception::TypeError(String::New("Argument must be array")));
return scope.Close(Undefined());
}
//Get array
Local<Array> a = Array::Cast(*args[0]);
//Iterate over array
for (unsigned int i = 0; i<a->Length(); i++) {
//Get element and check it's numeric
Local<Value> element = a->Get(i);
if (!element->IsNumber()) {
ThrowException(Exception::TypeError(String::New("Array must be integer")));
return scope.Close(Undefined());
}
//Set corresponding memory bytes
sharedMem_int[OFFSET_SHAREDRAM + i] = (unsigned int) element->NumberValue();
}
//Return nothing
return scope.Close(Undefined());
};
示例8: getView
Ti::TiValue Ti::TiViewProxy::remove(Ti::TiValue value)
{
Ti::TiValue val;
val.setUndefined();
Ti::TiViewProxy *childProxy = static_cast<Ti::TiViewProxy*>(value.toProxy());
if(!_childViewsProxies.contains(childProxy)) return val;
Ti::TiView* childView = childProxy->getView();
Ti::TiView* thisView = getView();
childProxy->makeWeak();
thisView->remove(childView);
_childViewsProxies.removeOne(childProxy);
childProxy->_parentProxy = NULL;
Local<Value> children = _jsObject->Get(String::New("children"));
if(!children.IsEmpty() && !children->IsUndefined())
{
Local<Array> array = Local<Array>::Cast(children);
for(int i = 0, len = array->Length(); i < len; i++) {
if(array->Get(i) == value.toJSValue())
{
array->Delete(i);
break;
}
}
}
return val;
}
示例9:
jsvalue JsEngine::WrappedFromV8(Handle<Object> obj)
{
jsvalue v;
if (js_object_marshal_type == JSOBJECT_MARSHAL_TYPE_DYNAMIC) {
v.type = JSVALUE_TYPE_WRAPPED;
v.length = 0;
// A Persistent<Object> is exactly the size of an IntPtr, right?
// If not we're in deep deep trouble (on IA32 and AMD64 should be).
// We should even cast it to void* because C++ doesn't allow to put
// it in a union: going scary and scarier here.
v.value.ptr = new Persistent<Object>(Persistent<Object>::New(obj));
} else {
v.type = JSVALUE_TYPE_DICT;
Local<Array> names = obj->GetOwnPropertyNames();
v.length = names->Length();
jsvalue* values = new jsvalue[v.length * 2];
if (values != NULL) {
for(int i = 0; i < v.length; i++) {
int indx = (i * 2);
Local<Value> key = names->Get(i);
values[indx] = AnyFromV8(key);
values[indx+1] = AnyFromV8(obj->Get(key));
}
v.value.arr = values;
}
}
return v;
}
示例10: ThrowException
static Handle<Value> waitForEvents(const Arguments& args)
{
if (!args[0]->IsArray())
ThrowException(Exception::Error(String::New("CL_INVALID_VALUE")));
Local<Array> eventsArray = Array::Cast(*args[0]);
std::vector<const EventWrapper*> events;
for (int i=0; i<eventsArray->Length(); i++) {
Local<Object> obj = eventsArray->Get(i)->ToObject();
EventWrapper *e = ObjectWrap::Unwrap<Event>(obj)->getEventWrapper();
events.push_back(e);
}
cl_int ret = ContextWrapper::waitForEvents(events);
if (ret != CL_SUCCESS) {
WEBCL_COND_RETURN_THROW(CL_INVALID_VALUE);
WEBCL_COND_RETURN_THROW(CL_INVALID_CONTEXT);
WEBCL_COND_RETURN_THROW(CL_INVALID_EVENT);
WEBCL_COND_RETURN_THROW(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST);
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 Undefined();
}
示例11:
jobjectArray JNIV8Object::jniGetV8Keys(JNIEnv *env, jobject obj, jboolean ownOnly) {
JNIV8Object_PrepareJNICall(JNIV8Object, Object, nullptr);
MaybeLocal<Array> maybeArrayRef = ownOnly ? localRef->GetOwnPropertyNames(context) : localRef->GetPropertyNames();
if(maybeArrayRef.IsEmpty()) {
ptr->getEngine()->forwardV8ExceptionToJNI(&try_catch);
return nullptr;
}
Local<Array> arrayRef = maybeArrayRef.ToLocalChecked();
Local<Value> valueRef;
jobjectArray result = nullptr;
jstring string;
std::string test;
for(uint32_t i=0,n=arrayRef->Length(); i<n; i++) {
MaybeLocal<Value> maybeValueRef = arrayRef->Get(context, i);
if(!maybeValueRef.ToLocal<Value>(&valueRef)) {
ptr->getEngine()->forwardV8ExceptionToJNI(&try_catch);
return nullptr;
}
string = JNIV8Marshalling::v8string2jstring(valueRef->ToString(isolate));
if(!result) {
result = env->NewObjectArray(n, _jniString.clazz, string);
} else {
env->SetObjectArrayElement(result, i, string);
}
env->DeleteLocalRef(string);
}
return result;
}
示例12: result
static std::string toStdString(Local<String> s) {
char *buf = new char[s->Length() + 1];
s->WriteUtf8(buf);
std::string result(buf);
delete[] buf;
return result;
}
示例13: if
void
encodeArray(bson_buffer *bb, const char *name, const Local<Value> element) {
Local<Array> a = Array::Cast(*element);
bson_buffer *arr = bson_append_start_array(bb, name);
for (int i = 0, l=a->Length(); i < l; i++) {
Local<Value> val = a->Get(Number::New(i));
stringstream keybuf;
string keyval;
keybuf << i << endl;
keybuf >> keyval;
if (val->IsString()) {
encodeString(arr, keyval.c_str(), val);
}
else if (val->IsInt32()) {
encodeInteger(arr, keyval.c_str(), val);
}
else if (val->IsNumber()) {
encodeNumber(arr, keyval.c_str(), val);
}
else if (val->IsBoolean()) {
encodeBoolean(arr, keyval.c_str(), val);
}
else if (val->IsArray()) {
encodeArray(arr, keyval.c_str(), val);
}
else if (val->IsObject()) {
bson bson(encodeObject(val));
bson_append_bson(arr, keyval.c_str(), &bson);
bson_destroy(&bson);
}
}
bson_append_finish_object(arr);
}
示例14: TitaniumCountlyAndroidMessaging_dispose
static void TitaniumCountlyAndroidMessaging_dispose()
{
HandleScope scope;
if (bindingCache.IsEmpty()) {
return;
}
Local<Array> propertyNames = bindingCache->GetPropertyNames();
uint32_t length = propertyNames->Length();
for (uint32_t i = 0; i < length; ++i) {
String::Utf8Value binding(propertyNames->Get(i));
int bindingLength = binding.length();
titanium::bindings::BindEntry *extBinding =
::TitaniumCountlyAndroidMessagingBindings::lookupGeneratedInit(*binding, bindingLength);
if (extBinding && extBinding->dispose) {
extBinding->dispose();
}
}
bindingCache.Dispose();
bindingCache = Persistent<Object>();
}
开发者ID:Arthien,项目名称:countly-sdk-appcelerator-titanium-android,代码行数:25,代码来源:TitaniumCountlyAndroidMessagingBootstrap.cpp
示例15: 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();
}