hasProperty static method
bool
hasProperty(
- dynamic value,
- dynamic key
)
Implementation
static bool hasProperty(dynamic value, dynamic key) {
key = _normalizeProperty(key);
if (value is Map) {
if (value.containsKey(key) ||
getOwnPropertyDescriptor(value, key) != null) {
return true;
}
final prototype = getPrototype(value);
return prototype != null && hasProperty(prototype, key);
}
if (value is List) {
key = _normalizeIndexProperty(key);
if (key is int) {
return key >= 0 && key < value.length && !isArrayHole(value[key]);
}
return getters(value).containsKey(key) || methods(value).containsKey(key);
}
if (value is String) {
key = _normalizeIndexProperty(key);
if (key is int) return key >= 0 && key < value.length;
return getters(value).containsKey(key) || methods(value).containsKey(key);
}
if (value is Invokable) {
return value.hasGettableProperty(key) || value.hasMethod(key);
}
return false;
}