V8: Exclude undefined properties from result

This commit is contained in:
Mikhail Lobotskiy
2023-11-16 19:28:46 +04:00
parent 84c34eed65
commit d646876347

View File

@ -452,12 +452,17 @@ namespace NSJSBase
v8::Local<v8::Array> names = value->GetPropertyNames(context).ToLocalChecked();
uint32_t len = names->Length();
std::vector<std::string> ret(len);
std::vector<std::string> ret;
for (uint32_t i = 0; i < len; i++)
{
v8::Local<v8::Value> propertyName = names->Get(context, i).ToLocalChecked();
v8::Local<v8::Value> propertyValue = value->Get(context, propertyName).ToLocalChecked();
// skip undefined properties
if (propertyValue->IsUndefined())
continue;
CJSValueV8 _value;
_value.value = names->Get(context, i).ToLocalChecked();
ret[i] = _value.toStringA();
_value.value = propertyName;
ret.push_back(_value.toStringA());
}
return ret;