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); }
void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* ctx_w) { NanScope(); if (returned_value->IsArray()) { Handle<Array> array = Handle<Array>::Cast(returned_value); ctx_w->imports = sass_make_import_list(array->Length()); for (size_t i = 0; i < array->Length(); ++i) { Local<Value> value = array->Get(i); if (!value->IsObject()) continue; Local<Object> object = Local<Object>::Cast(value); char* path = create_string(object->Get(NanNew<String>("file"))); char* contents = create_string(object->Get(NanNew<String>("contents"))); ctx_w->imports[i] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0); } } else if (returned_value->IsObject()) { ctx_w->imports = sass_make_import_list(1); Local<Object> object = Local<Object>::Cast(returned_value); char* path = create_string(object->Get(NanNew<String>("file"))); char* contents = create_string(object->Get(NanNew<String>("contents"))); ctx_w->imports[0] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0); } else { ctx_w->imports = sass_make_import_list(1); ctx_w->imports[0] = sass_make_import_entry(ctx_w->file, 0, 0); } }
int SerializePart(google::protobuf::Message *message, Handle<Object> subj) { NanScope(); // get a reflection const Reflection *r = message->GetReflection(); const Descriptor *d = message->GetDescriptor(); // build a list of required properties vector<string> required; for (int i = 0; i < d->field_count(); i++) { const FieldDescriptor *field = d->field(i); if (field->is_required()) required.push_back(field->name()); } // build a reflection // get properties of passed object Local<Array> properties = subj->GetPropertyNames(); uint32_t len = properties->Length(); // check that all required properties are present for (uint32_t i = 0; i < required.size(); i++) { Handle<String> key = String::New(required.at(i).c_str()); if (!subj->Has(key)) return -1; } for (uint32_t i = 0; i < len; i++) { Local<Value> property = properties->Get(i); Local<String> property_s = property->ToString(); if (*property_s == NULL) continue; String::Utf8Value temp(property); std::string propertyName = std::string(*temp); const FieldDescriptor *field = d->FindFieldByName(propertyName); if (field == NULL) continue; Local<Value> val = subj->Get(property); if (field->is_repeated()) { if (!val->IsArray()) continue; Handle<Array> array = val.As<Array>(); int len = array->Length(); for (int i = 0; i < len; i++) SerializeField(message, r, field, array->Get(i)); } else { SerializeField(message, r, field, val); } } return 0; }
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(); }
void V8BuilderPolicy::AppendToDictKeyList(std::string const & _key, type const & var) { Nan::HandleScope scope; Local<Value> object(Nan::New(object_)); assert(object->IsObject()); Local<Object> obj = Local<Object>::Cast(object); KeyMap::const_iterator k_it = keys_.find(_key); if (k_it == keys_.end()) { Nan::Persistent<v8::String> * pers_key = new Nan::Persistent<v8::String>(Nan::New(_key).ToLocalChecked()); keys_[_key] = pers_key; k_it = keys_.find(_key); } Local<String> key = Nan::New(*k_it->second); // Local<String> key = Nan::New(_key).ToLocalChecked(); if (obj->Has(key)) { Local<Value> value = obj->Get(key); if (value->IsArray()) { Local<Array> arr = Local<Array>::Cast(value); arr->Set(arr->Length(), Nan::New(var)); } else { Local<Array> arr(Nan::New<Array>()); arr->Set(0, value); arr->Set(1, Nan::New(var)); obj->Set(key, arr); } } else { if (options_.explicit_array_) { Local<Array> arr(Nan::New<Array>()); arr->Set(0, Nan::New(var)); obj->Set(key, arr); } else { obj->Set(key, Nan::New(var)); } } }
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? } } } }
void PDFPageDriver::SetMediaBox(Local<String> property,Local<Value> value,const AccessorInfo &info) { HandleScope scope; PDFPageDriver* pageDriver = ObjectWrap::Unwrap<PDFPageDriver>(info.Holder()); if(!value->IsArray()) ThrowException(Exception::TypeError(String::New("Media box is set to a value which is not a 4 numbers array"))); if(value->ToObject()->Get(v8::String::New("length"))->ToObject()->Uint32Value() != 4) ThrowException(Exception::TypeError(String::New("Media box is set to a value which is not a 4 numbers array"))); pageDriver->mPDFPage->SetMediaBox(PDFRectangle(value->ToObject()->Get(0)->ToNumber()->Value(), value->ToObject()->Get(1)->ToNumber()->Value(), value->ToObject()->Get(2)->ToNumber()->Value(), value->ToObject()->Get(3)->ToNumber()->Value())); }
static GetdnsType getGetdnsType(Local<Value> value) { if (value->IsNumber() || value->IsNumberObject()) { return IntType; } else if (value->IsBoolean() || value->IsBooleanObject()) { return BoolType; } else if (value->IsString() || value->IsStringObject()) { return StringType; } else if (value->IsObject()) { // could be a node buffer or array if (node::Buffer::HasInstance(value)) { return BinDataType; } else if (value->IsArray()) { return ListType; } else if (GNUtil::isDictionaryObject(value)) { return DictType; } } return UnknownType; }
static void setUpstreams(getdns_context* context, Handle<Value> opt) { if (opt->IsArray()) { getdns_list* upstreams = getdns_list_create(); Handle<Array> values = Handle<Array>::Cast(opt); for (uint32_t i = 0; i < values->Length(); ++i) { Local<Value> ipOrTuple = values->Get(i); getdns_dict* ipDict = NULL; if (ipOrTuple->IsArray()) { // two tuple - first is IP, 2nd is port Handle<Array> tuple = Handle<Array>::Cast(ipOrTuple); if (tuple->Length() > 0) { String::AsciiValue asciiStr(tuple->Get(0)->ToString()); ipDict = getdns_util_create_ip(*asciiStr); if (ipDict && tuple->Length() > 1 && tuple->Get(1)->IsNumber()) { // port uint32_t port = tuple->Get(1)->Uint32Value(); getdns_dict_set_int(ipDict, "port", port); } } } else { String::AsciiValue asciiStr(ipOrTuple->ToString()); ipDict = getdns_util_create_ip(*asciiStr); } if (ipDict) { size_t len = 0; getdns_list_get_length(upstreams, &len); getdns_list_set_dict(upstreams, len, ipDict); getdns_dict_destroy(ipDict); } else { Local<String> msg = String::Concat(String::New("Upstream value is invalid: "), ipOrTuple->ToString()); ThrowException(Exception::TypeError(msg)); } } getdns_return_t r = getdns_context_set_upstream_recursive_servers(context, upstreams); getdns_list_destroy(upstreams); if (r != GETDNS_RETURN_GOOD) { ThrowException(Exception::TypeError(String::New("Failed to set upstreams."))); } } }
void ContactsPersonProxy::_setPhone(void* userContext, Handle<Value> value) { ContactsPersonProxy *obj = (ContactsPersonProxy*) userContext; if(!value->IsObject()) return; Handle<Object> phoneObject = value->ToObject(); Local<Array> phoneProperties = phoneObject->GetPropertyNames(); for(int i = 0, len = phoneProperties->Length(); i < len; i++) { Local<String> phoneKey = phoneProperties->Get(i)->ToString(); Local<Value> phoneValue = phoneObject->Get(phoneKey); AttributeSubKind::Type subKind = AttributeSubKind::Other; QString phoneStringValue = titanium::V8ValueToQString(phoneKey); if(phoneStringValue == "home") { subKind = AttributeSubKind::Home; } else if(phoneStringValue == "work") { subKind = AttributeSubKind::Work; } else if(phoneStringValue == "mobile") { subKind = AttributeSubKind::PhoneMobile; } if(!phoneValue->IsArray()) return; Local<Array> phones = Local<Array>::Cast(phoneValue); for(int i = 0, len = phones->Length(); i < len; i++) { Local<Value> currentMessage = phones->Get(Number::New(i)); if(!currentMessage->IsString()) return; obj->setContactDetails(AttributeKind::Phone, subKind, currentMessage); } } }
void SerializePart(google::protobuf::Message *message, Handle<Object> src) { Handle<Function> to_array = handle_->GetInternalField(3).As<Function>(); Handle<Array> properties = to_array->Call(src, 0, NULL).As<Array>(); const Reflection *r = message->GetReflection(); for (int i = 0; i < descriptor->field_count(); i++) { Local<Value> value = properties->Get(i); if (value->IsUndefined() || value->IsNull()) continue; const FieldDescriptor* field = descriptor->field(i); if (field->is_repeated()) { if (value->IsArray()) { Handle<Array> array = value.As<Array>(); int length = array->Length(); for (int j = 0; j < length; j++) SerializeField(message, r, field, array->Get(j)); } else if (value->IsObject() && field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && field->message_type()->name().compare(0, 20, "KeyValuePair_String_") == 0) { Local<Object> object = value.As<Object>(); Local<Array> subProperties = object->GetOwnPropertyNames(); int len = subProperties->Length(); for (int keyIdx = 0; keyIdx < len; keyIdx++) { Local<Object> keyValuePair = Object::New(); Local<Value> key = subProperties->Get(keyIdx); keyValuePair->Set(KeySymbol, key); keyValuePair->Set(ValueSymbol, object->Get(key)); SerializeField(message, r, field, keyValuePair); } } } else { SerializeField(message, r, field, value); } } }
Handle<Value> Session::Request(const Arguments& args) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsString()) { return ThrowException(Exception::Error(String::New( "Service URI string must be provided as first parameter."))); } if (args.Length() < 2 || !args[1]->IsString()) { return ThrowException(Exception::Error(String::New( "String request name must be provided as second parameter."))); } if (args.Length() < 3 || !args[2]->IsObject()) { return ThrowException(Exception::Error(String::New( "Object containing request parameters must be provided " "as third parameter."))); } if (args.Length() < 4 || !args[3]->IsInt32()) { return ThrowException(Exception::Error(String::New( "Integer correlation identifier must be provided " "as fourth parameter."))); } if (args.Length() >= 5 && !args[4]->IsUndefined() && !args[4]->IsString()) { return ThrowException(Exception::Error(String::New( "Optional request label must be a string."))); } if (args.Length() > 5) { return ThrowException(Exception::Error(String::New( "Function expects at most five arguments."))); } int cidi = args[3]->Int32Value(); Session* session = ObjectWrap::Unwrap<Session>(args.This()); BLPAPI_EXCEPTION_TRY Local<String> uri = args[0]->ToString(); String::AsciiValue uriv(uri); blpapi::Service service = session->d_session->getService(*uriv); Local<String> name = args[1]->ToString(); String::Utf8Value namev(name); blpapi::Request request = service.createRequest(*namev); // Loop over object properties, appending/setting into the request. Local<Object> obj = args[2]->ToObject(); Local<Array> props = obj->GetPropertyNames(); for (std::size_t i = 0; i < props->Length(); ++i) { // Process the key. Local<Value> keyval = props->Get(i); Local<String> key = keyval->ToString(); String::Utf8Value keyv(key); // Process the value. // // The values present on the outer object are marshalled into the // blpapi::Request by setting values using 'set'. Arrays indicate // values which should be marshalled using 'append'. Local<Value> val = obj->Get(keyval); if (val->IsString()) { Local<String> s = val->ToString(); String::Utf8Value valv(s); request.set(*keyv, *valv); } else if (val->IsBoolean()) { request.set(*keyv, val->BooleanValue()); } else if (val->IsNumber()) { request.set(*keyv, val->NumberValue()); } else if (val->IsInt32()) { request.set(*keyv, val->Int32Value()); } else if (val->IsUint32()) { request.set(*keyv, static_cast<blpapi::Int64>(val->Uint32Value())); } else if (val->IsDate()) { blpapi::Datetime dt; mkdatetime(&dt, val); request.set(*keyv, dt); } else if (val->IsArray()) { // Arrays are marshalled into the blpapi::Request by appending // value types using the key of the array in the outer object. Local<Object> subarray = val->ToObject(); int jmax = Array::Cast(*val)->Length(); for (int j = 0; j < jmax; ++j) { Local<Value> subval = subarray->Get(j); // Only strings, booleans, and numbers are marshalled. if (subval->IsString()) { Local<String> s = subval->ToString(); String::Utf8Value subvalv(s); request.append(*keyv, *subvalv); } else if (subval->IsBoolean()) { request.append(*keyv, subval->BooleanValue()); } else if (subval->IsNumber()) { request.append(*keyv, subval->NumberValue()); } else if (subval->IsInt32()) { request.append(*keyv, subval->Int32Value()); } else if (subval->IsUint32()) { request.append(*keyv, static_cast<blpapi::Int64>(subval->Uint32Value())); } else if (subval->IsDate()) { blpapi::Datetime dt; mkdatetime(&dt, subval); request.append(*keyv, dt); } else { return ThrowException(Exception::Error(String::New( "Array contains invalid value type."))); } } } else { return ThrowException(Exception::Error(String::New( "Object contains invalid value type."))); } } blpapi::CorrelationId cid(cidi); if (args.Length() == 5) { String::Utf8Value labelv(args[4]->ToString()); session->d_session->sendRequest(request, session->d_identity, cid, 0, *labelv, labelv.length()); } else { session->d_session->sendRequest(request, session->d_identity, cid); } BLPAPI_EXCEPTION_CATCH_RETURN return scope.Close(Integer::New(cidi)); }
Handle<Value> Session::subscribe(const Arguments& args, bool resubscribe) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsArray()) { return ThrowException(Exception::Error(String::New( "Array of subscription information must be provided."))); } if (args.Length() >= 2 && !args[1]->IsUndefined() && !args[1]->IsString()) { return ThrowException(Exception::Error(String::New( "Optional subscription label must be a string."))); } if (args.Length() > 2) { return ThrowException(Exception::Error(String::New( "Function expects at most two arguments."))); } blpapi::SubscriptionList sl; Local<Object> o = args[0]->ToObject(); for (std::size_t i = 0; i < Array::Cast(*(args[0]))->Length(); ++i) { Local<Value> v = o->Get(i); if (!v->IsObject()) { return ThrowException(Exception::Error(String::New( "Array elements must be objects " "containing subscription information."))); } Local<Object> io = v->ToObject(); // Process 'security' string Local<Value> iv = io->Get(String::New("security")); if (!iv->IsString()) { return ThrowException(Exception::Error(String::New( "Property 'security' must be a string."))); } String::Utf8Value secv(iv); if (0 == secv.length()) { return ThrowException(Exception::Error(String::New( "Property 'security' must be a string."))); } // Process 'fields' array iv = io->Get(String::New("fields")); if (!iv->IsArray()) { return ThrowException(Exception::Error(String::New( "Property 'fields' must be an array of strings."))); } std::string fields; formFields(&fields, iv->ToObject()); // Process 'options' array iv = io->Get(String::New("options")); if (!iv->IsUndefined() && !iv->IsNull() && !iv->IsObject()) { return ThrowException(Exception::Error(String::New( "Property 'options' must be an object containing " "whose keys and key values will be configured as " "options."))); } std::string options; formOptions(&options, iv); // Process 'correlation' int or string iv = io->Get(String::New("correlation")); if (!iv->IsInt32()) { return ThrowException(Exception::Error(String::New( "Property 'correlation' must be an integer."))); } int correlation = iv->Int32Value(); sl.add(*secv, fields.c_str(), options.c_str(), blpapi::CorrelationId(correlation)); } Session* session = ObjectWrap::Unwrap<Session>(args.This()); BLPAPI_EXCEPTION_TRY if (args.Length() == 2) { Local<String> s = args[1]->ToString(); String::Utf8Value labelv(s); if (resubscribe) session->d_session->resubscribe(sl, *labelv, labelv.length()); else session->d_session->subscribe(sl, *labelv, labelv.length()); } else { if (resubscribe) session->d_session->resubscribe(sl); else session->d_session->subscribe(sl); } BLPAPI_EXCEPTION_CATCH_RETURN return scope.Close(args.This()); }
DBScanHelper::DBScanHelper(const Arguments &args) : nbounds(0), isIndexScan(false) { DEBUG_MARKER(UDEB_DEBUG); Local<Value> v; const Local<Object> spec = args[0]->ToObject(); int opcode = args[1]->Int32Value(); tx = unwrapPointer<NdbTransaction *>(args[2]->ToObject()); lmode = NdbOperation::LM_CommittedRead; scan_options = & options; options.optionsPresent = 0ULL; v = spec->Get(SCAN_TABLE_RECORD); if(! v->IsNull()) { Local<Object> o = v->ToObject(); row_record = unwrapPointer<const Record *>(o); } v = spec->Get(SCAN_INDEX_RECORD); if(! v->IsNull()) { Local<Object> o = v->ToObject(); isIndexScan = true; key_record = unwrapPointer<const Record *>(o); } v = spec->Get(SCAN_LOCK_MODE); if(! v->IsNull()) { int intLockMode = v->Int32Value(); lmode = static_cast<NdbOperation::LockMode>(intLockMode); } // SCAN_BOUNDS is an array of BoundHelpers v = spec->Get(SCAN_BOUNDS); if(v->IsArray()) { Local<Object> o = v->ToObject(); while(o->Has(nbounds)) { nbounds++; } bounds = new NdbIndexScanOperation::IndexBound *[nbounds]; for(int i = 0 ; i < nbounds ; i++) { Local<Object> b = o->Get(i)->ToObject(); bounds[i] = unwrapPointer<NdbIndexScanOperation::IndexBound *>(b); } } v = spec->Get(SCAN_OPTION_FLAGS); if(! v->IsNull()) { options.scan_flags = v->Uint32Value(); options.optionsPresent |= NdbScanOperation::ScanOptions::SO_SCANFLAGS; } v = spec->Get(SCAN_OPTION_BATCH_SIZE); if(! v->IsNull()) { options.batch = v->Uint32Value(); options.optionsPresent |= NdbScanOperation::ScanOptions::SO_BATCH; } v = spec->Get(SCAN_OPTION_PARALLELISM); if(! v->IsNull()) { options.parallel = v->Uint32Value(); options.optionsPresent |= NdbScanOperation::ScanOptions::SO_PARALLEL; } v = spec->Get(SCAN_FILTER_CODE); if(! v->IsNull()) { Local<Object> o = v->ToObject(); options.interpretedCode = unwrapPointer<NdbInterpretedCode *>(o); options.optionsPresent |= NdbScanOperation::ScanOptions::SO_INTERPRETED; } /* Scanning delete requires key info */ if(opcode == OP_SCAN_DELETE) { options.scan_flags |= NdbScanOperation::SF_KeyInfo; options.optionsPresent |= NdbScanOperation::ScanOptions::SO_SCANFLAGS; } /* Done defining the object */ }
void JSZCluster::checkArgument(const v8::FunctionCallbackInfo<v8::Value> &info, unsigned int index, const std::shared_ptr<ClusterCmdParamsBase> &cmdParam) { if (info.Length() <= ((int) index + 1)) { stringstream stream; stream << EXECUTE_CMD_BY_ID << " needs almost " << index << " arguments where the first is the cmd"; throw JSException(stream.str()); } Local<v8::Value> arg = info[index + 1]; switch (cmdParam->getZCLDataType()) { case ZCLTypeDataType::ZCLTypeUInt8: case ZCLTypeDataType::ZCLTypeUInt16: case ZCLTypeDataType::ZCLTypeUInt24: case ZCLTypeDataType::ZCLTypeUInt32: case ZCLTypeDataType::ZCLTypeUInt40: case ZCLTypeDataType::ZCLTypeUInt48: case ZCLTypeDataType::ZCLTypeUInt56: case ZCLTypeDataType::ZCLTypeUInt64: if (!arg->IsUint32()) { stringstream stream; stream << EXECUTE_CMD_BY_ID << " needs as argument " << index << " an unsigned integer"; throw JSException(stream.str()); } break; case ZCLTypeDataType::ZCLTypeSInt8: case ZCLTypeDataType::ZCLTypeSInt16: case ZCLTypeDataType::ZCLTypeSInt24: case ZCLTypeDataType::ZCLTypeSInt32: case ZCLTypeDataType::ZCLTypeSInt40: case ZCLTypeDataType::ZCLTypeSInt48: case ZCLTypeDataType::ZCLTypeSInt56: case ZCLTypeDataType::ZCLTypeSInt64: if (!arg->IsInt32()) { stringstream stream; stream << EXECUTE_CMD_BY_ID << " needs as argument " << index << " an integer"; throw JSException(stream.str()); } break; case ZCLTypeDataType::ZCLTypeIEEEaddress: case ZCLTypeDataType::ZCLTypeStringChar: if (!arg->IsString()) { stringstream stream; stream << EXECUTE_CMD_BY_ID << " needs as argument " << index << " a string"; throw JSException(stream.str()); } break; case ZCLTypeDataType::ZCLTypeArray: if (!arg->IsUint32Array() && !arg->IsUint32Array()) { if (!arg->IsArray()) { stringstream stream; stream << EXECUTE_CMD_BY_ID << " needs as argument " << index << " an array"; throw JSException(stream.str()); } } break; default: stringstream stream; stream << EXECUTE_CMD_BY_ID << " needs as argument " << index << " a type " << cmdParam->getZCLDataType() << " the it is not managed"; throw JSException(stream.str()); } }
ScanOperation::ScanOperation(const Arguments &args) : KeyOperation(), scan_op(0), index_scan_op(0), nbounds(0), isIndexScan(false) { DEBUG_MARKER(UDEB_DEBUG); Local<Value> v; const Local<Object> spec = args[0]->ToObject(); opcode = args[1]->Int32Value(); ctx = unwrapPointer<TransactionImpl *>(args[2]->ToObject()); lmode = NdbOperation::LM_CommittedRead; scan_options.scan_flags = 0; scan_options.optionsPresent = 0ULL; v = spec->Get(SCAN_TABLE_RECORD); if(! v->IsNull()) { Local<Object> o = v->ToObject(); row_record = unwrapPointer<const Record *>(o); createBlobReadHandles(row_record); } v = spec->Get(SCAN_INDEX_RECORD); if(! v->IsNull()) { Local<Object> o = v->ToObject(); isIndexScan = true; key_record = unwrapPointer<const Record *>(o); } v = spec->Get(SCAN_LOCK_MODE); if(! v->IsNull()) { int intLockMode = v->Int32Value(); DEBUG_PRINT("Scan lock mode %d", intLockMode); lmode = static_cast<NdbOperation::LockMode>(intLockMode); } // SCAN_BOUNDS is an array of BoundHelpers v = spec->Get(SCAN_BOUNDS); if(v->IsArray()) { Local<Object> o = v->ToObject(); while(o->Has(nbounds)) { nbounds++; } DEBUG_PRINT("Index Scan with %d IndexBounds", nbounds); bounds = new NdbIndexScanOperation::IndexBound *[nbounds]; for(int i = 0 ; i < nbounds ; i++) { Local<Object> b = o->Get(i)->ToObject(); bounds[i] = unwrapPointer<NdbIndexScanOperation::IndexBound *>(b); } } v = spec->Get(SCAN_OPTION_FLAGS); if(! v->IsNull()) { scan_options.scan_flags = v->Uint32Value(); } v = spec->Get(SCAN_OPTION_BATCH_SIZE); if(! v->IsNull()) { scan_options.batch = v->Uint32Value(); scan_options.optionsPresent |= NdbScanOperation::ScanOptions::SO_BATCH; } v = spec->Get(SCAN_OPTION_PARALLELISM); if(! v->IsNull()) { scan_options.parallel = v->Uint32Value(); scan_options.optionsPresent |= NdbScanOperation::ScanOptions::SO_PARALLEL; } v = spec->Get(SCAN_FILTER_CODE); if(! v->IsNull()) { Local<Object> o = v->ToObject(); scan_options.interpretedCode = unwrapPointer<NdbInterpretedCode *>(o); scan_options.optionsPresent |= NdbScanOperation::ScanOptions::SO_INTERPRETED; } /* Scanning delete requires key info */ if(opcode == OP_SCAN_DELETE) { scan_options.scan_flags |= NdbScanOperation::SF_KeyInfo; } /* If any flags were set, also set SO_SCANFLAGS options */ if(scan_options.scan_flags != 0) { scan_options.optionsPresent |= NdbScanOperation::ScanOptions::SO_SCANFLAGS; } /* Done defining the object */ debug_print_flags_and_options(scan_options); }
bool GNUtil::isDictionaryObject(Local<Value> obj) { return obj->IsObject() && !(obj->IsRegExp() || obj->IsDate() || obj->IsFunction() || obj->IsArray()); }
Handle<Value> Compute(const Arguments& args) { HandleScope scope; Local<Value> v = args[1]; //make sure args is an array if(v->IsArray()) { Local<Array> arr = Local<Array>::Cast(v); int length = 0; length = arr->Get(String::New("length"))->ToObject()->Uint32Value(); std::vector<double> myArgs(length); //convert the v8::Array to a std::vector<double> for(int i=0; i<length; i++) { //check to make sure each value is a valid number, if not throw exception if(arr->Get(Number::New(i))->IsNumber()) myArgs[i] = arr->Get(Number::New(i))->ToObject()->NumberValue(); else { ThrowException(Exception::TypeError(String::New("Invalid values in array."))); return scope.Close(Undefined()); } } //use our new std::vector in our external library String::Utf8Value inputString(args[0]->ToString()); std::string arg1 = *inputString; if(!(arg1 == "add" || arg1 == "subtract" || arg1 == "multiply")) { ThrowException(Exception::TypeError(String::New("Arg1 must be 'add', 'subtract', 'multiply'"))); return scope.Close(Undefined()); } else { myMath myMathObj; double result = 0; if(arg1 == "add") result = myMathObj.add(myArgs); else if(arg1 == "subtract") result = myMathObj.subtract(myArgs); else if(arg1 == "multiply") result = myMathObj.multiply(myArgs); //convert result back to v8 number object and return it return scope.Close(Number::New(result)); } } else { //throw exception ThrowException(Exception::TypeError(String::New("2nd argument must be an array."))); return scope.Close(Undefined()); } }
Handle<Value> Query::New(Arguments const& args) { HandleScope scope; if (!args.IsConstructCall()) { return ThrowException(Exception::Error(String::New("Cannot call constructor as function, you need to use 'new' keyword"))); } try { if (args.Length() != 1) { return ThrowException(Exception::TypeError(String::New("please provide an object of options for the first argument"))); } if (!args[0]->IsObject()) { return ThrowException(Exception::TypeError(String::New("first argument must be an object"))); } Local<Object> obj = args[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined()) { return ThrowException(Exception::TypeError(String::New("first arg must be an object"))); } if (!obj->Has(String::New("coordinates"))) { return ThrowException(Exception::TypeError(String::New("must provide a coordinates property"))); } Local<Value> coordinates = obj->Get(String::New("coordinates")); if (!coordinates->IsArray()) { return ThrowException(Exception::TypeError(String::New("coordinates must be an array of (lat/long) pairs"))); } // Handle scenario in which caller explicitly specified service std::string service; if (obj->Has(String::New("service"))) { Local<Value> serviceValue = obj->Get(String::New("service")); v8::String::Utf8Value serviceUtf8Value(serviceValue->ToString()); service = std::string(*serviceUtf8Value); } // Handle 'nearest', otherwise assume 'viaroute' service. if (service == "nearest" || service == "locate") { Local<Array> coordinates_array = Local<Array>::Cast(coordinates); if (coordinates_array->Length() != 1) { return ThrowException(Exception::TypeError(String::New("coordinates array should only have one lat/long pair for 'nearest' or 'locate' queries"))); } Local<Value> coordinate = coordinates_array->Get(0); if (!coordinate->IsArray()) { return ThrowException(Exception::TypeError(String::New("coordinates must be an array of (lat/long) pairs"))); } Local<Array> coordinate_array = Local<Array>::Cast(coordinate); if (coordinate_array->Length() != 2) { return ThrowException(Exception::TypeError(String::New("coordinates must be an array of (lat/long) pairs"))); } Query* q = new Query(); q->this_->service = service; q->this_->coordinates.push_back( FixedPointCoordinate(coordinate_array->Get(0)->NumberValue()*COORDINATE_PRECISION, coordinate_array->Get(1)->NumberValue()*COORDINATE_PRECISION)); q->Wrap(args.This()); return args.This(); } Local<Array> coordinates_array = Local<Array>::Cast(coordinates); if (coordinates_array->Length() < 2) { return ThrowException(Exception::TypeError(String::New("at least two coordinates must be provided"))); } Query* q = new Query(); q->this_->zoomLevel = 18; //no generalization q->this_->printInstructions = false; //turn by turn instructions q->this_->alternateRoute = true; //get an alternate route, too q->this_->geometry = true; //retrieve geometry of route q->this_->compression = true; //polyline encoding q->this_->checkSum = UINT_MAX; //see wiki q->this_->service = "viaroute"; //that's routing q->this_->outputFormat = "json"; q->this_->jsonpParameter = ""; //set for jsonp wrapping q->this_->language = ""; //unused atm if (obj->Has(String::New("alternateRoute"))) { q->this_->alternateRoute = obj->Get(String::New("alternateRoute"))->BooleanValue(); } if (obj->Has(String::New("checksum"))) { q->this_->checkSum = static_cast<unsigned>(obj->Get(String::New("checksum"))->Uint32Value()); } if (obj->Has(String::New("zoomLevel"))) { q->this_->zoomLevel = static_cast<short>(obj->Get(String::New("zoomLevel"))->Int32Value()); } if (obj->Has(String::New("printInstructions"))) { q->this_->printInstructions = obj->Get(String::New("printInstructions"))->BooleanValue(); } if (obj->Has(String::New("jsonpParameter"))) { q->this_->jsonpParameter = *v8::String::Utf8Value(obj->Get(String::New("jsonpParameter"))); } if (obj->Has(String::New("hints"))) { Local<Value> hints = obj->Get(String::New("hints")); if (!hints->IsArray()) { return ThrowException(Exception::TypeError(String::New("hints must be an array of strings/null"))); } Local<Array> hints_array = Local<Array>::Cast(hints); for (uint32_t i = 0; i < hints_array->Length(); ++i) { Local<Value> hint = hints_array->Get(i); if (hint->IsString()) { q->this_->hints.push_back(*v8::String::Utf8Value(hint)); } else if(hint->IsNull()){ q->this_->hints.push_back(""); }else{ return ThrowException(Exception::TypeError(String::New("hint must be null or string"))); } } } for (uint32_t i = 0; i < coordinates_array->Length(); ++i) { Local<Value> coordinate = coordinates_array->Get(i); if (!coordinate->IsArray()) { return ThrowException(Exception::TypeError(String::New("coordinates must be an array of (lat/long) pairs"))); } Local<Array> coordinate_array = Local<Array>::Cast(coordinate); if (coordinate_array->Length() != 2) { return ThrowException(Exception::TypeError(String::New("coordinates must be an array of (lat/long) pairs"))); } q->this_->coordinates.push_back( FixedPointCoordinate(coordinate_array->Get(0)->NumberValue()*COORDINATE_PRECISION, coordinate_array->Get(1)->NumberValue()*COORDINATE_PRECISION)); } q->Wrap(args.This()); return args.This(); } catch (std::exception const& ex) { return ThrowException(Exception::TypeError(String::New(ex.what()))); } return Undefined(); }
Handle<Value> Query::New(Arguments const& args) { HandleScope scope; if (!args.IsConstructCall()) { return ThrowException(Exception::Error(String::New("Cannot call constructor as function, you need to use 'new' keyword"))); } try { if (args.Length() != 1) { return ThrowException(Exception::TypeError(String::New("please provide an object of options for the first argument"))); } if (!args[0]->IsObject()) { return ThrowException(Exception::TypeError(String::New("first argument must be an object"))); } Local<Object> obj = args[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined()) { return ThrowException(Exception::TypeError(String::New("first arg must be an object"))); } if (!obj->Has(String::NewSymbol("coordinates"))) { return ThrowException(Exception::TypeError(String::New("must provide a coordinates property"))); } Local<Value> coordinates = obj->Get(String::New("coordinates")); if (!coordinates->IsArray()) { return ThrowException(Exception::TypeError(String::New("coordinates must be an array of (lat/long) pairs"))); } Local<Array> coordinates_array = Local<Array>::Cast(coordinates); if (coordinates_array->Length() < 2) { return ThrowException(Exception::TypeError(String::New("at least two coordinates must be provided"))); } Query* q = new Query(); q->this_->zoomLevel = 18; //no generalization q->this_->printInstructions = true; //turn by turn instructions q->this_->alternateRoute = true; //get an alternate route, too q->this_->geometry = true; //retrieve geometry of route q->this_->compression = true; //polyline encoding q->this_->checkSum = UINT_MAX; //see wiki q->this_->service = "viaroute"; //that's routing q->this_->outputFormat = "json"; q->this_->jsonpParameter = ""; //set for jsonp wrapping q->this_->language = ""; //unused atm if (obj->Has(String::NewSymbol("alternateRoute"))) { q->this_->alternateRoute = obj->Get(String::New("alternateRoute"))->BooleanValue(); } for (uint32_t i = 0; i < coordinates_array->Length(); ++i) { Local<Value> coordinate = coordinates_array->Get(i); if (!coordinate->IsArray()) { return ThrowException(Exception::TypeError(String::New("coordinates must be an array of (lat/long) pairs"))); } Local<Array> coordinate_array = Local<Array>::Cast(coordinate); if (coordinate_array->Length() != 2) { return ThrowException(Exception::TypeError(String::New("coordinates must be an array of (lat/long) pairs"))); } q->this_->coordinates.push_back( FixedPointCoordinate(coordinate_array->Get(0)->NumberValue()*COORDINATE_PRECISION, coordinate_array->Get(1)->NumberValue()*COORDINATE_PRECISION)); } q->Wrap(args.This()); return args.This(); } catch (std::exception const& ex) { return ThrowException(Exception::TypeError(String::New(ex.what()))); } return Undefined(); }
void Layer::set_prop(Local<String> property, Local<Value> value, const AccessorInfo& info) { HandleScope scope; Layer* l = ObjectWrap::Unwrap<Layer>(info.Holder()); std::string a = TOSTR(property); if (a == "name") { if (!value->IsString()) { ThrowException(Exception::Error( String::New("'name' must be a string"))); } else { l->layer_->set_name(TOSTR(value)); } } else if (a == "srs") { if (!value->IsString()) { ThrowException(Exception::Error( String::New("'srs' must be a string"))); } else { l->layer_->set_srs(TOSTR(value)); } } else if (a == "styles") { if (!value->IsArray()) ThrowException(Exception::Error( String::New("Must provide an array of style names"))); else { Local<Array> a = Local<Array>::Cast(value->ToObject()); // todo - how to check if cast worked? uint32_t i = 0; uint32_t a_length = a->Length(); while (i < a_length) { l->layer_->add_style(TOSTR(a->Get(i))); i++; } } } else if (a == "datasource") { Local<Object> obj = value->ToObject(); if (value->IsNull() || value->IsUndefined()) { ThrowException(Exception::TypeError(String::New("mapnik.Datasource or mapnik.JSDatasource instance expected"))); } else { if (Datasource::constructor->HasInstance(obj)) { JSDatasource *d = ObjectWrap::Unwrap<JSDatasource>(obj); // TODO - addLayer should be add_layer in mapnik l->layer_->set_datasource(d->get()); } else if (JSDatasource::constructor->HasInstance(obj)) { JSDatasource *d = ObjectWrap::Unwrap<JSDatasource>(obj); // TODO - addLayer should be add_layer in mapnik l->layer_->set_datasource(d->get()); } else { ThrowException(Exception::TypeError(String::New("mapnik.Datasource or mapnik.JSDatasource instance expected"))); } } } }
/*----------------------------------------------------------------------------- * Parse options */ bool ConnectParseOptions(Local<Object> options, ConnectRequest* request) { // Get options data std::vector<std::string> optionNames = cvv8::CastFromJS<std::vector<std::string> >(options->GetPropertyNames()); for (size_t i = 0; i < optionNames.size(); i++) { char* optionName = (char*)(optionNames[i].c_str()); Local<Value> optionValue = options->Get(String::NewSymbol(optionName)); if (optionValue->IsUndefined()) { continue; } if (tva_str_casecmp(optionName, "username") == 0) { String::AsciiValue val(optionValue->ToString()); request->username = strdup(*val); } else if (tva_str_casecmp(optionName, "password") == 0) { String::AsciiValue val(optionValue->ToString()); request->password = strdup(*val); } else if (tva_str_casecmp(optionName, "tmx") == 0) { if (optionValue->IsString()) { String::AsciiValue val(optionValue->ToString()); request->primaryTmx = strdup(*val); } else if (optionValue->IsArray()) { Handle<Array> tmxs = Handle<Array>::Cast(optionValue); char** p_tmx = &request->primaryTmx; Local<Value> element; element = tmxs->Get(0); if (!element->IsUndefined()) { String::AsciiValue tmx(element->ToString()); *p_tmx = strdup(*tmx); p_tmx = &request->secondaryTmx; } if (tmxs->Length() > 1) { element = tmxs->Get(1); if (!element->IsUndefined()) { String::AsciiValue tmx(element->ToString()); *p_tmx = strdup(*tmx); } } } } else if (tva_str_casecmp(optionName, "name") == 0) { String::AsciiValue val(optionValue->ToString()); request->gdClientName = strdup(*val); } else if (tva_str_casecmp(optionName, "timeout") == 0) { request->timeout = optionValue->Int32Value() * 1000; } else if (tva_str_casecmp(optionName, "gdMaxOut") == 0) { request->gdMaxOut = optionValue->Int32Value(); } else if (tva_str_casecmp(optionName, "config") == 0) { if (optionValue->IsObject()) { Local<Object> config = Local<Object>::Cast(optionValue); std::vector<std::string> configNames = cvv8::CastFromJS<std::vector<std::string> >(config->GetPropertyNames()); for (size_t j = 0; j < configNames.size(); j++) { char* configName = (char*)(configNames[j].c_str()); Local<Value> configValue = config->Get(String::NewSymbol(configName)); if (configValue->IsUndefined()) { continue; } for (size_t c = 0; c < NUM_PARAMS; c++) { ConnectConfigParam* cp = &g_connectConfig[c]; if (tva_str_casecmp(configName, cp->jsName) == 0) { switch (cp->configType) { case ConfigTypeBool: { bool bVal; if (configValue->IsBoolean()) { bVal = configValue->BooleanValue(); } else if (configValue->IsNumber()) { bVal = (configValue->NumberValue() != 0); } else if (configValue->IsString()) { String::AsciiValue bStrVal(config->ToString()); bVal = (tva_str_casecmp(*bStrVal, "true") == 0); } tvaAppCfgSet(cp->tvaParam, &bVal, (TVA_INT32)sizeof(bVal)); } break; case ConfigTypeInt: { int intVal = configValue->Int32Value(); tvaAppCfgSet(cp->tvaParam, &intVal, (TVA_INT32)sizeof(intVal)); } break; case ConfigTypeString: { String::AsciiValue strVal(configValue->ToString()); tvaAppCfgSet(cp->tvaParam, *strVal, (TVA_INT32)strlen(*strVal)); } break; case ConfigTypeCustom: if (cp->tvaParam == TVA_APPCFG_DATA_TRANSPORT_TYPE) { TVA_DATATRANSPORT_TYPE transportType = TVA_DATATRANSPORT_UDP; if (configValue->IsString()) { String::AsciiValue strVal(config->ToString()); if (tva_str_casecmp(*strVal, "TCP")) { transportType = TVA_DATATRANSPORT_TCP; } else if (tva_str_casecmp(*strVal, "SSL")) { transportType = TVA_DATATRANSPORT_SSL; } } else if (configValue->IsNumber()) { int numVal = (int)configValue->NumberValue(); if ((numVal == TVA_DATATRANSPORT_TCP) || (numVal == TVA_DATATRANSPORT_SSL)) { transportType = (TVA_DATATRANSPORT_TYPE)numVal; } } tvaAppCfgSet(cp->tvaParam, &transportType, (TVA_INT32)sizeof(transportType)); } break; } break; } } } } } } // Make sure required arguments were specified if (!request->username || !request->password || !request->primaryTmx) { return false; } return true; }
void ContactsPersonProxy::_setAddress(void* userContext, Handle<Value> value) { ContactsPersonProxy *obj = (ContactsPersonProxy*) userContext; if(!obj->isEditing) { obj->builder_ = obj->contact_.edit(); } // The value passed in *MUST* be an object containing arrays of objects // http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Contacts.Person-property-address if(!value->IsObject()) return; // Get the JS Object and it's properties Local<Object> addressObject = value->ToObject(); Local<Array> addressProperties = addressObject->GetPropertyNames(); // Look for properties, such as "work", "home", or "other" for(int i = 0, len = addressProperties->Length(); i < len; i++) { // Get the key and value or each main object // { work: [ ... ] }" Local<String> addressKey = addressProperties->Get(i)->ToString(); Local<Value> addressValue = addressObject->Get(addressKey); // Create the subkind from the key of the object AttributeSubKind::Type subKind = AttributeSubKind::Other; QString _key = titanium::V8ValueToQString(addressKey); if(_key.toLower() == "work") { subKind = AttributeSubKind::Work; } if(_key.toLower() == "home") { subKind = AttributeSubKind::Home; } // The value of the individual address object *MUST* be an array of address objects // [ { street: '12 Main St' }, { street: '21 Meh St' } ] if(!addressValue->IsArray()) return; // Cast the value of the array to a v8 Array and look for addresses Local<Array> addresses = Local<Array>::Cast(addressValue); for(int i = 0, len = addresses->Length(); i < len; i++) { // Create the new address builder object and set the subkind ContactPostalAddressBuilder addressBuilder; addressBuilder.setSubKind(subKind); // Get the actual address object from the array of address objects // This *MUST* be an object with keys and values // { street: '12 Main St' } Local<Value> currentAddress = addresses->Get(Number::New(i)); if(!currentAddress->IsObject()) return; // Get the individual address object and look for it's properties Local<Object> currentAddressObject = currentAddress->ToObject(); Local<Array> currentAddressProperties = currentAddressObject->GetPropertyNames(); // Go through the keys and value of this object, one at a time for(int i = 0, len = currentAddressProperties->Length(); i < len; i++) { Local<String> currentAddressKey = currentAddressProperties->Get(i)->ToString(); Local<Value> currentAddressValue = currentAddressObject->Get(currentAddressKey); // The value *MUST* be a string if(!currentAddressValue->IsString()) return; // Cast it to a String and get the UTF8 strings Local<String> currentAddressStringValue = currentAddressValue->ToString(); // Convert them to QStrings for better manipulation QString _key = titanium::V8ValueToQString(currentAddressKey); QString _value = titanium::V8ValueToQString(currentAddressStringValue); // Start populating the address builder if(_key.toLower() == "city"){ addressBuilder.setCity(_value); } if(_key.toLower() == "label"){ addressBuilder.setLabel(_value); } if(_key.toLower() == "line1"){ addressBuilder.setLine1(_value); } if(_key.toLower() == "line2") { addressBuilder.setLine2(_value); } if(_key.toLower() == "street") { if(_value.contains("\n")) { QStringList l = _value.split('\n'); addressBuilder.setLine1(l.at(0)); l.removeAt(0); addressBuilder.setLine2(l.join("")); } else { addressBuilder.setLine1(_value); } } if(_key.toLower() == "zip"){ addressBuilder.setPostalCode(_value); } if(_key.toLower() == "county"){ addressBuilder.setRegion(_value); } if(_key.toLower() == "country"){ addressBuilder.setCountry(_value); } } // Once finished with an address, add it to the contact obj->builder_.addPostalAddress(addressBuilder); } } // Once done, update the contact if(!obj->isEditing) { ContactService().updateContact(obj->contact_); } }
void ContactsPersonProxy::_setInstantMessage(void* userContext, Handle<Value> value) { ContactsPersonProxy *obj = (ContactsPersonProxy*) userContext; if(!value->IsObject()) return; Handle<Object> messageObject = value->ToObject(); Local<Array> messageProperties = messageObject->GetPropertyNames(); for(int i = 0, len = messageProperties->Length(); i < len; i++) { Local<String> messageKey = messageProperties->Get(i)->ToString(); Local<Value> messageValue = messageObject->Get(messageKey); AttributeSubKind::Type subKind = AttributeSubKind::Other; QString messageKeyString = titanium::V8ValueToQString(messageKey).toLower(); if(messageKeyString == "aim") { subKind = AttributeSubKind::InstantMessagingAim; } else if(messageKeyString == "aliwangwang") { subKind = AttributeSubKind::InstantMessagingAliwangwang; } else if(messageKeyString == "bbmpin") { subKind = AttributeSubKind::InstantMessagingBbmPin; } else if(messageKeyString == "googletalk") { subKind = AttributeSubKind::InstantMessagingGoogleTalk; } else if(messageKeyString == "icq") { subKind = AttributeSubKind::InstantMessagingIcq; } else if(messageKeyString == "irc") { subKind = AttributeSubKind::InstantMessagingIrc; } else if(messageKeyString == "jabber") { subKind = AttributeSubKind::InstantMessagingJabber; } else if(messageKeyString == "msLcs") { subKind = AttributeSubKind::InstantMessagingMsLcs; } else if(messageKeyString == "msn") { subKind = AttributeSubKind::InstantMessagingMsn; } else if(messageKeyString == "qq") { subKind = AttributeSubKind::InstantMessagingQq; } else if(messageKeyString == "sametime") { subKind = AttributeSubKind::InstantMessagingSametime; } else if(messageKeyString == "skype") { subKind = AttributeSubKind::InstantMessagingSkype; } else if(messageKeyString == "yahoomessenger") { subKind = AttributeSubKind::InstantMessagingYahooMessenger; } else if(messageKeyString == "yahoomessengerjapan") { subKind = AttributeSubKind::InstantMessagingYahooMessengerJapan; } if(!messageValue->IsArray()) return; Local<Array> messages = Local<Array>::Cast(messageValue); for(int i = 0, len = messages->Length(); i < len; i++) { Local<Value> currentMessage = messages->Get(Number::New(i)); if(!currentMessage->IsString()) return; obj->setContactDetails(AttributeKind::InstantMessaging, subKind, currentMessage); } } }