diff --git a/frameworks/bridge/declarative_frontend/jsview/js_data_change_listener.h b/frameworks/bridge/declarative_frontend/jsview/js_data_change_listener.h index 74eb50a4a4f2ef7d4c6ae0e9910056b5be28341e..89cbb7d06063a2d196af987a208fa6a791a7db4a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_data_change_listener.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_data_change_listener.h @@ -168,11 +168,12 @@ private: void TransferJSInfoType(std::list& DataOperations, JSRef value) { - if (!value->GetProperty("type")->IsString()) { + auto jsType = value->GetProperty("type"); + if (!jsType->IsString()) { return; } V2::Operation dataOperation; - std::string operationType = value->GetProperty("type")->ToString(); + std::string operationType = jsType->ToString(); dataOperation.type = operationType; dataOperation.count = 1; const int ADDOP = 1; @@ -205,38 +206,45 @@ private: void transferIndex(JSRef value, V2::Operation& dataOperation) { - if (value->GetProperty("index")->IsNumber()) { - dataOperation.index = value->GetProperty("index")->ToNumber(); - } else if (value->GetProperty("index")->IsObject()) { - JSRef coupleIndex = JSRef::Cast(value->GetProperty("index")); - if (coupleIndex->GetProperty("from")->IsNumber()) { - dataOperation.coupleIndex.first = coupleIndex->GetProperty("from")->ToNumber(); + auto jsIndex = value->GetProperty("index"); + if (jsIndex->IsNumber()) { + dataOperation.index = jsIndex->ToNumber(); + } else if (jsIndex->IsObject()) { + JSRef coupleIndex = JSRef::Cast(jsIndex); + auto jsFrom = coupleIndex->GetProperty("from"); + if (jsFrom->IsNumber()) { + dataOperation.coupleIndex.first = jsFrom->ToNumber(); } - if (coupleIndex->GetProperty("to")->IsNumber()) { - dataOperation.coupleIndex.second = coupleIndex->GetProperty("to")->ToNumber(); + auto jsTo = coupleIndex->GetProperty("to"); + if (jsTo->IsNumber()) { + dataOperation.coupleIndex.second = jsTo->ToNumber(); } - if (coupleIndex->GetProperty("start")->IsNumber()) { - dataOperation.coupleIndex.first = coupleIndex->GetProperty("start")->ToNumber(); + auto jsStart = coupleIndex->GetProperty("start"); + if (jsStart->IsNumber()) { + dataOperation.coupleIndex.first = jsStart->ToNumber(); } - if (coupleIndex->GetProperty("end")->IsNumber()) { - dataOperation.coupleIndex.second = coupleIndex->GetProperty("end")->ToNumber(); + auto jsEnd = coupleIndex->GetProperty("end"); + if (jsEnd->IsNumber()) { + dataOperation.coupleIndex.second = jsEnd->ToNumber(); } } } void transferCount(JSRef value, V2::Operation& dataOperation) { - if (value->GetProperty("count")->IsNumber()) { - dataOperation.count = value->GetProperty("count")->ToNumber(); + auto jsCount = value->GetProperty("count"); + if (jsCount->IsNumber()) { + dataOperation.count = jsCount->ToNumber(); } } void transferKey(JSRef value, V2::Operation& dataOperation) { - if (value->GetProperty("key")->IsString()) { - dataOperation.key = value->GetProperty("key")->ToString(); - } else if (value->GetProperty("key")->IsArray()) { - JSRef keys = JSRef::Cast(value->GetProperty("key")); + auto jsKey = value->GetProperty("key"); + if (jsKey->IsString()) { + dataOperation.key = jsKey->ToString(); + } else if (jsKey->IsArray()) { + JSRef keys = JSRef::Cast(jsKey); if (dataOperation.type == "add" && static_cast(dataOperation.count) < keys->Length()) { allocateMoreKeys = true; return; @@ -248,19 +256,23 @@ private: } } dataOperation.keyList = keyList; - } else if (value->GetProperty("key")->IsObject()) { - JSRef coupleKey = JSRef::Cast(value->GetProperty("key")); - if (coupleKey->GetProperty("from")->IsString()) { - dataOperation.coupleKey.first = coupleKey->GetProperty("from")->ToString(); + } else if (jsKey->IsObject()) { + JSRef coupleKey = JSRef::Cast(jsKey); + auto jsFrom = coupleKey->GetProperty("from"); + if (jsFrom->IsString()) { + dataOperation.coupleKey.first = jsFrom->ToString(); } - if (coupleKey->GetProperty("to")->IsString()) { - dataOperation.coupleKey.second = coupleKey->GetProperty("to")->ToString(); + auto jsTo = coupleKey->GetProperty("to"); + if (jsTo->IsString()) { + dataOperation.coupleKey.second = jsTo->ToString(); } - if (coupleKey->GetProperty("start")->IsString()) { - dataOperation.coupleKey.first = coupleKey->GetProperty("start")->ToString(); + auto jsStart = coupleKey->GetProperty("start"); + if (jsStart->IsString()) { + dataOperation.coupleKey.first = jsStart->ToString(); } - if (coupleKey->GetProperty("end")->IsString()) { - dataOperation.coupleKey.second = coupleKey->GetProperty("end")->ToString(); + auto jsEnd = coupleKey->GetProperty("end"); + if (jsEnd->IsString()) { + dataOperation.coupleKey.second = jsEnd->ToString(); } } }