| 159 | } |
| 160 | |
| 161 | void LookupInList(const ListValue& cel_list, const Value& key, |
| 162 | ExecutionFrameBase& frame, Value& result) { |
| 163 | absl::optional<int64_t> maybe_idx; |
| 164 | if (frame.options().enable_heterogeneous_equality) { |
| 165 | auto number = CelNumberFromValue(key); |
| 166 | if (number.has_value() && number->LosslessConvertibleToInt()) { |
| 167 | maybe_idx = number->AsInt(); |
| 168 | } |
| 169 | } else if (InstanceOf<IntValue>(key)) { |
| 170 | maybe_idx = key.GetInt().NativeValue(); |
| 171 | } |
| 172 | |
| 173 | if (!maybe_idx.has_value()) { |
| 174 | result = cel::ErrorValue(absl::UnknownError( |
| 175 | absl::StrCat("Index error: expected integer type, got ", |
| 176 | cel::KindToString(ValueKindToKind(key->kind()))))); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | int64_t idx = *maybe_idx; |
| 181 | auto size = cel_list.Size(); |
| 182 | if (!size.ok()) { |
| 183 | result = cel::ErrorValue(size.status()); |
| 184 | return; |
| 185 | } |
| 186 | if (idx < 0 || idx >= *size) { |
| 187 | result = cel::ErrorValue(absl::UnknownError( |
| 188 | absl::StrCat("Index error: index=", idx, " size=", *size))); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | absl::Status lookup = |
| 193 | cel_list.Get(idx, frame.descriptor_pool(), frame.message_factory(), |
| 194 | frame.arena(), &result); |
| 195 | |
| 196 | if (!lookup.ok()) { |
| 197 | result = cel::ErrorValue(std::move(lookup)); |
| 198 | } |
| 199 | ABSL_DCHECK(!result.IsUnknown()); |
| 200 | } |
| 201 | |
| 202 | void LookupInContainer(const Value& container, const Value& key, |
| 203 | ExecutionFrameBase& frame, Value& result) { |
no test coverage detected